RuleToSourceFlags

Description

[Flags]
enum Tinman.Core.Parsing.RuleToSourceFlags

Enumeration of flags that control source code output for rules of a Grammar.

Public / Constants

None

public constant None → (0:int32)

No format flags for emitting source code.

Compact

public constant Compact → (1:int32)

Emits compact computer-ish source code instead of nice-looking human-readable code.

OmitAst

public constant OmitAst → (2:int32)

Omit AST-building rule syntax.

OmitTrim

public constant OmitTrim → (4:int32)

Omit whitespace trimming rules?

EmitExternal

public constant EmitExternal → (8:int32)

Also emit external rules in source code?

GrammarAst

public constant GrammarAst → (16:int32)

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'* '}' '}' ;

Optimize

public constant Optimize → (32:int32)

Optimize output by removing redundant or obsolete grammar elements?

The following elements are considered redundant or obsolete:

All

public constant All → (63:int32)

All flags.