%start ParolLs %title "Parol grammar" %comment "Parol's own grammar enhanced with comment processing" %grammar_type 'll(k)' %line_comment '//' %block_comment '/*' '*/' %user_type OwnedToken = crate::parol_ls_grammar::OwnedToken %% ParolLs : Prolog GrammarDefinition; Prolog : StartDeclaration { Declaration } { ScannerState }; StartDeclaration : "%start": OwnedToken Identifier; Declaration : "%title": OwnedToken String | "%comment": OwnedToken String | "%user_type": OwnedToken Identifier "=": OwnedToken UserTypeName | '%grammar_type': OwnedToken LiteralString // The type of the grammar, e.g. LL(k), LALR(1) | ScannerDirectives; ScannerDirectives : "%line_comment": OwnedToken TokenLiteral | "%block_comment": OwnedToken TokenLiteral TokenLiteral | "%auto_newline_off": OwnedToken | "%auto_ws_off": OwnedToken | '%on': OwnedToken IdentifierList '%enter': OwnedToken Identifier // Scanner state enter directives ; GrammarDefinition : "%%": OwnedToken Production { Production }; DoubleColon : "::": OwnedToken; ProductionLHS : Identifier ":": OwnedToken; Production : ProductionLHS Alternations ";": OwnedToken; Alternations : Alternation { '|': OwnedToken Alternation }; Alternation : { Factor }; Factor : Group | Repeat | Optional | Symbol; Symbol : NonTerminal | SimpleToken | TokenWithStates | ScannerSwitch; TokenLiteral : String | LiteralString | Regex; SimpleToken : TokenLiteral [ ASTControl ]; TokenWithStates : "<": OwnedToken IdentifierList ">": OwnedToken TokenLiteral [ ASTControl ]; Group : '(': OwnedToken Alternations ')': OwnedToken; Optional : '[': OwnedToken Alternations ']': OwnedToken; Repeat : '{': OwnedToken Alternations '}': OwnedToken; NonTerminal : Identifier [ ASTControl ]; Identifier : /[a-zA-Z_][a-zA-Z0-9_]*/: OwnedToken; String : /"(\\.|[^\\])*?"/: OwnedToken; LiteralString : /'(\\'|[^'])*?'/: OwnedToken; ScannerState : "%scanner": OwnedToken Identifier '{': OwnedToken { ScannerDirectives } '}': OwnedToken; IdentifierList : Identifier { ",": OwnedToken Identifier }; ScannerSwitch : "%sc": OwnedToken '(': OwnedToken [ Identifier ] ')': OwnedToken | "%push": OwnedToken '(': OwnedToken Identifier ')': OwnedToken | "%pop": OwnedToken '(': OwnedToken ')': OwnedToken; ASTControl : CutOperator | UserTypeDeclaration; CutOperator : '^': OwnedToken; UserTypeDeclaration : ":": OwnedToken UserTypeName; UserTypeName : Identifier { DoubleColon Identifier }; Regex : /\u{2f}(\\.|[^\\])*?\u{2f}/: OwnedToken // \u{2f} is / ; // End comment