-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-nix.ebnf
201 lines (151 loc) · 4.2 KB
/
tree-sitter-nix.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// From tree-sitter-nix/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
source_code ::=
_expression
_expression ::=
_expr_function_expression
keyword ::=
'if'|'then'|'else'|'let'|'inherit'|'in'|'rec'|'with'|'assert'
identifier ::=
[a-zA-Z_][a-zA-Z0-9_\'#x2D-]*
variable_expression ::=
identifier
integer_expression ::=
[0-9]+
float_expression ::=
(([1-9][0-9]*'.'[0-9]*)|('0'?'.'[0-9]+))([Ee][+-]?[0-9]+)?
path_expression ::=
_path_start ( path_fragment | _immediate_interpolation )*
_hpath_start ::=
'\~\/'[a-zA-Z0-9._#x2D-\+\/]+
hpath_expression ::=
_hpath_start ( path_fragment | _immediate_interpolation )*
spath_expression ::=
'<'[a-zA-Z0-9._#x2D-\+]+('\/'[a-zA-Z0-9._#x2D-\+]+)*'>'
uri_expression ::=
[a-zA-Z][a-zA-Z0-9\+#x2D-.]*':'[a-zA-Z0-9%\/\?:@\&=\+\$,#x2D-_.\!\~\*\']+
_expr_function_expression ::=
function_expression
| assert_expression
| with_expression
| let_expression
| _expr_if
function_expression ::=
identifier ':' _expr_function_expression
| formals ':' _expr_function_expression
| formals '@' identifier ':' _expr_function_expression
| identifier '@' formals ':' _expr_function_expression
formals ::=
'{' '}'
| '{' formal ( ',' formal )* '}'
| '{' formal ( ',' formal )* ',' ellipses '}'
| '{' ellipses '}'
formal ::=
identifier ( '?' _expression )?
ellipses ::=
'...'
assert_expression ::=
'assert' _expression ';' _expr_function_expression
with_expression ::=
'with' _expression ';' _expr_function_expression
let_expression ::=
'let' binding_set? 'in' _expr_function_expression
_expr_if ::=
if_expression
| _expr_op
if_expression ::=
'if' _expression 'then' _expression 'else' _expression
_expr_op ::=
has_attr_expression
| unary_expression
| binary_expression
| _expr_apply_expression
has_attr_expression ::=
_expr_op '?' attrpath
unary_expression ::=
'!' _expr_op
| '-' _expr_op
binary_expression ::=
_expr_op '==' _expr_op
| _expr_op '!=' _expr_op
| _expr_op '<' _expr_op
| _expr_op '<=' _expr_op
| _expr_op '>' _expr_op
| _expr_op '>=' _expr_op
| _expr_op '&&' _expr_op
| _expr_op '||' _expr_op
| _expr_op '+' _expr_op
| _expr_op '-' _expr_op
| _expr_op '*' _expr_op
| _expr_op '/' _expr_op
| _expr_op '->' _expr_op
| _expr_op '//' _expr_op
| _expr_op '++' _expr_op
_expr_apply_expression ::=
apply_expression
| _expr_select_expression
apply_expression ::=
_expr_apply_expression _expr_select_expression
_expr_select_expression ::=
select_expression
| _expr_simple
select_expression ::=
_expr_simple '.' attrpath
| _expr_simple '.' attrpath 'or' _expr_select_expression
_expr_simple ::=
variable_expression
| integer_expression
| float_expression
| string_expression
| indented_string_expression
| path_expression
| hpath_expression
| spath_expression
| uri_expression
| parenthesized_expression
| attrset_expression
| let_attrset_expression
| rec_attrset_expression
| list_expression
parenthesized_expression ::=
'(' _expression ')'
attrset_expression ::=
'{' binding_set? '}'
let_attrset_expression ::=
'let' '{' binding_set? '}'
rec_attrset_expression ::=
'rec' '{' binding_set? '}'
string_expression ::=
'"' ( string_fragment | interpolation | escape_sequence | dollar_escape '$' )* '"'
escape_sequence ::=
'\'([^$]|[ #x09#x0A#x0B#x0C#x0D])
indented_string_expression ::=
"''" ( _indented_string_fragment | interpolation | _indented_escape_sequence | _indented_dollar_escape '$' )* "''"
_indented_escape_sequence ::=
"'''"|"''\"([^$]|[ #x09#x0A#x0B#x0C#x0D])
binding_set ::=
( binding | inherit | inherit_from )+
binding ::=
attrpath '=' _expression ';'
inherit ::=
'inherit' inherited_attrs ';'
inherit_from ::=
'inherit' '(' _expression ')' inherited_attrs ';'
attrpath ::=
( identifier | string_expression | interpolation ) ( '.' ( identifier | string_expression | interpolation ) )*
inherited_attrs ::=
( identifier | string_expression | interpolation )+
_immediate_interpolation ::=
'${' _expression '}'
interpolation ::=
'${' _expression '}'
list_expression ::=
'[' _expr_select_expression* ']'
comment ::=
( '#' '.'* | '/*' [^*]*'\'*+([^/*][^*]*'\'*+)* '/' )