meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
include [2023/03/03 16:16] revuskyinclude [2023/03/03 16:20] (current) revusky
Line 43: Line 43:
     }     }
    
-JavaCC 21 will replace the **PARSER_CLASS** and **LEXER_CLASS** aliases with the appropriate names -- i.e. the actual class names of the XXXParser or XXXLexer being generated. So, if you have a Foo language in which you want to embed JSON expressions, so you include a JSON grammar, if that JSON grammar is to include some code within the generated parser, it cannot be:+CongoCC 21 replaces the **PARSER_CLASS** and **LEXER_CLASS** aliases with the appropriate names -- i.e. the actual class names of the XXXParser or XXXLexer being generated. So, if you have a Foo language in which you want to embed JSON expressions, so you include a JSON grammar, if that JSON grammar is to include some code within the generated parser, it cannot be:
  
     INJECT JSONParser :     INJECT JSONParser :
Line 50: Line 50:
     }     }
  
-because the parser class we are generating is not JSONParser, it is FOOParser! However, the person writing a a generally useful JSON grammar that can be embedded in other grammars does not know the classname of Parser (or Lexer) that is being generated. So, he needs to use the alias **PARSER_CLASS** or possibly **LEXER_CLASS** for the injected code to be included+because the parser class we are generating is not JSONParser, it is FooParser! However, the person writing a a generally useful JSON grammar that can be embedded in other grammars does not know the classname of Parser (or Lexer) that is being generated. So, he needs to use the alias **PARSER_CLASS** or possibly **LEXER_CLASS** for the injected code to be included.
- +
-So, do not be surprised when the code within PARSER_BEGIN...PARSER_END is ignored if it is within an INCLUDEd grammar. You need to write INJECT(PARSER_CLASS) to achieve the desired result.+
  
 In fact, the aliases **PARSER_CLASS**, **LEXER_CLASS**, **CONSTANTS_CLASS**, and **PARSER_PACKAGE** can be used in code injections and java actions to make an included grammar (or grammar fragment) more generally useful. In fact, the aliases **PARSER_CLASS**, **LEXER_CLASS**, **CONSTANTS_CLASS**, and **PARSER_PACKAGE** can be used in code injections and java actions to make an included grammar (or grammar fragment) more generally useful.
  
-To see a concrete example of **INCLUDE** in use, you can take a look at https://github.com/javacc21/javacc21/tree/master/src/grammars. Specifically, you can see that the JavaCC.javacc grammar **INCLUDE**s the Java.javacc. Another point is that this Java.javacc grammar file is, on its own quite generally usable. And useful!+To see a concrete example of **INCLUDE** in use, you can take a look at https://github.com/congo-cc/congo-parser-generator/tree/master/src/grammars. Specifically, you can see that the CongoCC.ccc grammar **INCLUDE**s the Java.ccc. Another point is that this Java.ccc grammar file is, on its own quite generally usable. And useful!
  
 </markdown> </markdown>