File info in Lexer/Parser

Answered

I am working on a plugin that has 5 versions of the language and each language shares the same extension. In order for the plugin to work, I use a check in ParserUtil to see which version has been set in project settings. I would like to have the LexerParser use a language version defined on a per-file basis, not a project basis, as there can be multiple files of different versions in the same project.

I am having a hard time though accessing the virtual file from the ParserUtil class, and I cannot access the PSI file, because it has not been created yet so checking the tree in the builder object throws an error.

My question is, is there a way to read user-data on the virtual file from ParserUtil? Or is there a way to allow per file information access from ParserUtil.

I thought I could alter the lexer to output different tokens based on the desired version by passing in a parameter to the constructor, but again, I cannot see how to access the file's data from the parser definition either.

Is it possible to store file information in a way that is accessible to the Parser and/or Lexer?

0
3 comments

See com.intellij.openapi.roots.impl.FilePropertyPusher and com.intellij.lang.LanguagePerFileMappings

0

Thank you for getting back to me, Unfortunately, I have already tried to use FilePropertyPusher, and though I can set the data, I cannot figure out how to access it from the lexer or the parser. Is there a way to access the Virtual File from either the JFlex lexer, or a GrammarKit parser? Right now I can only figure out how to access a project wide setting for the script type, but that messes things up when a project has multiple files from different SDK versions.

If you could let me know how to access the VirtualFile from the lexer or the parser or at least how to get the property set with FilePropertyPusher, I would appreciate it.

Thank you for your time

0

Employ com.intellij.psi.LanguageSubstitutor using the LanguagePerFileMappings settings

0

Please sign in to leave a comment.