Repository navigation
Modifiers
Modifiers in ISPA Parser Generator are annotations applied to grammar elements (rules, expressions, or tokens) using square-bracket syntax [...]. They alter the parsing behavior, AST generation flow, or lexer mechanics for specific definitions without polluting the core language logic.
Modifiers provide fine-grained control over how individual nodes and tokens are processed by the ISPA compiler engine:
- AST Value Optimization: Inlining nodes to simplify the resulting AST hierarchy.
- Lexer Directives: Stripping out non-semantic tokens (like whitespace or comments) early in the pipeline.
- Parser Controls: Fine-tuning error recovery, associativity, or visibility.
Modifiers are specified directly preceding the definition or rule block using [modifier_name] or parameter-driven [modifier_name(arg)] syntax.
The [inline] directive instructs the compiler to collapse or flatten an AST node directly into its parent. This prevents unnecessary single-child node nesting in the generated tree.
[inline] // Collapses the AST node into the caller's AST level
operator:
@ PLUS | MINUS
{@}
;
-
Without
[inline]: Produce operator rule, containing either PLUS or MINUS token as value -
With
[inline]: Directly evaluate PLUS or MINUS token to the value calling operator rule
The [skip] modifier is applied to lexer tokens to indicate that matched sequences should be discarded by the lexer and omitted from token streams passed to the parser stage.
[skip] // Automatically skips this token whenever encountered
WHITESPACE: [ ]+;
- Ignoring spaces, tabs, and newlines.
- Stripping single-line and block comments (
// ...,/* ... */).