-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta_grammar.gram
52 lines (40 loc) · 1.27 KB
/
meta_grammar.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
start: grammar ENDMARKER { grammar }
grammar: rules=rule+ { Grammar(rules) }
rule:
| NAME ':' NEWLINE INDENT rhs NL DEDENT { Rule(name.text, rhs)}
| NAME ':' rhs NL { Rule(name.text, rhs)}
rhs:
| '|' alt NEWLINE rhs { Rhs(List(alt) + rhs.args)}
| '|' alt NEWLINE { Rhs(List(alt)) }
| alt NEWLINE { Rhs(List(alt)) }
alt:
| items action { Alt(items, action) }
| items { Alt(items) }
items: items=named_item+ { Items(items) }
named_item:
| NAME '=' item { NamedItem(item, name.text)}
| item { NamedItem(item) }
item:
| atom '*' { Repeat0(atom) }
| atom '+' { Repeat1(atom) }
| sep=atom '.' node=atom '+' { Gather(sep.text, node) }
| atom
atom:
| '(' items ')' { Group(items.args) }
| NAME { Atom(name.text) }
| STRING { Atom(string.text) }
action: '{' target '}' { target }
target:
| NAME target_atoms { Action(target_atoms, name)}
| target_atom { Action(target_atom) }
target_atoms:
| target_atom target_atoms { String(target_atom + ' ' + target_atoms) }
| target_atom
target_atom:
| NAME { String(name.text) }
| NUMBER { String(number.text) }
| ',' { String(', ') }
| '+' { String(' + ') }
| '(' { String('(') }
| ')' { String(')') }
| '.' { String('.')}