RuleToSourceFlags
Description
Enumeration of flags that control source code output for rules of a Grammar.
Public / Constants
GrammarAst
Outputs grammar rules in a way that represents the hierarchical structure of the abstract syntax tree that is created by the grammar.
AST rules are retained, all others are dropped (see IRule.Ast, IRule.AstIfLeft, IRule.AstIfRight). AST nodes are represented as token rules (see Rule.Token1), using the AST node type as the value (see AstNode.Type). The start and end of the children list of an AST node are marked with '{'
and '}'
token rules.
For example, the AST grammar of Grammar.GrammarCode grammar looks like this:
grammar := 'GRAMMAR' '{' (decl-skip | decl-rule)+ '}' ; decl-rule := 'RULE' '{' 'NAME' rule-list '}' | 'RULE_FLAGS' '{' 'RULE_FLAG' 'RULE' '{' 'NAME' rule-list '}' '}' ; decl-skip := 'RULE' '{' 'SKIP' rule-list '}' ; rule-ast := 'EXPR_AST' '{' 'NAME' rule-list (('IF_LEFT' | 'IF_RIGHT') rule-list)? '}' ; rule-brace := 'EXPR_BRACE' '{' rule-list '}' ; rule-choice := rule-sequence | 'EXPR_CHOICE' '{' rule-sequence rule-sequence+ '}' ; rule-except := rule-not | 'EXPR_EXCEPT' '{' rule-not rule-not '}' ; rule-list := rule-choice | 'EXPR_LIST' '{' rule-choice rule-choice '}' ; rule-not := rule-primary | 'EXPR_NOT' '{' rule-primary '}' ; rule-peek-no := 'EXPR_PEEK_NO' '{' rule-list '}' ; rule-peek-yes := 'EXPR_PEEK_YES' '{' rule-list '}' ; rule-primary := rule-char | rule-token | 'EXPR_SUBRULE' | rule-brace | rule-ast | rule-peek-yes | rule-peek-no ; rule-repeat := rule-except | 'EXPR_REPEAT' '{' rule-except ('ZERO_OR_ONE' | 'ZERO_OR_MORE' | 'ONE_OR_MORE' | 'MIN_MAX' '{' 'NUMBER'[1..2] '}') '}' ; rule-sequence := rule-trim | 'EXPR_SEQUENCE' '{' rule-trim rule-trim+ '}' ; rule-trim := rule-repeat | 'EXPR_TRIM_RIGHT' '{' rule-repeat '}' | 'EXPR_TRIM_LEFT' '{' (rule-repeat | 'EXPR_TRIM_RIGHT' '{' rule-repeat '}') '}' ; rule-char := char-set | char-set-inv | char-range | 'CHAR_EOF' ; char-range := char-one | 'CHAR_RANGE' '{' char-one char-one '}' ; char-one := 'CHAR_ONE' '{' 'CHAR_ESC'? '}' ; char-set := 'CHAR_SET' '{' ('CHAR_ESC' | 'CHAR_ONE')+ '}' ; char-set-inv := 'CHAR_SET_INV' '{' ('CHAR_ESC' | 'CHAR_ONE')+ '}' ; rule-token := 'EXPR_TOKEN' '{' 'CHAR_ESC'* '}' | 'EXPR_TOKEN_NOCASE' '{' 'EXPR_TOKEN' '{' 'CHAR_ESC'* '}' '}' ;
- See also
Optimize
Optimize output by removing redundant or obsolete grammar elements?
The following elements are considered redundant or obsolete:
-
A grammar rule that is not referenced by others, as indicated with GrammarRuleFlags.NotReferenced.
-
A grammar rule without any GrammarRuleFlags.ReportErrorMask flags that merely references another rule via
rule-name
orrule-token
.