// PEG grammar in EBNF form, to help implement the bootstrapping
// parser. Terminals are tokens as defined in token.go and
// returned by the Scanner implemented in scan.go.

Grammar = [ code ] [ RuleList ] .
RuleList = Rule { Rule } .
Rule = ident [ str | rstr | char ] ruledef Expression ( eol | eof | semicolon ) .

Expression = ChoiceExpr .
ChoiceExpr = ActionExpr { "/" ActionExpr } .
ActionExpr = SeqExpr [ code ] .
SeqExpr = LabeledExpr { LabeledExpr } .
LabeledExpr = [ ident colon ] PrefixedExpr .
PrefixedExpr = [ PrefixedOp ] SuffixedExpr .
PrefixedOp = ampersand | exclamation .
SuffixedExpr = PrimaryExpr [ SuffixedOp ] .
SuffixedOp = question | star | plus .
PrimaryExpr = LiteralMatcher | CharClassMatcher | AnyMatcher | RuleRefExpr | 
    lparen Expression rparen .

RuleRefExpr = ident .

LiteralMatcher = [ str | rstr | char ] .
CharClassMatcher = class .
AnyMatcher = dot .
