forked from we-like-parsers/pegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gram.gram
26 lines (19 loc) · 1.07 KB
/
gram.gram
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
start: rs=rules ENDMARKER { rs }
rules: rs=rule+ { rs }
rule: ( n=NAME ':' alts=alternatives NEWLINE { Tree('Rule', n, alts) }
| n=NAME ':' NEWLINE INDENT alts=('|' alternatives NEWLINE)+ DEDENT
{ Tree('Rule', n, flatten(alts)) }
)
alternatives: l=alt rs=('|' alt)* { Tree('Alts', l, *rs) }
alt: it=(named_item | item)+ { Tree('Alt', it) }
named_item: NAME '=' item { Tree('Named', name, item) }
item: ('[' alternatives ']' { Tree('Opt', alternatives) }
| atom ' '* '?' { Tree('Opt', atom) }
| atom '*' { Tree('ZeroOrMore', atom) }
| atom '1' { Tree('OneOrMore', atom) }
| atom { atom }
)
atom: ( '(' alternatives ')' { alternatives }
| NAME { name }
| STRING { string }
)