I am trying to write a lexer for an IntelliJ language plugin. In the JFLex manual there is an example that can lex string literals. However in this example they use a StringBuffer to insert each part of the lexed characters and continually build up a single string. The problem I have with this method is that it creates a copy of the characters that are being read and I dont know how to integrate that example with the IntelliJ. In IntelliJ one always returns a IElementType and then the associated text is taken from yytext() using the functions getTokenStart()
and getTokenEnd()
, such that the start and end of the whole token is mapped directly to the input string.
So I want to be able to return a token and the associated yytext()
should span over the whole text since the last time another token was returned. For example in the string literal example, I would read \"
which marks the literal start, then I change into state STRING
and when I read \"
again I change back into another state and return the string literal token. At that point I want yytext() to contain the whole string literal.
Is this possible with JFlex? If not what is the recommended why to pass the content from a StringBuffer to the IntelliJ API after a token has been matched that spans multiple actions.