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 '}' | 'RULE_FLAGS' '{' 'RULE_FLAG' 'RULE' '{' 'NAME' rule '}' '}' ;
decl-skip     := 'RULE' '{' 'SKIP' rule '}' ;

rule          := rule-list ;
rule-ast      := 'EXPR_AST' '{' 'NAME' rule (('IF_LEFT' | 'IF_RIGHT') rule)? '}' ;
rule-brace    := 'EXPR_BRACE' '{' rule '}' ;
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-primary  := rule-char | rule-token | rule-name | rule-brace | rule-ast ;
rule-repeat   := rule-except | 'EXPR_REPEAT' '{' rule-except ('ZERO_OR_ONE' | 'ZERO_OR_MORE' | 'ONE_OR_MORE' | 'MIN_MAX' '{' number number? '}') '}' ;
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-range | char-set | char-set-inv | 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* '}' '}' ;

char-eof      := 'CHAR_EOF' ;
char-esc      := 'CHAR_ESC' ;
number        := 'NUMBER' ;
rule-name     := 'EXPR_SUBRULE' ;

Optimize

public constant Optimize → (32:int32)

Optimize output by removing redundant or obsolete grammar elements?

The following elements are considered redundant or obsolete: