-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-lbnf.ebnf
99 lines (80 loc) · 1.63 KB
/
tree-sitter-lbnf.ebnf
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// From tree-sitter-lbnf/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
grammar ::=
( def ';' )*
def ::=
label '.' cat '::=' item*
| 'comment' string
| 'comment' string string
| 'internal' label '.' cat '::=' item*
| 'token' ident reg
| 'position' 'token' ident reg
| 'entrypoints' ident ( ',' ident )*
| 'separator' 'nonempty'? cat string
| 'terminator' 'nonempty'? cat string
| 'coercions' ident integer
| 'rules' ident '::=' item* ( '|' item* )*
| 'layout' string ( ',' string )*
| 'layout' 'stop' string ( ',' string )*
| 'layout' 'toplevel'
item ::=
string
| cat
cat ::=
'[' cat ']'
| ident
label ::=
label_id
| label_id prof_item*
| label_id label_id prof_item*
label_id ::=
ident
| '_'
| '[' ']'
| '(' ':' ')'
| '(' ':' '[' ']' ')'
prof_item ::=
'(' '[' ( int_list ( ',' int_list )* )? ']' ',' '[' ( integer ( ',' integer )* )? ']' ')'
int_list ::=
'[' ( integer ( ',' integer )* )? ']'
reg2 ::=
reg2 reg3
| reg3
reg1 ::=
reg1 '|' reg2
| reg2 '-' reg2
| reg2
reg3 ::=
reg3 '*'
| reg3 '+'
| reg3 '?'
| 'eps'
| char
| '[' string ']'
| '{' string '}'
| 'digit'
| 'letter'
| 'upper'
| 'lower'
| 'char'
| '(' reg ')'
reg ::=
reg1
integer ::=
[0-9]+
char ::=
"'" ( escape_sequence | [^#x0A'] ) "'"
string ::=
'"' ( [^\"#x0A]+ | escape_sequence )* '"'
escape_sequence ::=
( '\\' ( [^xuU] | [0-9]'{2,3}' | 'x'[0-9a-fA-F]'{2,}' | 'u'[0-9a-fA-F]'{4}' | 'U'[0-9a-fA-F]'{8}' ) )
ident ::=
[a-zA-Z][a-zA-Z_]*
comment ::=
( '--' '.'* | '{-' ( [^-] | '-'[^}] )* '-}' )