meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
include [2021/04/01 13:00] – revusky | include [2023/03/03 16:16] – revusky | ||
---|---|---|---|
Line 3: | Line 3: | ||
# The INCLUDE Statement | # The INCLUDE Statement | ||
- | JavaCC 21's **INCLUDE** statement allows you to break up your grammar file into multiple physical files. It would look like this typically: | + | Congo's **INCLUDE** statement allows you to break up your grammar file into multiple physical files. It would look like this typically: |
INCLUDE " | INCLUDE " | ||
Line 17: | Line 17: | ||
In legacy JavaCC, if you defined a token production without specifying a lexical state, any lexical definitions belonged to a lexical state called " | In legacy JavaCC, if you defined a token production without specifying a lexical state, any lexical definitions belonged to a lexical state called " | ||
- | Thus, JavaCC 21 introduces | + | Thus, CongoCC has a setting called **DEFAULT_LEXICAL_STATE**. That means that any lexical specifications where the lexical state is unspecified are in that state. Thus, a JSON grammar would likely have something like this at the top: |
- | DEFAULT_LEXICAL_STATE="JSON"; | + | DEFAULT_LEXICAL_STATE=JSON; |
| | ||
Line 29: | Line 29: | ||
## Wrinkles with Code Injection | ## Wrinkles with Code Injection | ||
- | JavaCC still supports the legacy JavaCC constructs of **PARSER_BEGIN...PARSER_END** and **TOKEN_MGR_DECLS**. (For how much longer, I am not making any promises...). However, those constructs are ignored within an **INCLUDE**d grammar. | + | You can *inject* code into the generated parser or lexer class, from within an included grammar, but you need to write something like: |
- | + | ||
- | You can still *inject* code into the generated parser or lexer class, from within an included grammar, but you need to write something like: | + | |
INJECT PARSER_CLASS : | INJECT PARSER_CLASS : |