forked from m2osw/csspp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.txt
More file actions
183 lines (144 loc) · 3.89 KB
/
syntax.txt
File metadata and controls
183 lines (144 loc) · 3.89 KB
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
The CSS Preprocessor basic syntax follows the normal CSS lexer at its
core. The extensions that we support actually appear in grammar.txt.
Source: http://www.w3.org/TR/css-syntax-3/
##################### CSS Preprocessor Expressions
##################### CSS 3 Grammar
# A stylesheet is what appears in a <style> tag hence the support for
# CDO and CDC tokens
stylesheet: <empty>
| stylesheet-list
stylesheet-list: CDO-TOKEN
| CDC-TOKEN
| WHITESPACE-TOKEN
| qualified-rule
| at-rule
| stylesheet-list stylesheet-list
rule-list: <empty>
| rule
| rule rule-list
rule: WHITESPACE-TOKEN
| qualified-rule
| at-rule
at-rule: AT-KEYWORD-TOKEN component-value-list {}-block
| AT-KEYWORD-TOKEN component-value-list ';'
qualified-rule: component-value-list block
declaration-list: WHITESPACE-TOKEN
| WHITESPACE-TOKEN declaration ';' declaration-list
| WHITESPACE-TOKEN at-rule declaration-list
declaration: IDENT-TOKEN WHITESPACE-TOKEN ':' component-value-list
| IDENT-TOKEN WHITESPACE-TOKEN ':' component-value-list !important
!important: '!' WHITESPACE-TOKEN IDENT-TOKEN(=="important") WHITESPACE-TOKEN
component-value-list: <empty>
| component-value
| component-value component-value-list
component-value: preserved-token
| {}-block
| ()-block
| []-block
| function-block
preserved-token: ANY-TOKEN except '{', '(', '[', FUNCTION-TOKEN
{}-block: '{' component-value-list '}'
()-block: '(' component-value-list ')'
[]-block: '[' component-value-list ']'
function-block: FUNCTION-TOKEN component-value-list ')'
// TODO: determine where these are allowed (probably "declaration" identifiers)
// unless all tokens can be qualified
qualified-name: IDENT-TOKEN
| IDENT-TOKEN '|' IDENT-TOKEN
// Since component values include all tokens as is, we do not need to
// extend anything to support the SASS syntax. CSS 3 already accepts
// entries such as:
//
// a { width: 33px; b { height: 43px; } }
//
##################### CSS 2.2 Grammar
http://dev.w3.org/csswg/css2/grammar.html
stylesheet
: [ CHARSET_SYM STRING ';' ]?
[S|CDO|CDC]* [ import [ CDO S* | CDC S* ]* ]*
[ [ ruleset | media | page ] [ CDO S* | CDC S* ]* ]*
;
import
: IMPORT_SYM S*
[STRING|URI] S* media_list? ';' S*
;
media
: MEDIA_SYM S* media_list '{' S* ruleset* '}' S*
;
media_list
: medium [ COMMA S* medium]*
;
medium
: IDENT S*
;
page
: PAGE_SYM S* pseudo_page?
'{' S* declaration? [ ';' S* declaration? ]* '}' S*
;
pseudo_page
: ':' IDENT S*
;
operator
: '/' S* | ',' S*
;
combinator
: '+' S*
| '>' S*
;
property
: IDENT S*
;
ruleset
: selector [ ',' S* selector ]*
'{' S* declaration? [ ';' S* declaration? ]* '}' S*
;
selector
: simple_selector [ combinator selector | S+ [ combinator? selector ]? ]?
;
simple_selector
: element_name [ HASH | class | attrib | pseudo ]*
| [ HASH | class | attrib | pseudo ]+
;
class
: '.' IDENT
;
element_name
: IDENT | '*'
;
attrib
: '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S*
[ IDENT | STRING ] S* ]? ']'
;
pseudo
: ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ]
;
declaration
: property ':' S* expr prio?
;
prio
: IMPORTANT_SYM S*
;
expr
: term [ operator? term ]*
;
term
: [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
TIME S* | FREQ S* ]
| STRING S* | IDENT S* | URI S* | hexcolor | function
;
function
: FUNCTION S* expr ')' S*
;
/*
* There is a constraint on the color that it must
* have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
* after the "#"; e.g., "#000" is OK, but "#abcd" is not.
*/
hexcolor
: HASH S*
;
# Local Variables:
# indent-tabs-mode: nil
# tab-width: 4
# End:
# vim: ts=4 sw=4 et