src/Compiler/Resources/pp2/grammar.pp2
%include lexer
#Grammar
: __definition()*
;
__definition
: TokenDefinition()
| PragmaDefinition()
| IncludeDefinition()
| RuleDefinition()
;
/**
| ---------------------------------------------------------------------------------
| List of root structure definitions
| ---------------------------------------------------------------------------------
*/
#TokenDefinition -> Railt\Component\Compiler\Grammar\Delegate\TokenDelegate
: <T_TOKEN>
| <T_SKIP>
;
#PragmaDefinition
: <T_PRAGMA>
;
#IncludeDefinition -> Railt\Component\Compiler\Grammar\Delegate\IncludeDelegate
: <T_INCLUDE>
;
/**
| ---------------------------------------------------------------------------------
| Rule Definition
| ---------------------------------------------------------------------------------
*/
#RuleDefinition -> Railt\Component\Compiler\Grammar\Delegate\RuleDelegate
: ShouldKeep()? RuleName() RuleDelegate()?
::T_EQ:: RuleProduction() ::T_END_OF_RULE::?
;
#RuleName
: <T_NAME>
;
#RuleDelegate
: ::T_DELEGATE:: <T_NAME>
;
#ShouldKeep
: ::T_KEPT_NAME::
;
#RuleProduction
: __alternation()
;
__alternation
: __concatenation()
| Alternation()
;
#Alternation
: __concatenation() ( <T_OR> __concatenation() )+
;
__concatenation
: __repetition()
| Concatenation()
;
#Concatenation
: __repetition() __repetition()+
;
__repetition
: ( __simple() | Repetition() ) Rename()?
;
#Repetition
: __simple() Quantifier()
;
__simple
: <T_GROUP_OPEN> __alternation() <T_GROUP_CLOSE>
| <T_TOKEN_SKIPPED>
| <T_TOKEN_KEPT>
| <T_TOKEN_STRING>
| <T_INVOKE>
;
#Quantifier
: <T_REPEAT_ZERO_OR_ONE>
| <T_REPEAT_ONE_OR_MORE>
| <T_REPEAT_ZERO_OR_MORE>
| <T_REPEAT_N_TO_M>
| <T_REPEAT_ZERO_OR_MORE>
| <T_REPEAT_ZERO_TO_M>
| <T_REPEAT_N_OR_MORE>
| <T_REPEAT_EXACTLY_N>
;
#Rename
: <T_KEPT_NAME> <T_NAME>