-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-css.ebnf
219 lines (160 loc) · 4.24 KB
/
tree-sitter-css.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
//
// From tree-sitter-css/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
stylesheet ::=
_top_level_item*
_top_level_item ::=
declaration
| rule_set
| import_statement
| media_statement
| charset_statement
| namespace_statement
| keyframes_statement
| supports_statement
| at_rule
import_statement ::=
'@import' _value ( _query ( ',' _query )* )? ';'
media_statement ::=
'@media' _query ( ',' _query )* block
charset_statement ::=
'@charset' _value ';'
namespace_statement ::=
'@namespace' identifier? ( string_value | call_expression ) ';'
keyframes_statement ::=
( '@keyframes' | '@'[-a-z]+'keyframes' ) identifier keyframe_block_list
keyframe_block_list ::=
'{' keyframe_block* '}'
keyframe_block ::=
( from | to | integer_value ) block
from ::=
'from'
to ::=
'to'
supports_statement ::=
'@supports' _query block
postcss_statement ::=
at_keyword _value* ';'
at_rule ::=
at_keyword ( _query ( ',' _query )* )? ( ';' | block )
rule_set ::=
selectors block
selectors ::=
_selector ( ',' _selector )*
block ::=
'{' _block_item* last_declaration? '}'
_block_item ::=
declaration
| rule_set
| import_statement
| media_statement
| charset_statement
| namespace_statement
| keyframes_statement
| supports_statement
| postcss_statement
| at_rule
_selector ::=
universal_selector
| identifier
| class_selector
| nesting_selector
| pseudo_class_selector
| pseudo_element_selector
| id_selector
| attribute_selector
| string_value
| child_selector
| descendant_selector
| sibling_selector
| adjacent_sibling_selector
| namespace_selector
nesting_selector ::=
'&'
universal_selector ::=
'*'
class_selector ::=
_selector? '.' identifier
pseudo_class_selector ::=
_selector? _pseudo_class_selector_colon identifier pseudo_class_arguments?
pseudo_element_selector ::=
_selector? '::' identifier pseudo_element_arguments?
id_selector ::=
_selector? '#' identifier
attribute_selector ::=
_selector? '[' ( identifier | namespace_selector ) ( ( '=' | '~=' | '^=' | '|=' | '*=' | '$=' ) _value )? ']'
child_selector ::=
_selector '>' _selector
descendant_selector ::=
_selector _descendant_operator _selector
sibling_selector ::=
_selector '~' _selector
adjacent_sibling_selector ::=
_selector '+' _selector
namespace_selector ::=
_selector '|' _selector
pseudo_class_arguments ::=
'(' ( ( _selector | _value+ ) ( ',' ( _selector | _value+ ) )* )? ')'
pseudo_element_arguments ::=
'(' ( ( _selector | _value+ ) ( ',' ( _selector | _value+ ) )* )? ')'
declaration ::=
identifier ':' _value ( ','? _value )* important? ';'
last_declaration ::=
identifier ':' _value ( ','? _value )* important?
important ::=
'!important'
_query ::=
identifier
| feature_query
| binary_query
| unary_query
| selector_query
| parenthesized_query
feature_query ::=
'(' identifier ':' _value+ ')'
parenthesized_query ::=
'(' _query ')'
binary_query ::=
_query ( 'and' | 'or' ) _query
unary_query ::=
( 'not' | 'only' ) _query
selector_query ::=
'selector' '(' _selector ')'
_value ::=
identifier | plain_value | color_value | integer_value | float_value | string_value | grid_value | binary_expression | parenthesized_value | call_expression | important
parenthesized_value ::=
'(' _value ')'
color_value ::=
'#' [0-9a-fA-F]'{3,8}'
string_value ::=
"'" ([^'#x0A]|"\"("."|"#x0A"))* "'"
| '"' ([^"#x0A]|'\'('.'|'#x0A'))* '"'
integer_value ::=
( ( '+' | '-' )? [0-9]+ ) unit?
float_value ::=
( ( '+' | '-' )? [0-9]* ( '.' [0-9]+ | [eE] '-'? [0-9]+ | '.' [0-9]+ [eE] '-'? [0-9]+ ) ) unit?
unit ::=
[a-zA-Z%]+
grid_value ::=
'[' _value ( ',' _value )* ']'
call_expression ::=
identifier arguments
binary_expression ::=
_value ( '+' | '-' | '*' | '/' ) _value
arguments ::=
'(' ( _value+ ( ( ',' | ';' ) _value+ )* )? ')'
identifier ::=
('--'|'-'?[a-zA-Z_])[a-zA-Z0-9-_]*
at_keyword ::=
'@'[a-zA-Z-_]+
js_comment ::=
'//' '.'*
comment ::=
( '/*' [^*]*'\'*+([^/*][^*]*'\'*+)* '/' )
plain_value ::=
( ( [-_] | '\/'[^\* #x09#x0A#x0B#x0C#x0D,;!{}()#x5B#x5D] )* [a-zA-Z] ( [^/ #x09#x0A#x0B#x0C#x0D,;!{}()#x5B#x5D] | '\/'[^\* #x09#x0A#x0B#x0C#x0D,;!{}()#x5B#x5D] )* )