-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-hcl.ebnf
232 lines (166 loc) · 4.17 KB
/
tree-sitter-hcl.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//
// From tree-sitter-hcl/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
config_file ::=
body | object
body ::=
( attribute | block )+
attribute ::=
identifier '=' expression
block ::=
identifier ( string_lit | identifier )* block_start body? block_end
block_start ::=
'{'
block_end ::=
'}'
identifier ::=
( ( '\p{ID_Start}' | '_' ) ( '\p{ID_Continue}' | '-' )* )
expression ::=
_expr_term | conditional
_expr_term ::=
literal_value
| template_expr
| collection_value
| variable_expr
| function_call
| for_expr
| operation
| _expr_term index
| _expr_term get_attr
| _expr_term splat
| '(' expression ')'
literal_value ::=
numeric_lit
| bool_lit
| null_lit
| string_lit
numeric_lit ::=
[0-9]+('.'[0-9]+([eE][-+]?[0-9]+)?)?
| '0x'[0-9a-zA-Z]+
bool_lit ::=
'true'
| 'false'
null_lit ::=
'null'
string_lit ::=
quoted_template_start template_literal? quoted_template_end
collection_value ::=
tuple
| object
_comma ::=
','
tuple ::=
tuple_start _tuple_elems? tuple_end
tuple_start ::=
'['
tuple_end ::=
']'
_tuple_elems ::=
expression ( _comma expression )* _comma?
object ::=
object_start _object_elems? object_end
object_start ::=
'{'
object_end ::=
'}'
_object_elems ::=
object_elem ( _comma? object_elem )* _comma?
object_elem ::=
expression ( '=' | ':' ) expression
index ::=
new_index
| legacy_index
new_index ::=
'[' expression ']'
legacy_index ::=
'.' [0-9]+
get_attr ::=
'.' identifier
splat ::=
attr_splat
| full_splat
attr_splat ::=
'.*' ( get_attr | index )*
full_splat ::=
'[*]' ( get_attr | index )*
for_expr ::=
for_tuple_expr
| for_object_expr
for_tuple_expr ::=
tuple_start for_intro expression for_cond? tuple_end
for_object_expr ::=
object_start for_intro expression '=>' expression ellipsis? for_cond? object_end
for_intro ::=
'for' identifier ( ',' identifier )? 'in' expression ':'
for_cond ::=
'if' expression
variable_expr ::=
identifier
function_call ::=
identifier _function_call_start function_arguments? _function_call_end
_function_call_start ::=
'('
_function_call_end ::=
')'
function_arguments ::=
expression ( _comma expression )* ( _comma | ellipsis )?
ellipsis ::=
'...'
conditional ::=
expression '?' expression ':' expression
operation ::=
unary_operation
| binary_operation
unary_operation ::=
( '-' | '!' ) _expr_term
binary_operation ::=
_expr_term ( '*' | '/' | '%' ) _expr_term
| _expr_term ( '+' | '-' ) _expr_term
| _expr_term ( '>' | '>=' | '<' | '<=' ) _expr_term
| _expr_term ( '==' | '!=' ) _expr_term
| _expr_term ( '&&' ) _expr_term
| _expr_term ( '||' ) _expr_term
template_expr ::=
quoted_template
| heredoc_template
quoted_template ::=
quoted_template_start _template? quoted_template_end
heredoc_template ::=
heredoc_start heredoc_identifier _template? heredoc_identifier
heredoc_start ::=
'<<'
| '<<-'
strip_marker ::=
'~'
_template ::=
( template_interpolation | template_directive | template_literal )+
template_literal ::=
_template_literal_chunk+
template_interpolation ::=
template_interpolation_start strip_marker? expression? strip_marker? template_interpolation_end
template_directive ::=
template_for
| template_if
template_for ::=
template_for_start _template? template_for_end
template_for_start ::=
template_directive_start strip_marker? 'for' identifier ( ',' identifier )? 'in' expression strip_marker? template_directive_end
template_for_end ::=
template_directive_start strip_marker? 'endfor' strip_marker? template_directive_end
template_if ::=
template_if_intro _template? ( template_else_intro _template? )? template_if_end
template_if_intro ::=
template_directive_start strip_marker? 'if' expression strip_marker? template_directive_end
template_else_intro ::=
template_directive_start strip_marker? 'else' strip_marker? template_directive_end
template_if_end ::=
template_directive_start strip_marker? 'endif' strip_marker? template_directive_end
comment ::=
( '#' '.'* | '//' '.'* | '/*' [^*]*'\'*+([^/*][^*]*'\'*+)* '/' )
_whitespace ::=
[ #x09#x0A#x0B#x0C#x0D]