intellij-ideagrammar-kit

How to handle end of file in IntelliJ grammar kit


I'm working on IntelliJ support for a DSL using the Grammar-Kit. I have a rule in the bnf file which requires an EOF (end of file) token at the end: rule ::= ( object | (( LCURL EOL* properties EOL* RCURL ) | properties ) ) EOL* EOF

I assumed I can simpy create a lexer rule in the flex file <<EOF>> { return EOF;} and that's it.. Unfortunately somewhere deeper in the IntelliJ code the logic which handles lexer's advance() method does not finish unless it gets a null from the lexer causing an infinite loop as the end of file returns a not-null token.

Is there any elegant (simple) way to handle an End Of File in the Grammar-Kit allowing the 'end of file' to be used in the Parser definition (the bnf)?


Solution

  • In .bnf file you can use <<eof>>. It's an external rule which links to GeneratedParserUtilBase.eof method.