Mon, 12 Aug 2013 15:17:33 +0100
[css-syntax] Return U+FFFD for escaped surrogate code points.
1 <h1>CSS Syntax Module Level 3</h1>
3 <pre class='metadata'>
4 Status: ED
5 ED: http://dev.w3.org/csswg/css-syntax
6 Shortname: css-syntax
7 Level: 3
8 Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/
9 Editor: Simon Sapin, Mozilla, http://exyr.org/about/
10 Abstract: This module describes, in general terms, the basic structure and syntax of CSS stylesheets. It defines, in detail, the syntax and parsing of CSS - how to turn a stream of bytes into a meaningful stylesheet.
11 Ignored Properties: color, animation-timing-function, text-decoration
12 Ignored Terms: <keyframes-name>, <keyframe-rule>, <keyframe-selector>, <translation-value>, <media-query-list>, <string>
13 </pre>
15 <link href="railroad-diagrams.css" rel="stylesheet" type="text/css">
17 <h2 id="intro">
18 Introduction</h2>
20 <em>This section is not normative.</em>
22 This module defines the abstract syntax and parsing of CSS stylesheets
23 and other things which use CSS syntax
24 (such as the HTML <code>style</code> attribute).
26 It defines algorithms for converting a stream of codepoints
27 (in other words, text)
28 into a stream of CSS tokens,
29 and then further into CSS objects
30 such as stylesheets, rules, and declarations.
32 <h3 id="placement">
33 Module interactions</h3>
35 This module defines the syntax and parsing of CSS stylesheets.
36 It supersedes the lexical scanner and grammar defined in CSS 2.1.
38 <h2 id='syntax-description'>
39 Description of CSS's Syntax</h2>
41 <em>This section is not normative.</em>
43 A CSS document is a series of <a>qualified rules</a>,
44 which are usually style rules that apply CSS properties to elements,
45 and <a>at-rules</a>,
46 which define special processing rules or values for the CSS document.
48 A qualified rule starts with a prelude
49 then has a {}-wrapped block containing a sequence of declarations.
50 The meaning of the prelude varies based on the context that the rule appears in -
51 for style rules, it's a selector which specifies what elements the declarations will apply to.
52 Each declaration has a name,
53 followed by a colon and the declaration value.
54 Declarations are separated by semicolons.
56 <div class='example'>
58 A typical rule might look something like this:
60 <pre>
61 p > a {
62 color: blue;
63 text-decoration: underline;
64 }
65 </pre>
67 In the above rule, "<code>p > a</code>" is the selector,
68 which, if the source document is HTML,
69 selects any <code><a></code> elements that are children of a <code><p></code> element.
71 "<code>color: blue;</code>" is a declaration specifying that,
72 for the elements that match the selector,
73 their 'color' property should have the value ''blue''.
74 Similiarly, their 'text-decoration' property should have the value ''underline''.
75 </div>
77 At-rules are all different, but they have a basic structure in common.
78 They start with an "@" character followed by their name.
79 Some <a>at-rules</a> are simple statements,
80 with their name followed by more CSS values to specify their behavior,
81 and finally ended by a semicolon.
82 Others are blocks;
83 they can have CSS values following their name,
84 but they end with a {}-wrapped block,
85 similar to a <a>qualified rule</a>.
86 Even the contents of these blocks are specific to the given <a>at-rule</a>:
87 sometimes they contain a sequence of declarations, like a <a>qualified rule</a>;
88 other times, they may contain additional blocks, or at-rules, or other structures altogether.
90 <div class='example'>
92 Here are several examples of <a>at-rules</a> that illustrate the varied syntax they may contain.
94 <pre>@import "my-styles.css";</pre>
96 The ''@import'' <a>at-rule</a> is a simple statement.
97 After its name, it takes a single string or ''url()'' function to indicate the stylesheet that it should import.
99 <pre>
100 @page :left {
101 margin-left: 4cm;
102 margin-right: 3cm;
103 }
104 </pre>
106 The ''@page'' <a>at-rule</a> consists of an optional page selector (the '':left'' pseudoclass),
107 followed by a block of properties that apply to the page when printed.
108 In this way, it's very similar to a normal style rule,
109 except that its properties don't apply to any "element",
110 but rather the page itself.
112 <pre>
113 @media print {
114 body { font-size: 10pt }
115 }
116 </pre>
118 The ''@media'' <a>at-rule</a> begins with a media type
119 and a list of optional media queries.
120 Its block contains entire rules,
121 which are only applied when the ''@media''s conditions are fulfilled.
122 </div>
124 Property names and <a>at-rule</a> names are always <b>identifiers</b>,
125 which have to start with a letter or a hyphen followed by a letter,
126 and then can contain letters, numbers, hyphens, or underscores.
127 You can include any character at all,
128 even ones that CSS uses in its syntax,
129 by <a>escaping</a> it.
131 The syntax of selectors is defined in the <a href="http://www.w3.org/TR/selectors/">Selectors spec</a>.
132 Similarly, the syntax of the wide variety of CSS values is defined in the <a href="http://www.w3.org/TR/css3-values/">Values & Units spec</a>.
133 The special syntaxes of individual <a>at-rules</a> can be found in the specs that define them.
135 <h3>
136 Escaping</h3>
138 <em>This section is not normative.</em>
140 Any Unicode character can be included in an identifier or quoted string
141 by <dfn>escaping</dfn> it.
142 CSS escape sequences start with a backslash (\), and continue with:
144 <ul>
145 <li>
146 Any Unicode character that is not a <a>hex digits</a> or a <a>newline</a>.
147 The escape sequence is replaced by that character.
148 <li>
149 Or one to six <a>hex digits</a>, followed by an optional <a>whitespace</a>.
150 The escape sequence is replaced by the Unicode character
151 whose codepoint number is given by the hexadecimal digits.
152 This optional whitespace allow hexadecimal escape sequences
153 to be followed by "real" hex digits.
155 <p class=example>
156 An identifier with the value "&B"
157 could be written as ''\26 B'' or ''\000026B''.
159 <p class=note>
160 A "real" space after the escape sequence must be doubled.
161 </ul>
163 <h3>
164 Error Handling</h3>
166 <em>This section is not normative.</em>
168 When errors occur in CSS,
169 the parser attempts to recover gracefully,
170 throwing away only the minimum amount of content
171 before returning to parsing as normal.
172 This is because errors aren't always mistakes -
173 new syntax looks like an error to an old parser,
174 and it's useful to be able to add new syntax to the language
175 without worrying about stylesheets that include it being completely broken in older UAs.
177 The precise error-recovery behavior is detailed in the parser itself,
178 but it's simple enough that a short description is fairly accurate:
180 <ul>
181 <li>
182 At the "top level" of a stylesheet,
183 an 〈at-keyword〉 starts an at-rule.
184 Anything else starts a qualified rule,
185 and is included in the rule's prelude.
186 This may produce an invalid selector,
187 but that's not the concern of the CSS parser —
188 at worst, it means the selector will match nothing.
190 <li>
191 Once an at-rule starts,
192 nothing is invalid from the parser's standpoint;
193 it's all part of the at-rule's prelude.
194 Encountering a semicolon 〈;〉 ends the at-rule immediately,
195 while encountering an opening curly-brace 〈{〉 starts the at-rule's body.
196 The at-rule seeks forward, matching blocks (content surrounded by (), {}, or [])
197 until it finds a closing curly-brace 〈}〉 that isn't matched by anything else
198 or inside of another block.
199 The contents of the at-rule are then interpreted according to the at-rule's own grammar.
201 <li>
202 Qualified rules work similarly,
203 except that semicolons don't end them;
204 instead, they are just taken in as part of the rule's prelude.
205 When the first {} block is found,
206 the contents are always interpreted as a list of declarations.
208 <li>
209 When interpreting a list of declarations,
210 unknown syntax at any point causes the parser to throw away whatever declaration it's currently building,
211 and seek forward until it finds a semicolon (or the end of the block).
212 It then starts fresh, trying to parse a declaration again.
214 <li>
215 If the stylesheet ends while any rule, declaration, function, string, etc. are still open,
216 everything is automatically closed.
217 This doesn't make them invalid,
218 though they may be incomplete
219 and thus thrown away when they are verified against their grammar.
220 </ul>
222 <h2>
223 Tokenizing and Parsing CSS</h2>
225 User agents must use the parsing rules described in this specification
226 to generate the CSSOM trees from text/css resources.
227 Together, these rules define what is referred to as the CSS parser.
229 This specification defines the parsing rules for CSS documents,
230 whether they are syntactically correct or not.
231 Certain points in the parsing algorithm are said to be a <dfn title="parse error">parse errors</dfn>.
232 The error handling for parse errors is well-defined:
233 user agents must either act as described below when encountering such problems,
234 or must abort processing at the first error that they encounter for which they do not wish to apply the rules described below.
236 Conformance checkers must report at least one parse error condition to the user
237 if one or more parse error conditions exist in the document
238 and must not report parse error conditions
239 if none exist in the document.
240 Conformance checkers may report more than one parse error condition if more than one parse error condition exists in the document.
241 Conformance checkers are not required to recover from parse errors,
242 but if they do,
243 they must recover in the same way as user agents.
245 <h3>
246 Overview of the Parsing Model</h3>
248 The input to the CSS parsing process consists of a stream of Unicode code points,
249 which is passed through a tokenization stage followed by a tree construction stage.
250 The output is a CSSStyleSheet object.
252 Note: Implementations that do not support scripting do not have to actually create a CSSOM CSSStyleSheet object,
253 but the CSSOM tree in such cases is still used as the model for the rest of the specification.
255 <h3>
256 The input byte stream</h3>
258 When parsing a stylesheet,
259 the stream of Unicode code points that comprises the input to the tokenization stage may be initially seen by the user agent as a stream of bytes
260 (typically coming over the network or from the local file system).
261 The bytes encode the actual characters according to a particular character encoding,
262 which the user agent must use to decode the bytes into characters.
264 To decode the stream of bytes into a stream of characters,
265 UAs must follow these steps.
267 The algorithms to <a href="http://encoding.spec.whatwg.org/#concept-encoding-get"><dfn>get an encoding</dfn></a>
268 and <a href="http://encoding.spec.whatwg.org/#decode"><dfn>decode</dfn></a>
269 are defined in the <a href="http://encoding.spec.whatwg.org/">Encoding Standard</a>.
271 First, <dfn>determine the fallback encoding</dfn>:
273 <ol>
274 <li>
275 If HTTP or equivalent protocol defines an encoding (e.g. via the charset parameter of the Content-Type header),
276 <a>get an encoding</a> for the specified value.
277 If that does not return failure,
278 use the return value as the fallback encoding.
280 <li>
281 Otherwise, check the byte stream. If the first several bytes match the hex sequence
283 <pre>40 63 68 61 72 73 65 74 20 22 (not 22)* 22 3B</pre>
285 then <a>get an encoding</a> for the sequence of <code>(not 22)*</code> bytes,
286 decoded per <code>windows-1252</code>.
288 Note: Anything ASCII-compatible will do, so using <code>windows-1252</code> is fine.
291 Note: The byte sequence above,
292 when decoded as ASCII,
293 is the string "<code>@charset "…";</code>",
294 where the "…" is the sequence of bytes corresponding to the encoding's name.
296 If the return value was <code>utf-16</code> or <code>utf-16be</code>,
297 use <code>utf-8</code> as the fallback encoding;
298 if it was anything else except failure,
299 use the return value as the fallback encoding.
301 Note: This mimics HTML <code><meta></code> behavior.
303 <li>
304 Otherwise, <a>get an encoding</a> for the value of the <code>charset</code> attribute on the <code><link></code> element or <code><?xml-stylesheet?></code> processing instruction that caused the style sheet to be included, if any.
305 If that does not return failure,
306 use the return value as the fallback encoding.
308 <li>
309 Otherwise, if the referring style sheet or document has an encoding,
310 use that as the fallback encoding.
312 <li>
313 Otherwise, use <code>utf-8</code> as the fallback encoding.
314 </ol>
316 Then, <a>decode</a> the byte stream using the fallback encoding.
318 Note: the <a>decode</a> algorithm lets the byte order mark (BOM) take precedence,
319 hence the usage of the term "fallback" above.
321 <p class='issue'>
322 Anne says that steps 3/4 should be an input to this algorithm from the specs that define importing stylesheet,
323 to make the algorithm as a whole cleaner.
324 Perhaps abstract it into the concept of an "environment charset" or something?
326 <p class='issue'>
327 Should we only take the charset from the referring document if it's same-origin?
330 <h3>
331 Preprocessing the input stream</h3>
333 The input stream consists of the characters (individual unicode code-points)
334 pushed into it as the input byte stream is decoded.
336 Before sending the input stream to the tokenizer,
337 implementations must make the following character substitutions:
339 <ul>
340 <li>
341 Replace any U+000D CARRIAGE RETURN (CR) characters,
342 U+000C FORM FEED (FF) characters,
343 or pairs of U+000D CARRIAGE RETURN (CR) followed by U+000A LINE FEED (LF)
344 by a single U+000A LINE FEED (LF) character.
346 <li>
347 Replace any U+0000 NULL characters with U+FFFD REPLACEMENT CHARACTER (�).
348 </ul>
351 <h2>
352 Tokenization</h2>
354 Implementations must act as if they used the following algorithms to tokenize CSS.
355 To transform a stream of characters into a stream of tokens,
356 repeatedly <a>consume a token</a>
357 until an 〈EOF〉 is reached,
358 collecting the returned tokens into a stream.
359 Each call to the <a>consume a token</a> algorithm
360 returns a single token,
361 so it can also be used "on-demand" to tokenize a stream of characters <em>during</em> parsing,
362 if so desired.
364 The output of the tokenization step is a stream of zero or more of the following tokens:
365 〈ident〉,
366 〈function〉,
367 〈at-keyword〉,
368 〈hash〉,
369 〈string〉,
370 〈bad-string〉,
371 〈url〉,
372 〈bad-url〉,
373 〈delim〉,
374 〈number〉,
375 〈percentage〉,
376 〈dimension〉,
377 〈unicode-range〉,
378 〈include-match〉,
379 〈dash-match〉,
380 〈prefix-match〉,
381 〈suffix-match〉,
382 〈substring-match〉,
383 〈column〉,
384 〈whitespace〉,
385 〈CDO〉,
386 〈CDC〉,
387 〈colon〉,
388 〈semicolon〉,
389 〈comma〉,
390 〈[〉,
391 〈]〉,
392 〈(〉,
393 〈)〉,
394 〈{〉,
395 and 〈}〉.
397 <ul>
398 <li>
399 〈ident〉, 〈function〉, 〈at-keyword〉, 〈hash〉, 〈string〉, and 〈url〉 tokens have a value composed of zero or more characters.
400 Additionally, hash tokens have a type flag set to either "id" or "unrestricted". The type flag defaults to "unrestricted" if not otherwise set.
402 <li>
403 〈delim〉 tokens have a value composed of a single character.
405 <li>
406 〈number〉, 〈percentage〉, and 〈dimension〉 tokens have a representation composed of one or more character, and a numeric value.
407 〈number〉 and 〈dimension〉 tokens additionally have a type flag set to either "integer" or "number". The type flag defaults to "integer" if not otherwise set.
408 〈dimension〉 tokens additionally have a unit composed of one or more characters.
410 <li>
411 〈unicode-range〉 tokens have a range of characters.
412 </ul>
414 Note: The type flag of hash tokens is used in the Selectors syntax [[SELECT]].
415 Only hash tokens with the "id" type are valid <a href="http://www.w3.org/TR/selectors/#id-selectors">ID selectors</a>.
417 Note: As a technical note,
418 the tokenizer defined here requires only three characters of look-ahead.
419 The tokens it produces are designed to allow Selectors to be parsed with one token of look-ahead,
420 and additional tokens may be added in the future to maintain this invariant.
423 <h3 id='token-diagrams'>
424 Token Railroad Diagrams</h3>
426 <em>This section is non-normative.</em>
428 This section presents an informative view of the tokenizer,
429 in the form of railroad diagrams.
430 Railroad diagrams are more compact than an explicit parser,
431 but often easier to read than an regular expression.
433 These diagrams are <em>informative</em> and <em>incomplete</em>;
434 they describe the grammar of "correct" tokens,
435 but do not describe error-handling at all.
436 They are provided solely to make it easier to get an intuitive grasp of the syntax of each token.
438 Diagrams with names between 〈〉 brackets represent tokens.
439 The rest are productions referred to by other diagrams.
441 <!--
442 The "source" of these diagrams is in ./Diagrams.src.html
443 The generated SVG is copied here so that JavaScript is not required
444 to view the spec.
445 -->
447 <dl>
448 <dt id="comment-diagram">comment</dt>
449 <dd><svg class="railroad-diagram" width="497" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M86 41h0"></path><rect x="50" y="30" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="45">/*</text></g><path d="M86 41h10"></path><g><path d="M96 41h0"></path><path d="M400 41h0"></path><path d="M96 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M116 21h264"></path></g><path d="M380 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M96 41h20"></path><g><path d="M116 41h0"></path><path d="M380 41h0"></path><path d="M116 41h10"></path><g><path d="M126 41h0"></path><path d="M370 41h0"></path><rect x="126" y="30" width="244" height="22"></rect><text x="248" y="45">anything but * followed by /</text></g><path d="M370 41h10"></path><path d="M126 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M126 61h244"></path></g><path d="M370 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M380 41h20"></path></g><path d="M400 41h10"></path><g><path d="M410 41h0"></path><path d="M446 41h0"></path><rect x="410" y="30" width="36" height="22" rx="10" ry="10"></rect><text x="428" y="45">*/</text></g><path d="M446 41h10"></path><path d="M 456 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
451 <dt id="newline-diagram">newline</dt>
452 <dd><svg class="railroad-diagram" width="173" height="152"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 31h0"></path><path d="M132 31h0"></path><path d="M40 31h20"></path><g><path d="M60 31h8"></path><path d="M104 31h8"></path><rect x="68" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="86" y="35">\n</text></g><path d="M112 31h20"></path><path d="M40 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M60 61h0"></path><path d="M112 61h0"></path><rect x="60" y="50" width="52" height="22" rx="10" ry="10"></rect><text x="86" y="65">\r\n</text></g><path d="M112 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><path d="M40 31a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10"></path><g><path d="M60 91h8"></path><path d="M104 91h8"></path><rect x="68" y="80" width="36" height="22" rx="10" ry="10"></rect><text x="86" y="95">\r</text></g><path d="M112 91a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10"></path><path d="M40 31a10 10 0 0 1 10 10v70a10 10 0 0 0 10 10"></path><g><path d="M60 121h8"></path><path d="M104 121h8"></path><rect x="68" y="110" width="36" height="22" rx="10" ry="10"></rect><text x="86" y="125">\f</text></g><path d="M112 121a10 10 0 0 0 10 -10v-70a10 10 0 0 1 10 -10"></path></g><path d="M 132 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
454 <dt id="whitespace-character-diagram">whitespace character</dt>
455 <dd><svg class="railroad-diagram" width="197" height="122"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 31h0"></path><path d="M156 31h0"></path><path d="M40 31h20"></path><g><path d="M60 31h8"></path><path d="M128 31h8"></path><rect x="68" y="20" width="60" height="22" rx="10" ry="10"></rect><text x="98" y="35">space</text></g><path d="M136 31h20"></path><path d="M40 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M60 61h20"></path><path d="M116 61h20"></path><rect x="80" y="50" width="36" height="22" rx="10" ry="10"></rect><text x="98" y="65">\t</text></g><path d="M136 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><path d="M40 31a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10"></path><g><path d="M60 91h0"></path><path d="M136 91h0"></path><rect x="60" y="80" width="76" height="22"></rect><text x="98" y="95">newline</text></g><path d="M136 91a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10"></path></g><path d="M 156 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
457 <dt id="escape-diagram">escape</dt>
458 <dd><svg class="railroad-diagram" width="521" height="122"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M78 31h0"></path><rect x="50" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="35">\</text></g><path d="M78 31h10"></path><g><path d="M88 31h0"></path><path d="M480 31h0"></path><path d="M88 31h20"></path><g><path d="M108 31h70"></path><path d="M390 31h70"></path><rect x="178" y="20" width="212" height="22"></rect><text x="284" y="35">not newline or hex digit</text></g><path d="M460 31h20"></path><path d="M88 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M108 61h0"></path><path d="M460 61h0"></path><path d="M108 61h10"></path><g><path d="M118 61h0"></path><path d="M230 61h0"></path><path d="M118 61h10"></path><g><path d="M128 61h0"></path><path d="M220 61h0"></path><rect x="128" y="50" width="92" height="22"></rect><text x="174" y="65">hex digit</text></g><path d="M220 61h10"></path><path d="M128 61a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10"></path><g><path d="M128 91h9.5"></path><path d="M210.5 91h9.5"></path><text x="174" y="96" class="comment">1-6 times</text></g><path d="M220 91a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10"></path></g><path d="M230 61h10"></path><g><path d="M240 61h0"></path><path d="M460 61h0"></path><path d="M240 61h20"></path><g><path d="M260 61h180"></path></g><path d="M440 61h20"></path><path d="M240 61a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><g><path d="M260 81h0"></path><path d="M440 81h0"></path><rect x="260" y="70" width="180" height="22"></rect><text x="350" y="85">whitespace character</text></g><path d="M440 81a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path></g></g><path d="M460 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M 480 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
460 <dt id="〈whitespace〉-diagram">〈whitespace〉</dt>
461 <dd><svg class="railroad-diagram" width="301" height="71"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M250 31h0"></path><path d="M50 31h10"></path><g><path d="M60 31h0"></path><path d="M240 31h0"></path><rect x="60" y="20" width="180" height="22"></rect><text x="150" y="35">whitespace character</text></g><path d="M240 31h10"></path><path d="M60 31a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M60 51h180"></path></g><path d="M240 51a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M250 31h10"></path><path d="M 260 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
463 <dt id="〈ident〉-diagram">〈ident〉</dt>
464 <dd><svg class="railroad-diagram" width="729" height="110"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 41h0"></path><path d="M108 41h0"></path><path d="M40 41h20"></path><g><path d="M60 41h28"></path></g><path d="M88 41h20"></path><path d="M40 41a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><g><path d="M60 61h0"></path><path d="M88 61h0"></path><rect x="60" y="50" width="28" height="22" rx="10" ry="10"></rect><text x="74" y="65">-</text></g><path d="M88 61a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path></g><g><path d="M108 41h0"></path><path d="M344 41h0"></path><path d="M108 41h20"></path><g><path d="M128 41h0"></path><path d="M324 41h0"></path><rect x="128" y="30" width="196" height="22"></rect><text x="226" y="45">a-z A-Z _ or non-ASCII</text></g><path d="M324 41h20"></path><path d="M108 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M128 71h64"></path><path d="M260 71h64"></path><rect x="192" y="60" width="68" height="22"></rect><text x="226" y="75">escape</text></g><path d="M324 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><g><path d="M344 41h0"></path><path d="M688 41h0"></path><path d="M344 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M364 21h304"></path></g><path d="M668 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M344 41h20"></path><g><path d="M364 41h0"></path><path d="M668 41h0"></path><path d="M364 41h10"></path><g><path d="M374 41h0"></path><path d="M658 41h0"></path><path d="M374 41h20"></path><g><path d="M394 41h0"></path><path d="M638 41h0"></path><rect x="394" y="30" width="244" height="22"></rect><text x="516" y="45">a-z A-Z 0-9 _ - or non-ASCII</text></g><path d="M638 41h20"></path><path d="M374 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M394 71h88"></path><path d="M550 71h88"></path><rect x="482" y="60" width="68" height="22"></rect><text x="516" y="75">escape</text></g><path d="M638 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M658 41h10"></path><path d="M374 41a10 10 0 0 0 -10 10v29a10 10 0 0 0 10 10"></path><g><path d="M374 90h284"></path></g><path d="M658 90a10 10 0 0 0 10 -10v-29a10 10 0 0 0 -10 -10"></path></g><path d="M668 41h20"></path></g><path d="M 688 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
466 <dt id="〈function〉-diagram">〈function〉</dt>
467 <dd><svg class="railroad-diagram" width="225" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M126 31h0"></path><rect x="50" y="20" width="76" height="22"></rect><text x="88" y="35">〈ident〉</text></g><path d="M126 31h10"></path><path d="M136 31h10"></path><g><path d="M146 31h0"></path><path d="M174 31h0"></path><rect x="146" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="160" y="35">(</text></g><path d="M174 31h10"></path><path d="M 184 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
469 <dt id="〈at-keyword〉-diagram">〈at-keyword〉</dt>
470 <dd><svg class="railroad-diagram" width="225" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M78 31h0"></path><rect x="50" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="35">@</text></g><path d="M78 31h10"></path><path d="M88 31h10"></path><g><path d="M98 31h0"></path><path d="M174 31h0"></path><rect x="98" y="20" width="76" height="22"></rect><text x="136" y="35">〈ident〉</text></g><path d="M174 31h10"></path><path d="M 184 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
472 <dt id="〈hash〉-diagram">〈hash〉</dt>
473 <dd><svg class="railroad-diagram" width="453" height="100"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M78 31h0"></path><rect x="50" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="35">#</text></g><path d="M78 31h10"></path><path d="M88 31h10"></path><g><path d="M98 31h0"></path><path d="M402 31h0"></path><path d="M98 31h10"></path><g><path d="M108 31h0"></path><path d="M392 31h0"></path><path d="M108 31h20"></path><g><path d="M128 31h0"></path><path d="M372 31h0"></path><rect x="128" y="20" width="244" height="22"></rect><text x="250" y="35">a-z A-Z 0-9 _ - or non-ASCII</text></g><path d="M372 31h20"></path><path d="M108 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M128 61h88"></path><path d="M284 61h88"></path><rect x="216" y="50" width="68" height="22"></rect><text x="250" y="65">escape</text></g><path d="M372 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M392 31h10"></path><path d="M108 31a10 10 0 0 0 -10 10v29a10 10 0 0 0 10 10"></path><g><path d="M108 80h284"></path></g><path d="M392 80a10 10 0 0 0 10 -10v-29a10 10 0 0 0 -10 -10"></path></g><path d="M402 31h10"></path><path d="M 412 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
475 <dt id="〈string〉-diagram">〈string〉</dt>
476 <dd><svg class="railroad-diagram" width="481" height="248"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 41h0"></path><path d="M440 41h0"></path><path d="M40 41h20"></path><g><path d="M60 41h0"></path><path d="M420 41h0"></path><path d="M60 41h10"></path><g><path d="M70 41h0"></path><path d="M98 41h0"></path><rect x="70" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="84" y="45">"</text></g><path d="M98 41h10"></path><g><path d="M108 41h0"></path><path d="M372 41h0"></path><path d="M108 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M128 21h224"></path></g><path d="M352 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M108 41h20"></path><g><path d="M128 41h0"></path><path d="M352 41h0"></path><path d="M128 41h10"></path><g><path d="M138 41h0"></path><path d="M342 41h0"></path><path d="M138 41h20"></path><g><path d="M158 41h0"></path><path d="M322 41h0"></path><rect x="158" y="30" width="164" height="22"></rect><text x="240" y="45">not " \ or newline</text></g><path d="M322 41h20"></path><path d="M138 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M158 71h48"></path><path d="M274 71h48"></path><rect x="206" y="60" width="68" height="22"></rect><text x="240" y="75">escape</text></g><path d="M322 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><path d="M138 41a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10"></path><g><path d="M158 101h10"></path><path d="M312 101h10"></path><path d="M168 101h10"></path><g><path d="M178 101h0"></path><path d="M206 101h0"></path><rect x="178" y="90" width="28" height="22" rx="10" ry="10"></rect><text x="192" y="105">\</text></g><path d="M206 101h10"></path><path d="M216 101h10"></path><g><path d="M226 101h0"></path><path d="M302 101h0"></path><rect x="226" y="90" width="76" height="22"></rect><text x="264" y="105">newline</text></g><path d="M302 101h10"></path></g><path d="M322 101a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10"></path></g><path d="M342 41h10"></path><path d="M138 41a10 10 0 0 0 -10 10v59a10 10 0 0 0 10 10"></path><g><path d="M138 120h204"></path></g><path d="M342 120a10 10 0 0 0 10 -10v-59a10 10 0 0 0 -10 -10"></path></g><path d="M352 41h20"></path></g><path d="M372 41h10"></path><g><path d="M382 41h0"></path><path d="M410 41h0"></path><rect x="382" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="396" y="45">"</text></g><path d="M410 41h10"></path></g><path d="M420 41h20"></path><path d="M40 41a10 10 0 0 1 10 10v88a10 10 0 0 0 10 10"></path><g><path d="M60 149h0"></path><path d="M420 149h0"></path><path d="M60 149h10"></path><g><path d="M70 149h0"></path><path d="M98 149h0"></path><rect x="70" y="138" width="28" height="22" rx="10" ry="10"></rect><text x="84" y="153">'</text></g><path d="M98 149h10"></path><g><path d="M108 149h0"></path><path d="M372 149h0"></path><path d="M108 149a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M128 129h224"></path></g><path d="M352 129a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M108 149h20"></path><g><path d="M128 149h0"></path><path d="M352 149h0"></path><path d="M128 149h10"></path><g><path d="M138 149h0"></path><path d="M342 149h0"></path><path d="M138 149h20"></path><g><path d="M158 149h0"></path><path d="M322 149h0"></path><rect x="158" y="138" width="164" height="22"></rect><text x="240" y="153">not ' \ or newline</text></g><path d="M322 149h20"></path><path d="M138 149a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M158 179h48"></path><path d="M274 179h48"></path><rect x="206" y="168" width="68" height="22"></rect><text x="240" y="183">escape</text></g><path d="M322 179a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><path d="M138 149a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10"></path><g><path d="M158 209h10"></path><path d="M312 209h10"></path><path d="M168 209h10"></path><g><path d="M178 209h0"></path><path d="M206 209h0"></path><rect x="178" y="198" width="28" height="22" rx="10" ry="10"></rect><text x="192" y="213">\</text></g><path d="M206 209h10"></path><path d="M216 209h10"></path><g><path d="M226 209h0"></path><path d="M302 209h0"></path><rect x="226" y="198" width="76" height="22"></rect><text x="264" y="213">newline</text></g><path d="M302 209h10"></path></g><path d="M322 209a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10"></path></g><path d="M342 149h10"></path><path d="M138 149a10 10 0 0 0 -10 10v59a10 10 0 0 0 10 10"></path><g><path d="M138 228h204"></path></g><path d="M342 228a10 10 0 0 0 10 -10v-59a10 10 0 0 0 -10 -10"></path></g><path d="M352 149h20"></path></g><path d="M372 149h10"></path><g><path d="M382 149h0"></path><path d="M410 149h0"></path><rect x="382" y="138" width="28" height="22" rx="10" ry="10"></rect><text x="396" y="153">'</text></g><path d="M410 149h10"></path></g><path d="M420 149a10 10 0 0 0 10 -10v-88a10 10 0 0 1 10 -10"></path></g><path d="M 440 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
478 <dt id="〈url〉-diagram">〈url〉</dt>
479 <dd><svg class="railroad-diagram" width="829" height="102"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M174 41h0"></path><rect x="50" y="30" width="124" height="22"></rect><text x="112" y="45">〈ident "url"〉</text></g><path d="M174 41h10"></path><path d="M184 41h10"></path><g><path d="M194 41h0"></path><path d="M222 41h0"></path><rect x="194" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="208" y="45">(</text></g><path d="M222 41h10"></path><g><path d="M232 41h0"></path><path d="M388 41h0"></path><path d="M232 41h20"></path><g><path d="M252 41h116"></path></g><path d="M368 41h20"></path><path d="M232 41a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><g><path d="M252 61h0"></path><path d="M368 61h0"></path><rect x="252" y="50" width="116" height="22"></rect><text x="310" y="65">〈whitespace〉</text></g><path d="M368 61a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path></g><g><path d="M388 41h0"></path><path d="M740 41h0"></path><path d="M388 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M408 21h312"></path></g><path d="M720 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M388 41h20"></path><g><path d="M408 41h0"></path><path d="M720 41h0"></path><g><path d="M408 41h0"></path><path d="M564 41h0"></path><path d="M408 41h20"></path><g><path d="M428 41h0"></path><path d="M544 41h0"></path><rect x="428" y="30" width="116" height="22"></rect><text x="486" y="45">url-unquoted</text></g><path d="M544 41h20"></path><path d="M408 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M428 71h24"></path><path d="M520 71h24"></path><rect x="452" y="60" width="68" height="22"></rect><text x="486" y="75">STRING</text></g><path d="M544 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><g><path d="M564 41h0"></path><path d="M720 41h0"></path><path d="M564 41h20"></path><g><path d="M584 41h116"></path></g><path d="M700 41h20"></path><path d="M564 41a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><g><path d="M584 61h0"></path><path d="M700 61h0"></path><rect x="584" y="50" width="116" height="22"></rect><text x="642" y="65">〈whitespace〉</text></g><path d="M700 61a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path></g></g><path d="M720 41h20"></path></g><path d="M740 41h10"></path><g><path d="M750 41h0"></path><path d="M778 41h0"></path><rect x="750" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="764" y="45">)</text></g><path d="M778 41h10"></path><path d="M 788 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
481 <dt id="url-unquoted-diagram">url-unquoted</dt>
482 <dd><svg class="railroad-diagram" width="509" height="100"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M458 31h0"></path><path d="M50 31h10"></path><g><path d="M60 31h0"></path><path d="M448 31h0"></path><path d="M60 31h20"></path><g><path d="M80 31h0"></path><path d="M428 31h0"></path><rect x="80" y="20" width="348" height="22"></rect><text x="254" y="35">not " ' ( ) \ whitespace or non-printable</text></g><path d="M428 31h20"></path><path d="M60 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M80 61h140"></path><path d="M288 61h140"></path><rect x="220" y="50" width="68" height="22"></rect><text x="254" y="65">escape</text></g><path d="M428 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M448 31h10"></path><path d="M60 31a10 10 0 0 0 -10 10v29a10 10 0 0 0 10 10"></path><g><path d="M60 80h388"></path></g><path d="M448 80a10 10 0 0 0 10 -10v-29a10 10 0 0 0 -10 -10"></path></g><path d="M458 31h10"></path><path d="M 468 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
484 <dt id="〈number〉-diagram">〈number〉</dt>
485 <dd><svg class="railroad-diagram" width="713" height="179"><g transform="translate(.5 .5)"><path d="M 20 50 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 60h0"></path><path d="M108 60h0"></path><path d="M40 60a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M60 40h0"></path><path d="M88 40h0"></path><rect x="60" y="29" width="28" height="22" rx="10" ry="10"></rect><text x="74" y="44">+</text></g><path d="M88 40a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M40 60h20"></path><g><path d="M60 60h28"></path></g><path d="M88 60h20"></path><path d="M40 60a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><g><path d="M60 80h0"></path><path d="M88 80h0"></path><rect x="60" y="69" width="28" height="22" rx="10" ry="10"></rect><text x="74" y="84">-</text></g><path d="M88 80a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path></g><g><path d="M108 60h0"></path><path d="M396 60h0"></path><path d="M108 60h20"></path><g><path d="M128 60h0"></path><path d="M376 60h0"></path><path d="M128 60h10"></path><g><path d="M138 60h0"></path><path d="M218 60h0"></path><path d="M138 60h10"></path><g><path d="M148 60h0"></path><path d="M208 60h0"></path><rect x="148" y="49" width="60" height="22"></rect><text x="178" y="64">digit</text></g><path d="M208 60h10"></path><path d="M148 60a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M148 80h60"></path></g><path d="M208 80a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M218 60h10"></path><path d="M228 60h10"></path><g><path d="M238 60h0"></path><path d="M266 60h0"></path><rect x="238" y="49" width="28" height="22" rx="10" ry="10"></rect><text x="252" y="64">.</text></g><path d="M266 60h10"></path><path d="M276 60h10"></path><g><path d="M286 60h0"></path><path d="M366 60h0"></path><path d="M286 60h10"></path><g><path d="M296 60h0"></path><path d="M356 60h0"></path><rect x="296" y="49" width="60" height="22"></rect><text x="326" y="64">digit</text></g><path d="M356 60h10"></path><path d="M296 60a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M296 80h60"></path></g><path d="M356 80a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M366 60h10"></path></g><path d="M376 60h20"></path><path d="M108 60a10 10 0 0 1 10 10v19a10 10 0 0 0 10 10"></path><g><path d="M128 99h84"></path><path d="M292 99h84"></path><path d="M212 99h10"></path><g><path d="M222 99h0"></path><path d="M282 99h0"></path><rect x="222" y="88" width="60" height="22"></rect><text x="252" y="103">digit</text></g><path d="M282 99h10"></path><path d="M222 99a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M222 119h60"></path></g><path d="M282 119a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M376 99a10 10 0 0 0 10 -10v-19a10 10 0 0 1 10 -10"></path><path d="M108 60a10 10 0 0 1 10 10v58a10 10 0 0 0 10 10"></path><g><path d="M128 138h50"></path><path d="M326 138h50"></path><path d="M178 138h10"></path><g><path d="M188 138h0"></path><path d="M216 138h0"></path><rect x="188" y="127" width="28" height="22" rx="10" ry="10"></rect><text x="202" y="142">.</text></g><path d="M216 138h10"></path><path d="M226 138h10"></path><g><path d="M236 138h0"></path><path d="M316 138h0"></path><path d="M236 138h10"></path><g><path d="M246 138h0"></path><path d="M306 138h0"></path><rect x="246" y="127" width="60" height="22"></rect><text x="276" y="142">digit</text></g><path d="M306 138h10"></path><path d="M246 138a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M246 158h60"></path></g><path d="M306 158a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M316 138h10"></path></g><path d="M376 138a10 10 0 0 0 10 -10v-58a10 10 0 0 1 10 -10"></path></g><g><path d="M396 60h0"></path><path d="M672 60h0"></path><path d="M396 60h20"></path><g><path d="M416 60h236"></path></g><path d="M652 60h20"></path><path d="M396 60a10 10 0 0 1 10 10v28a10 10 0 0 0 10 10"></path><g><path d="M416 108h0"></path><path d="M652 108h0"></path><g><path d="M416 108h0"></path><path d="M484 108h0"></path><path d="M416 108h20"></path><g><path d="M436 108h0"></path><path d="M464 108h0"></path><rect x="436" y="97" width="28" height="22" rx="10" ry="10"></rect><text x="450" y="112">e</text></g><path d="M464 108h20"></path><path d="M416 108a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M436 138h0"></path><path d="M464 138h0"></path><rect x="436" y="127" width="28" height="22" rx="10" ry="10"></rect><text x="450" y="142">E</text></g><path d="M464 138a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><g><path d="M484 108h0"></path><path d="M552 108h0"></path><path d="M484 108a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M504 88h0"></path><path d="M532 88h0"></path><rect x="504" y="77" width="28" height="22" rx="10" ry="10"></rect><text x="518" y="92">+</text></g><path d="M532 88a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M484 108h20"></path><g><path d="M504 108h28"></path></g><path d="M532 108h20"></path><path d="M484 108a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><g><path d="M504 128h0"></path><path d="M532 128h0"></path><rect x="504" y="117" width="28" height="22" rx="10" ry="10"></rect><text x="518" y="132">-</text></g><path d="M532 128a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path></g><path d="M552 108h10"></path><g><path d="M562 108h0"></path><path d="M642 108h0"></path><path d="M562 108h10"></path><g><path d="M572 108h0"></path><path d="M632 108h0"></path><rect x="572" y="97" width="60" height="22"></rect><text x="602" y="112">digit</text></g><path d="M632 108h10"></path><path d="M572 108a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M572 128h60"></path></g><path d="M632 128a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M642 108h10"></path></g><path d="M652 108a10 10 0 0 0 10 -10v-28a10 10 0 0 1 10 -10"></path></g><path d="M 672 60 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
487 <dt id="〈dimension〉-diagram">〈dimension〉</dt>
488 <dd><svg class="railroad-diagram" width="281" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M134 31h0"></path><rect x="50" y="20" width="84" height="22"></rect><text x="92" y="35">〈number〉</text></g><path d="M134 31h10"></path><path d="M144 31h10"></path><g><path d="M154 31h0"></path><path d="M230 31h0"></path><rect x="154" y="20" width="76" height="22"></rect><text x="192" y="35">〈ident〉</text></g><path d="M230 31h10"></path><path d="M 240 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
490 <dt id="〈percentage〉-diagram">〈percentage〉</dt>
491 <dd><svg class="railroad-diagram" width="233" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M134 31h0"></path><rect x="50" y="20" width="84" height="22"></rect><text x="92" y="35">〈number〉</text></g><path d="M134 31h10"></path><path d="M144 31h10"></path><g><path d="M154 31h0"></path><path d="M182 31h0"></path><rect x="154" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="168" y="35">%</text></g><path d="M182 31h10"></path><path d="M 192 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
493 <dt id="〈unicode-range〉-diagram">〈unicode-range〉</dt>
494 <dd><svg class="railroad-diagram" width="600" height="222"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 31h0"></path><path d="M108 31h0"></path><path d="M40 31h20"></path><g><path d="M60 31h0"></path><path d="M88 31h0"></path><rect x="60" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="74" y="35">U</text></g><path d="M88 31h20"></path><path d="M40 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M60 61h0"></path><path d="M88 61h0"></path><rect x="60" y="50" width="28" height="22" rx="10" ry="10"></rect><text x="74" y="65">u</text></g><path d="M88 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M108 31h10"></path><g><path d="M118 31h0"></path><path d="M146 31h0"></path><rect x="118" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="132" y="35">+</text></g><path d="M146 31h10"></path><g><path d="M156 31h0"></path><path d="M559 31h0"></path><path d="M156 31h20"></path><g><path d="M176 31h115.5"></path><path d="M423.5 31h115.5"></path><path d="M291.5 31h10"></path><g><path d="M301.5 31h0"></path><path d="M413.5 31h0"></path><path d="M301.5 31h10"></path><g><path d="M311.5 31h0"></path><path d="M403.5 31h0"></path><rect x="311.5" y="20" width="92" height="22"></rect><text x="357.5" y="35">hex digit</text></g><path d="M403.5 31h10"></path><path d="M311.5 31a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10"></path><g><path d="M311.5 61h9.5"></path><path d="M394 61h9.5"></path><text x="357.5" y="66" class="comment">1-6 times</text></g><path d="M403.5 61a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10"></path></g><path d="M413.5 31h10"></path></g><path d="M539 31h20"></path><path d="M156 31a10 10 0 0 1 10 10v50a10 10 0 0 0 10 10"></path><g><path d="M176 101h0"></path><path d="M539 101h0"></path><g><path d="M176 101h0"></path><path d="M328 101h0"></path><path d="M176 101a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M196 81h112"></path></g><path d="M308 81a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M176 101h20"></path><g><path d="M196 101h0"></path><path d="M308 101h0"></path><path d="M196 101h10"></path><g><path d="M206 101h0"></path><path d="M298 101h0"></path><rect x="206" y="90" width="92" height="22"></rect><text x="252" y="105">hex digit</text></g><path d="M298 101h10"></path><path d="M206 101a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10"></path><g><path d="M206 131h9.5"></path><path d="M288.5 131h9.5"></path><text x="252" y="136" class="comment">1-5 times</text></g><path d="M298 131a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10"></path></g><path d="M308 101h20"></path></g><path d="M328 101h10"></path><g><path d="M338 101h0"></path><path d="M529 101h0"></path><path d="M338 101h10"></path><g><path d="M348 101h71.5"></path><path d="M447.5 101h71.5"></path><rect x="419.5" y="90" width="28" height="22" rx="10" ry="10"></rect><text x="433.5" y="105">?</text></g><path d="M519 101h10"></path><path d="M348 101a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10"></path><g><path d="M348 131h0"></path><path d="M519 131h0"></path><text x="433.5" y="136" class="comment">1 to (6 - digits) times</text></g><path d="M519 131a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10"></path></g><path d="M529 101h10"></path></g><path d="M539 101a10 10 0 0 0 10 -10v-50a10 10 0 0 1 10 -10"></path><path d="M156 31a10 10 0 0 1 10 10v110a10 10 0 0 0 10 10"></path><g><path d="M176 161h25.5"></path><path d="M513.5 161h25.5"></path><path d="M201.5 161h10"></path><g><path d="M211.5 161h0"></path><path d="M323.5 161h0"></path><path d="M211.5 161h10"></path><g><path d="M221.5 161h0"></path><path d="M313.5 161h0"></path><rect x="221.5" y="150" width="92" height="22"></rect><text x="267.5" y="165">hex digit</text></g><path d="M313.5 161h10"></path><path d="M221.5 161a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10"></path><g><path d="M221.5 191h9.5"></path><path d="M304 191h9.5"></path><text x="267.5" y="196" class="comment">1-6 times</text></g><path d="M313.5 191a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10"></path></g><path d="M323.5 161h10"></path><path d="M333.5 161h10"></path><g><path d="M343.5 161h0"></path><path d="M371.5 161h0"></path><rect x="343.5" y="150" width="28" height="22" rx="10" ry="10"></rect><text x="357.5" y="165">-</text></g><path d="M371.5 161h10"></path><path d="M381.5 161h10"></path><g><path d="M391.5 161h0"></path><path d="M503.5 161h0"></path><path d="M391.5 161h10"></path><g><path d="M401.5 161h0"></path><path d="M493.5 161h0"></path><rect x="401.5" y="150" width="92" height="22"></rect><text x="447.5" y="165">hex digit</text></g><path d="M493.5 161h10"></path><path d="M401.5 161a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10"></path><g><path d="M401.5 191h9.5"></path><path d="M484 191h9.5"></path><text x="447.5" y="196" class="comment">1-6 times</text></g><path d="M493.5 191a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10"></path></g><path d="M503.5 161h10"></path></g><path d="M539 161a10 10 0 0 0 10 -10v-110a10 10 0 0 1 10 -10"></path></g><path d="M 559 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
496 <dt id="〈include-match〉-diagram">〈include-match〉</dt>
497 <dd><svg class="railroad-diagram" width="137" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M86 31h0"></path><rect x="50" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="35">~=</text></g><path d="M86 31h10"></path><path d="M 96 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
499 <dt id="〈dash-match〉-diagram">〈dash-match〉</dt>
500 <dd><svg class="railroad-diagram" width="137" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M86 31h0"></path><rect x="50" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="35">|=</text></g><path d="M86 31h10"></path><path d="M 96 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
502 <dt id="〈prefix-match〉-diagram">〈prefix-match〉</dt>
503 <dd><svg class="railroad-diagram" width="137" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M86 31h0"></path><rect x="50" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="35">^=</text></g><path d="M86 31h10"></path><path d="M 96 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
505 <dt id="〈suffix-match〉-diagram">〈suffix-match〉</dt>
506 <dd><svg class="railroad-diagram" width="137" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M86 31h0"></path><rect x="50" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="35">$=</text></g><path d="M86 31h10"></path><path d="M 96 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
508 <dt id="〈substring-match〉-diagram">〈substring-match〉</dt>
509 <dd><svg class="railroad-diagram" width="137" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M86 31h0"></path><rect x="50" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="35">*=</text></g><path d="M86 31h10"></path><path d="M 96 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
511 <dt id="〈column〉-diagram">〈column〉</dt>
512 <dd><svg class="railroad-diagram" width="137" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M86 31h0"></path><rect x="50" y="20" width="36" height="22" rx="10" ry="10"></rect><text x="68" y="35">||</text></g><path d="M86 31h10"></path><path d="M 96 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
514 <dt id="〈CDO〉-diagram">〈CDO〉</dt>
515 <dd><svg class="railroad-diagram" width="153" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M102 31h0"></path><rect x="50" y="20" width="52" height="22" rx="10" ry="10"></rect><text x="76" y="35"><!--</text></g><path d="M102 31h10"></path><path d="M 112 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
517 <dt id="〈CDC〉-diagram">〈CDC〉</dt>
518 <dd><svg class="railroad-diagram" width="145" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M94 31h0"></path><rect x="50" y="20" width="44" height="22" rx="10" ry="10"></rect><text x="72" y="35">--></text></g><path d="M94 31h10"></path><path d="M 104 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
520 </dl>
522 <h3>
523 Definitions</h3>
525 This section defines several terms used during the tokenization phase.
527 <dl>
528 <dt><dfn>next input character</dfn>
529 <dd>
530 The first character in the input stream that has not yet been consumed.
532 <dt><dfn>current input character</dfn>
533 <dd>
534 The last character to have been consumed.
536 <dt><dfn>reconsume the current input character</dfn>
537 <dd>
538 Push the <a>current input character</a> back onto the front of the input stream,
539 so that the next time you are instructed to consume the next input character,
540 it will instead reconsume the <a>current input character</a>.
542 <dt><dfn>EOF character</dfn>
543 <dd>
544 A conceptual character representing the end of the input stream.
545 Whenever the input stream is empty,
546 the <a>next input character</a> is always an EOF character.
548 <dt><dfn>digit</dfn>
549 <dd>
550 A character between U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9).
552 <dt><dfn>hex digit</dfn>
553 <dd>
554 A <a>digit</a>,
555 or a character between U+0041 LATIN CAPITAL LETTER A (A) and U+0046 LATIN CAPITAL LETTER F (F),
556 or a character between U+0061 LATIN SMALL LETTER A (a) and U+0066 LATIN SMALL LETTER F (f).
558 <dt><dfn>uppercase letter</dfn>
559 <dd>
560 A character between U+0041 LATIN CAPITAL LETTER A (A) and U+005A LATIN CAPITAL LETTER Z (Z).
562 <dt><dfn>lowercase letter</dfn>
563 <dd>
564 A character between U+0061 LATIN SMALL LETTER A (a) and U+007A LATIN SMALL LETTER Z (z).
566 <dt><dfn>letter</dfn>
567 <dd>
568 An <a>uppercase letter</a>
569 or a <a>lowercase letter</a>.
571 <dt><dfn>non-ASCII character</dfn>
572 <dd>
573 A character with a codepoint equal to or greater than U+0080 <control>.
575 <dt><dfn>name-start character</dfn>
576 <dd>
577 A <a>letter</a>,
578 a <a>non-ASCII character</a>,
579 or U+005F LOW LINE (_).
581 <dt><dfn>name character</dfn>
582 <dd>
583 A <a>name-start character</a>,
584 A <a>digit</a>,
585 or U+002D HYPHEN-MINUS (-).
587 <dt><dfn>non-printable character</dfn>
588 <dd>
589 A character between U+0000 NULL and U+0008 BACKSPACE,
590 or U+000B LINE TABULATION,
591 or a character between U+000E SHIFT OUT and U+001F INFORMATION SEPARATOR ONE,
592 or U+007F DELETE.
594 <dt><dfn>newline</dfn>
595 <dd>
596 U+000A LINE FEED.
597 <span class='note'>
598 Note that U+000D CARRIAGE RETURN and U+000C FORM FEED are not included in this definition,
599 as they are converted to U+000A LINE FEED during <a href="#preprocessing-the-input-stream">preprocessing</a>.
600 </span>
602 <dt><dfn>whitespace</dfn>
603 <dd>A <a>newline</a>, U+0009 CHARACTER TABULATION, or U+0020 SPACE.
605 <dt><dfn>maximum allowed codepoint</dfn>
606 <dd>The greatest codepoint defined by Unicode. This is currently U+10FFFF.
608 </dl>
610 <h3>
611 Tokenizer Algorithms</h3>
613 The algorithms defined in this section transform a stream of characters into a stream of tokens.
615 <h4>
616 <dfn>Consume a token</dfn></h4>
618 This section describes how to <a>consume a token</a> from a stream of characters.
619 It will return a single token of any type.
621 Consume the <a>next input character</a>.
623 <dl>
624 <dt><a>whitespace</a>
625 <dd>
626 Consume as much <a>whitespace</a> as possible.
627 Return a 〈whitespace〉.
629 <dt>U+0022 QUOTATION MARK (")
630 <dd>
631 <a>Consume a string token</a> with the ending character U+0022 QUOTATION MARK (")
632 and return it.
634 <dt>U+0023 NUMBER SIGN (#)
635 <dd>
636 If the <a>next input character</a> is a <a>name character</a>
637 or the <a title="next input character">next two input characters</a>
638 <a>are a valid escape</a>,
639 then:
641 <ol>
642 <li>
643 Create a 〈hash〉.
645 <li>
646 If the <a title="next input character">next 3 input characters</a> <a>would start an identifier</a>,
647 set the 〈hash〉’s type flag to "id".
649 <li>
650 <a>Consume a name</a>,
651 and set the 〈hash〉’s value to the returned string.
653 <li>
654 Return the 〈hash〉.
655 </ol>
657 Otherwise,
658 return a 〈delim〉
659 with its value set to the <a>current input character</a>.
661 <dt>U+0024 DOLLAR SIGN ($)
662 <dd>
663 If the <a>next input character</a> is
664 U+003D EQUALS SIGN (=),
665 consume it
666 and return a 〈suffix-match〉.
668 Otherwise,
669 emit a 〈delim〉
670 with its value set to the <a>current input character</a>.
672 <dt>U+0027 APOSTROPHE (')
673 <dd>
674 <a>Consume a string token</a> with the ending character U+0027 APOSTROPHE (')
675 and return it.
677 <dt>U+0028 LEFT PARENTHESIS (()
678 <dd>
679 Return a 〈(〉.
681 <dt>U+0029 RIGHT PARENTHESIS ())
682 <dd>
683 Return a 〈)〉.
685 <dt>U+002A ASTERISK (*)
686 <dd>
687 If the <a>next input character</a> is
688 U+003D EQUALS SIGN (=),
689 consume it
690 and return a 〈substring-match〉.
692 Otherwise,
693 return a 〈delim〉
694 with its value set to the <a>current input character</a>.
696 <dt>U+002B PLUS SIGN (+)
697 <dd>
698 If the input stream <a>starts with a number</a>,
699 <a>reconsume the current input character</a>,
700 <a>consume a numeric token</a>
701 and return it.
703 Otherwise,
704 return a 〈delim〉
705 with its value set to the <a>current input character</a>.
707 <dt>U+002C COMMA (,)
708 <dd>
709 Return a 〈comma〉.
711 <dt>U+002D HYPHEN-MINUS (-)
712 <dd>
713 If the input stream <a>starts with a number</a>,
714 <a>reconsume the current input character</a>,
715 <a>consume a numeric token</a>,
716 and return it.
718 Otherwise,
719 if the input stream <a>starts with an identifier</a>,
720 <a>reconsume the current input character</a>,
721 <a>consume an ident-like token</a>,
722 and return it.
724 Otherwise,
725 if the <a title="next input character">next 2 input characters</a> are
726 U+002D HYPHEN-MINUS
727 U+003E GREATER-THAN SIGN
728 (->),
729 consume them
730 and return a 〈CDC〉.
732 Otherwise,
733 return a 〈delim〉
734 with its value set to the <a>current input character</a>.
736 <dt>U+002E FULL STOP (.)
737 <dd>
738 If the input stream <a>starts with a number</a>,
739 <a>reconsume the current input character</a>,
740 <a>consume a numeric token</a>,
741 and return it.
743 Otherwise,
744 return a 〈delim〉
745 with its value set to the <a>current input character</a>.
747 <dt>U+002F SOLIDUS (/)
748 <dd>
749 If the <a>next input character</a> is U+002A ASTERISK (*),
750 consume it
751 and all following characters up to and including
752 the first U+002A ASTERISK (*) followed by a U+002F SOLIDUS (/),
753 or up to an EOF character.
754 Then <a>consume a token</a>
755 and return it.
757 Otherwise,
758 return a 〈delim〉
759 with its value set to the <a>current input character</a>.
761 <dt>U+003A COLON (:)
762 <dd>
763 Return a 〈colon〉.
765 <dt>U+003B SEMICOLON (;)
766 <dd>
767 Return a 〈semicolon〉.
769 <dt>U+003C LESS-THAN SIGN (<)
770 <dd>
771 If the <a title="next input character">next 3 input characters</a> are
772 U+0021 EXCLAMATION MARK
773 U+002D HYPHEN-MINUS
774 U+002D HYPHEN-MINUS
775 (!--),
776 consume them
777 and return a 〈CDO〉.
779 Otherwise,
780 return a 〈delim〉
781 with its value set to the <a>current input character</a>.
783 <dt>U+0040 COMMERCIAL AT (@)
784 <dd>
785 If the <a title="next input character">next 3 input characters</a>
786 <a>would start an identifier</a>,
787 <a>consume a name</a>,
788 create an 〈at-keyword〉 with its value set to the returned value,
789 and return it.
791 Otherwise,
792 return a 〈delim〉
793 with its value set to the <a>current input character</a>.
795 <dt>U+005B LEFT SQUARE BRACKET ([)
796 <dd>
797 Return a 〈[〉.
799 <dt>U+005C REVERSE SOLIDUS (\)
800 <dd>
801 If the input stream <a>starts with a valid escape</a>,
802 <a>reconsume the current input character</a>,
803 <a>consume an ident-like token</a>,
804 and return it.
806 Otherwise,
807 this is a <a>parse error</a>.
808 Return a 〈delim〉
809 with its value set to the <a>current input character</a>.
811 <dt>U+005D RIGHT SQUARE BRACKET (])
812 <dd>
813 Return a 〈]〉.
815 <dt>U+005E CIRCUMFLEX ACCENT (^)
816 <dd>
817 If the <a>next input character</a> is
818 U+003D EQUALS SIGN (=),
819 consume it
820 and return a 〈prefix-match〉.
822 Otherwise,
823 return a 〈delim〉
824 with its value set to the <a>current input character</a>.
826 <dt>U+007B LEFT CURLY BRACKET ({)
827 <dd>
828 Return a 〈{〉.
830 <dt>U+007D RIGHT CURLY BRACKET (})
831 <dd>
832 Return a 〈}〉.
834 <dt><a>digit</a>
835 <dd>
836 <a>Consume a numeric token</a>,
837 and return it.
839 <dt>U+0055 LATIN CAPITAL LETTER U (U)
840 <dt>U+0075 LATIN SMALL LETTER U (u)
841 <dd>
842 If the <a title="next input character">next 2 input character</a> are
843 U+002B PLUS SIGN (+)
844 followed by a <a>hex digit</a>
845 or U+003F QUESTION MARK (?),
846 consume the <a>next input character</a>.
847 <span class='note'>Note: don't consume both of them.</span>
848 <a>Consume a unicode-range token</a>
849 and return it.
851 Otherwise,
852 <a>reconsume the current input character</a>,
853 <a>consume an ident-like token</a>,
854 and return it.
856 <dt><a>name-start character</a>
857 <dd>
858 <a>Reconsume the current input character</a>,
859 <a>consume an ident-like token</a>,
860 and return it.
862 <dt>U+007C VERTICAL LINE (|)
863 <dd>
864 If the <a>next input character</a> is
865 U+003D EQUALS SIGN (=),
866 consume it
867 and return a 〈dash-match〉.
869 Otherwise,
870 if the <a>next input character</a> is
871 U+0073 VERTICAL LINE (|),
872 consume it
873 and return a 〈column〉.
875 Otherwise,
876 return a 〈delim〉
877 with its value set to the <a>current input character</a>.
879 <dt>U+007E TILDE (~)
880 <dd>
881 If the <a>next input character</a> is
882 U+003D EQUALS SIGN (=),
883 consume it
884 and return an 〈include-match〉.
886 Otherwise,
887 return a 〈delim〉
888 with its value set to the <a>current input character</a>.
890 <dt>EOF
891 <dd>
892 Return an 〈EOF〉 token.
894 <dt>anything else
895 <dd>
896 Return a 〈delim〉
897 with its value set to the <a>current input character</a>.
898 </dl>
903 <h4>
904 <dfn>Consume a numeric token</dfn></h4>
906 This section describes how to <a>consume a numeric token</a> from a stream of characters.
907 It returns either a 〈number〉, 〈percentage〉, or 〈dimension〉.
909 <a>Consume a number</a>.
911 If the <a title="next input character">next 3 input characters</a> <a>would start an identifier</a>,
912 then:
914 <ol>
915 <li>Create a 〈dimension〉 with the same representation, value, and type flag as the returned number,
916 and a unit set initially to the empty string.
918 <li><a>Consume a name</a>.
919 Set the 〈dimension〉’s unit to the returned value.
921 <li>Return the 〈dimension〉.
922 </ol>
924 Otherwise,
925 if the <a>next input character</a> is U+0025 PERCENTAGE SIGN (%),
926 consume it.
927 Create a 〈percentage〉 with the same representation and value as the returned number,
928 and return it.
930 Otherwise,
931 create a 〈number〉 with the same representation, value, and type flag as the returned number,
932 and return it.
935 <h4>
936 <dfn>Consume an ident-like token</dfn></h4>
938 This section describes how to <a>consume an ident-like token</a> from a stream of characters.
939 It returns an 〈ident〉, 〈function〉, 〈url〉, or 〈bad-url〉.
941 <a>Consume a name</a>.
943 If the returned string's value is an <a>ASCII case-insensitive</a> match for "url",
944 and the <a>next input character</a> is U+0028 LEFT PARENTHESIS ((),
945 consume it.
946 <a>Consume a url token</a>,
947 and return it.
949 Otherwise,
950 if the <a>next input character</a> is U+0028 LEFT PARENTHESIS ((),
951 consume it.
952 Create a 〈function〉 token
953 with its value set to the returned string
954 and return it.
956 Otherwise,
957 create an 〈ident〉 token
958 with its value set to the returned string
959 and return it.
962 <h4>
963 <dfn>Consume a string token</dfn></h4>
965 This section describes how to <a>consume a string token</a> from a stream of characters.
966 It returns either a 〈string〉 or 〈bad-string〉.
968 This algorithm must be called with an <var>ending character</var>,
969 which denotes the character that ends the string.
971 Initially create a 〈string〉 with its value set to the empty string.
973 Repeatedly consume the <a>next input character</a> from the stream:
975 <dl>
976 <dt><var>ending character</var>
977 <dt>EOF
978 <dd>
979 Return the 〈string〉.
981 <dt><a>newline</a>
982 <dd>
983 This is a <a>parse error</a>.
984 <a>Reconsume the current input character</a>,
985 create a 〈bad-string〉, and return it.
987 <dt>U+005C REVERSE SOLIDUS (\)
988 <dd>
989 If the <a>next input character</a> is EOF,
990 do nothing.
992 Otherwise,
993 if the <a>next input character</a> is a newline,
994 consume it.
996 Otherwise,
997 if the stream <a>starts with a valid escape</a>,
998 <a>consume an escaped character</a>
999 and append the returned character to the 〈string〉’s value.
1001 <dt>anything else
1002 <dd>
1003 Append the <a>current input character</a> to the 〈string〉’s value.
1004 </dl>
1007 <h4>
1008 <dfn>Consume a url token</dfn></h4>
1010 This section describes how to <a>consume a url token</a> from a stream of characters.
1011 It returns either a 〈url〉 or a 〈bad-url〉.
1013 Note: This algorithm assumes that the initial "url(" has already been consumed.
1015 Execute the following steps in order:
1017 <ol>
1018 <li>
1019 Initially create a 〈url〉 with its value set to the empty string.
1021 <li>
1022 Consume as much <a>whitespace</a> as possible.
1024 <li>
1025 If the <a>next input character</a> is EOF,
1026 return the 〈url〉.
1028 <li>
1029 If the <a>next input character</a> is a U+0022 QUOTATION MARK (") or U+0027 APOSTROPHE ('),
1030 then:
1032 <ol>
1033 <li>
1034 <a>Consume a string token</a> with the <a>current input character</a> as the ending character.
1036 <li>
1037 If a 〈bad-string〉 was returned,
1038 <a>consume the remnants of a bad url</a>,
1039 create a 〈bad-url〉,
1040 and return it.
1042 <li>
1043 Set the 〈url〉’s value to the returned 〈string〉’s value.
1045 <li>
1046 Consume as much <a>whitespace</a> as possible.
1048 <li>
1049 If the <a>next input character</a> is U+0029 RIGHT PARENTHESIS ()) or EOF,
1050 consume it and return the 〈url〉;
1051 otherwise,
1052 <a>consume the remnants of a bad url</a>,
1053 create a 〈bad-url〉,
1054 and return it.
1055 </ol>
1057 <li>
1058 Repeatedly consume the <a>next input character</a> from the stream:
1060 <dl>
1061 <dt>U+0029 RIGHT PARENTHESIS ())
1062 <dt>EOF
1063 <dd>
1064 Return the 〈url〉.
1066 <dt><a>whitespace</a>
1067 <dd>
1068 Consume as much <a>whitespace</a> as possible.
1069 If the <a>next input character</a> is U+0029 RIGHT PARENTHESIS ()) or EOF,
1070 consume it and return the 〈url〉;
1071 otherwise,
1072 <a>consume the remnants of a bad url</a>,
1073 create a 〈bad-url〉,
1074 and return it.
1076 <dt>U+0022 QUOTATION MARK (")
1077 <dt>U+0027 APOSTROPHE (')
1078 <dt>U+0028 LEFT PARENTHESIS (()
1079 <dt><a>non-printable character</a>
1080 <dd>
1081 This is a <a>parse error</a>.
1082 <a>Consume the remnants of a bad url</a>,
1083 create a 〈bad-url〉,
1084 and return it.
1086 <dt>U+005C REVERSE SOLIDUS
1087 <dd>
1088 If the stream <a>starts with a valid escape</a>,
1089 <a>consume an escaped character</a>
1090 and append the returned character to the 〈url〉’s value.
1092 Otherwise,
1093 this is a <a>parse error</a>.
1094 <a>Consume the remnants of a bad url</a>,
1095 create a 〈bad-url〉,
1096 and return it.
1098 <dt>anything else
1099 <dd>
1100 Append the <a>current input character</a>
1101 to the 〈url〉’s value.
1102 </dl>
1103 </ol>
1106 <h4>
1107 <dfn>Consume a unicode-range token</dfn></h4>
1109 This section describes how to <a>consume a unicode-range token</a>.
1110 It returns a 〈unicode-range〉 token.
1112 Note: This algorithm assumes that the initial "u+" has been consumed,
1113 and the next character verified to be a <a>hex digit</a> or a "?".
1115 Execute the following steps in order:
1117 <ol>
1118 <li>
1119 Create a new 〈unicode-range〉
1120 with an empty range.
1122 <li>
1123 Consume as many <a>hex digits</a> as possible, but no more than 6.
1124 If less than 6 <a>hex digits</a> were consumed,
1125 consume as many U+003F QUESTION MARK (?) characters as possible,
1126 but no more than enough to make the total of <a>hex digits</a> and U+003F QUESTION MARK (?) characters equal to 6.
1128 If any U+003F QUESTION MARK (?) characters were consumed,
1129 then:
1131 <ol>
1132 <li>
1133 Interpret the consumed characters as a hexadecimal number,
1134 with the U+003F QUESTION MARK (?) characters replaced by U+0030 DIGIT ZERO (0) characters.
1135 This is the <a>start of the range</a>.
1137 <li>
1138 Interpret the consumed characters as a hexadecimal number again,
1139 with the U+003F QUESTION MARK (?) character replaced by U+0046 LATIN CAPITAL LETTER F (F) characters.
1140 This is the <a>end of the range</a>.
1142 <li>
1143 <a>Set the 〈unicode-range〉’s range</a>, then return it.
1144 </ol>
1146 Otherwise,
1147 interpret the digits as a hexadecimal number.
1148 This is the <a>start of the range</a>.
1150 <li>
1151 If the <a title="next input character">next 2 input character</a> are
1152 U+002D HYPHEN-MINUS (-) followed by a <a>hex digit</a>,
1153 then:
1155 <ol>
1156 <li>Consume the <a>next input character</a>.
1158 <li>
1159 Consume as many <a>hex digits</a> as possible, but no more than 6.
1160 Interpret the digits as a hexadecimal number.
1161 This is the <a>end of the range</a>.
1162 <a>Set the 〈unicode-range〉’s range</a>, then return it.
1163 </ol>
1165 <li>
1166 <a>Set the 〈unicode-range〉’s range</a>
1167 and return it.
1168 </ol>
1171 <h4>
1172 <dfn>Consume an escaped character</dfn></h4>
1174 This section describes how to <a>consume an escaped character</a>.
1175 It assumes that the U+005C REVERSE SOLIDUS (\) has already been consumed
1176 and that the next input character has already been verified
1177 to not be a <a>newline</a> or EOF.
1178 It will return a character.
1180 Consume the <a>next input character</a>.
1182 <dl>
1183 <dt><a>hex digit</a>
1184 <dd>
1185 Consume as many <a>hex digits</a> as possible, but no more than 5.
1186 <span class='note'>Note that this means 1-6 hex digits have been consumed in total.</span>
1187 If the <a>next input character</a> is
1188 <a>whitespace</a>,
1189 consume it as well.
1190 Interpret the <a>hex digits</a> as a hexadecimal number.
1191 If this number is zero,
1192 or is between U+D800 and U+DFFF included,
1193 or is greater than the <a>maximum allowed codepoint</a>,
1194 return U+FFFD REPLACEMENT CHARACTER (�).
1195 Otherwise, return the character with that codepoint.
1197 <p class=note>
1198 U+D800 to U+DFFF are the
1199 <a href="http://www.unicode.org/glossary/#surrogate_code_point">surrogate code points</a>.
1201 <dt>EOF character
1202 <dd>
1203 Return U+FFFD REPLACEMENT CHARACTER (�).
1205 <dt>anything else
1206 <dd>
1207 Return the <a>current input character</a>.
1208 </dl>
1211 <h4>
1212 <dfn title="check if two characters are a valid escape|are a valid escape|starts with a valid escape">Check if two characters are a valid escape</dfn></h4>
1214 This section describes how to <a>check if two characters are a valid escape</a>.
1215 The algorithm described here can be called explicitly with two characters,
1216 or can be called with the input stream itself.
1217 In the latter case, the two characters in question are
1218 the <a>current input character</a>
1219 and the <a>next input character</a>,
1220 in that order.
1222 Note: This algorithm will not consume any additional characters.
1224 If the first character is not U+005D REVERSE SOLIDUS (\),
1225 return false.
1227 Otherwise,
1228 if the second character is a <a>newline</a>,
1229 return false.
1231 Otherwise, return true.
1234 <h4>
1235 <dfn title="check if three characters would start an identifier|starts with an identifier|start with an identifier|would start an identifier">Check if three characters would start an identifier</dfn></h4>
1237 This section describes how to <a>check if three characters would start an identifier</a>.
1238 The algorithm described here can be called explicitly with three characters,
1239 or can be called with the input stream itself.
1240 In the latter case, the three characters in question are
1241 the <a>current input character</a>
1242 and the <a title="next input character">next two input characters</a>,
1243 in that order.
1245 Note: This algorithm will not consume any additional characters.
1247 Look at the first character:
1249 <dl>
1250 <dt>U+002D HYPHEN-MINUS
1251 <dd>
1252 If the second character is a <a>name-start character</a>
1253 or the second and third characters <a>are a valid escape</a>,
1254 return true.
1255 Otherwise, return false.
1257 <dt><a>name-start character</a>
1258 <dd>
1259 Return true.
1261 <dt>U+005C REVERSE SOLIDUS (\)
1262 <dd>
1263 If the first and second characters <a>are a valid escape</a>,
1264 return true.
1265 Otherwise, return false.
1266 </dl>
1268 <h4>
1269 <dfn title="check if three characters would start a number|starts with a number|start with a number|would start a number">Check if three characters would start a number</dfn></h4>
1271 This section describes how to <a>check if three characters would start a number</a>.
1272 The algorithm described here can be called explicitly with three characters,
1273 or can be called with the input stream itself.
1274 In the latter case, the three characters in question are
1275 the <a>current input character</a>
1276 and the <a title="next input character">next two input characters</a>,
1277 in that order.
1279 Note: This algorithm will not consume any additional characters.
1281 Look at the first character:
1283 <dl>
1284 <dt>U+002B PLUS SIGN (+)
1285 <dt>U+002D HYPHEN-MINUS (-)
1286 <dd>
1287 If the second character
1288 is a <a>digit</a>,
1289 return true.
1291 Otherwise,
1292 if the second character
1293 is a U+002E FULL STOP (.)
1294 and the third character
1295 is a <a>digit</a>,
1296 return true.
1298 Otherwise, return false.
1300 <dt>U+002E FULL STOP (.)
1301 <dd>
1302 If the second character
1303 is a <a>digit</a>,
1304 return true.
1305 Otherwise, return false.
1307 <dt><a>digit</a>
1308 <dd>
1309 Return true.
1311 <dt>anything else
1312 <dd>
1313 Return false.
1314 </dl>
1317 <h4>
1318 <dfn>Consume a name</dfn></h4>
1320 This section describes how to <a>consume a name</a> from a stream of characters.
1321 It returns a string containing
1322 the largest name that can be formed from adjacent characters in the stream, starting from the first.
1324 Note: This algorithm does not do the verification of the first few characters
1325 that are necessary to ensure the returned characters would constitute an 〈ident〉.
1326 If that is the intended use,
1327 ensure that the stream <a>starts with an identifier</a>
1328 before calling this algorithm.
1330 Let <var>result</var> initially be an empty string.
1332 Repeatedly consume the <a>next input character</a> from the stream:
1334 <dl>
1335 <dt><a>name character</a>
1336 <dd>
1337 Append the character to <var>result</var>.
1339 <dt>the stream <a>starts with a valid escape</a>
1340 <dd>
1341 <a>Consume an escaped character</a>.
1342 Append the returned character to <var>result</var>.
1344 <dt>anything else
1345 <dd>
1346 Return <var>result</var>.
1347 </dl>
1350 <h4>
1351 <dfn>Consume a number</dfn></h4>
1353 This section describes how to <a>consume a number</a> from a stream of characters.
1354 It returns a 3-tuple of
1355 a string representation,
1356 a numeric value,
1357 and a type flag which is either "integer" or "number".
1359 Note: This algorithm does not do the verification of the first few characters
1360 that are necessary to ensure a number can be obtained from the stream.
1361 Ensure that the stream <a>starts with a number</a>
1362 before calling this algorithm.
1364 Execute the following steps in order:
1366 <ol>
1367 <li>
1368 Initially set <var>repr</var> to the empty string
1369 and <var>type</var> to "integer".
1371 <li>
1372 If the <a>next input character</a> is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
1373 consume it and append it to <var>repr</var>.
1375 <li>
1376 While the <a>next input character</a> is a <a>digit</a>,
1377 consume it and append it to <var>repr</var>.
1379 <li>
1380 If the <a title="next input character">next 2 input characters</a> are
1381 U+002E FULL STOP (.) followed by a <a>digit</a>,
1382 then:
1384 <ol>
1385 <li>Consume them.
1386 <li>Append them to <var>repr</var>.
1387 <li>Set <var>type</var> to "number".
1388 <li>While the <a>next input character</a> is a <a>digit</a>, consume it and append it to <var>repr</var>.
1389 </ol>
1391 <li>
1392 If the <a title="next input character">next 2 or 3 input characters</a> are
1393 U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),
1394 optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+),
1395 followed by a <a>digit</a>,
1396 then:
1398 <ol>
1399 <li>Consume them.
1400 <li>Append them to <var>repr</var>.
1401 <li>Set <var>type</var> to "number".
1402 <li>While the <a>next input character</a> is a <a>digit</a>, consume it and append it to <var>repr</var>.
1403 </ol>
1405 <li>
1406 <a title="convert a string to a number">Convert <var>repr</var> to a number</a>,
1407 and set the <var>value</var> to the returned value.
1409 <li>
1410 Return a 3-tuple of <var>repr</var>, <var>value</var>, and <var>type</var>.
1411 </ol>
1414 <h4>
1415 <dfn>Convert a string to a number</dfn></h4>
1417 This section describes how to <a>convert a string to a number</a>.
1418 It returns a number.
1420 Note: This algorithm does not do any verification to ensure that the string contains only a number.
1421 Ensure that the string contains only a valid CSS number
1422 before calling this algorithm.
1424 Divide the string into seven components,
1425 in order from left to right:
1427 <ol>
1428 <li>A <b>sign</b>:
1429 a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
1430 or the empty string.
1431 Let <var>s</var> be the number -1 if the sign is U+002D HYPHEN-MINUS (-);
1432 otherwise, let <var>s</var> be the number 1.
1434 <li>An <b>integer part</b>:
1435 zero or more <a>digits</a>.
1436 If there is at least one digit,
1437 let <var>i</var> be the number formed by interpreting the digits as a base-10 integer;
1438 otherwise, let <var>i</var> be the number 0.
1440 <li>A <b>decimal point</b>:
1441 a single U+002E FULL STOP (.),
1442 or the empty string.
1444 <li>A <b>fractional part</b>:
1445 zero or more <a>digits</a>.
1446 If there is at least one digit,
1447 let <var>f</var> be the number formed by interpreting the digits as a base-10 integer
1448 and <var>d</var> be the number of digits;
1449 otherwise, let <var>f</var> and <var>d</var> be the number 0.
1451 <li>An <b>exponent indicator</b>:
1452 a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),
1453 or the empty string.
1455 <li>An <b>exponent sign</b>:
1456 a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
1457 or the empty string.
1458 Let <var>t</var> be the number -1 if the sign is U+002D HYPHEN-MINUS (-);
1459 otherwise, let <var>t</var> be the number 1.
1461 <li>An <b>exponent</b>:
1462 zero or more <a>digits</a>.
1463 If there is at least one digit,
1464 let <var>e</var> be the number formed by interpreting the digits as a base-10 integer;
1465 otherwise, let <var>e</var> be the number 0.
1466 </ol>
1468 Return the number <code>s·(i + f·10<sup>-d</sup>)·10<sup>te</sup></code>.
1471 <h4>
1472 <dfn>Consume the remnants of a bad url</dfn></h4>
1474 This section describes how to <a>consume the remnants of a bad url</a> from a stream of characters,
1475 "cleaning up" after the tokenizer realizes that it's in the middle of a 〈bad-url〉 rather than a 〈url〉.
1476 It returns nothing;
1477 its sole use is to consume enough of the input stream to reach a recovery point
1478 where normal tokenizing can resume.
1480 Repeatedly consume the <a>next input character</a> from the stream:
1482 <dl>
1483 <dt>U+0029 RIGHT PARENTHESIS ())
1484 <dt>EOF
1485 <dd>
1486 Return.
1488 <dt>the input stream <a>starts with a valid escape</a>
1489 <dd>
1490 <a>Consume an escaped character</a>.
1491 <span class='note'>This allows an escaped right parenthesis ("\)") to be encountered without ending the 〈bad-url〉.
1492 This is otherwise identical to the "anything else" clause.</span>
1494 <dt>anything else
1495 <dd>
1496 Do nothing.
1497 </dl>
1499 <h4>
1500 <dfn>Set the 〈unicode-range〉’s range</dfn></h4>
1502 This section describes how to set a 〈unicode-range〉’s range
1503 so that the range it describes
1504 is within the supported range of unicode characters.
1506 It assumes that the <dfn>start of the range</dfn> has been defined,
1507 the <dfn>end of the range</dfn> might be defined,
1508 and both are non-negative integers.
1510 If the <a>start of the range</a> is greater than
1511 the <a>maximum allowed codepoint</a>,
1512 the 〈unicode-range〉’s range is empty.
1514 If the <a>end of the range</a> is defined,
1515 and it is less than the <a>start of the range</a>,
1516 the 〈unicode-range〉’s range is empty.
1518 If the <a>end of the range</a> is not defined,
1519 the 〈unicode-range〉’s range
1520 is the single character whose codepoint is the <a>start of the range</a>.
1522 Otherwise,
1523 if the <a>end of the range</a> is greater than
1524 the <a>maximum allowed codepoint</a>,
1525 change it to the <a>maximum allowed codepoint</a>.
1526 The 〈unicode-range〉’s range
1527 is all characters between
1528 the character whose codepoint is the <a>start of the range</a>
1529 and the character whose codepoint is the <a>end of the range</a>.
1532 <!--
1533 PPPPPPPPPPPPPPPPP AAA RRRRRRRRRRRRRRRRR SSSSSSSSSSSSSSS EEEEEEEEEEEEEEEEEEEEEERRRRRRRRRRRRRRRRR
1534 P::::::::::::::::P A:::A R::::::::::::::::R SS:::::::::::::::SE::::::::::::::::::::ER::::::::::::::::R
1535 P::::::PPPPPP:::::P A:::::A R::::::RRRRRR:::::R S:::::SSSSSS::::::SE::::::::::::::::::::ER::::::RRRRRR:::::R
1536 PP:::::P P:::::P A:::::::A RR:::::R R:::::RS:::::S SSSSSSSEE::::::EEEEEEEEE::::ERR:::::R R:::::R
1537 P::::P P:::::P A:::::::::A R::::R R:::::RS:::::S E:::::E EEEEEE R::::R R:::::R
1538 P::::P P:::::PA:::::A:::::A R::::R R:::::RS:::::S E:::::E R::::R R:::::R
1539 P::::PPPPPP:::::PA:::::A A:::::A R::::RRRRRR:::::R S::::SSSS E::::::EEEEEEEEEE R::::RRRRRR:::::R
1540 P:::::::::::::PPA:::::A A:::::A R:::::::::::::RR SS::::::SSSSS E:::::::::::::::E R:::::::::::::RR
1541 P::::PPPPPPPPP A:::::A A:::::A R::::RRRRRR:::::R SSS::::::::SS E:::::::::::::::E R::::RRRRRR:::::R
1542 P::::P A:::::AAAAAAAAA:::::A R::::R R:::::R SSSSSS::::S E::::::EEEEEEEEEE R::::R R:::::R
1543 P::::P A:::::::::::::::::::::A R::::R R:::::R S:::::S E:::::E R::::R R:::::R
1544 P::::P A:::::AAAAAAAAAAAAA:::::A R::::R R:::::R S:::::S E:::::E EEEEEE R::::R R:::::R
1545 PP::::::PP A:::::A A:::::A RR:::::R R:::::RSSSSSSS S:::::SEE::::::EEEEEEEE:::::ERR:::::R R:::::R
1546 P::::::::P A:::::A A:::::A R::::::R R:::::RS::::::SSSSSS:::::SE::::::::::::::::::::ER::::::R R:::::R
1547 P::::::::P A:::::A A:::::A R::::::R R:::::RS:::::::::::::::SS E::::::::::::::::::::ER::::::R R:::::R
1548 PPPPPPPPPPAAAAAAA AAAAAAARRRRRRRR RRRRRRR SSSSSSSSSSSSSSS EEEEEEEEEEEEEEEEEEEEEERRRRRRRR RRRRRRR
1549 -->
1551 <h2>
1552 Parsing</h2>
1554 The input to the parsing stage is a stream or list of tokens from the tokenization stage.
1555 The output depends on how the parser is invoked,
1556 as defined by the entry points listed later in this section.
1557 The parser output can consist of at-rules,
1558 qualified rules,
1559 and/or declarations.
1561 The parser's output is constructed according to the fundamental syntax of CSS,
1562 without regards for the validity of any specific item.
1563 Implementations may check the validity of items as they are returned by the various parser algorithms
1564 and treat the algorithm as returning nothing if the item was invalid according to the implementation's own grammar knowledge,
1565 or may construct a full tree as specified
1566 and "clean up" afterwards by removing any invalid items.
1568 The items that can appear in the tree are:
1570 <dl>
1571 <dt><dfn>at-rule</dfn>
1572 <dd>
1573 An at-rule has a name,
1574 a prelude consisting of a list of component values,
1575 and an optional block consisting of a simple {} block.
1577 Note: This specification places no limits on what an at-rule's block may contain.
1578 Individual at-rules must define whether they accept a block,
1579 and if so,
1580 how to parse it
1581 (preferably using one of the parser algorithms or entry points defined in this specification).
1583 <dt><dfn>qualified rule</dfn>
1584 <dd>
1585 A qualified rule has
1586 a prelude consisting of a list of component values,
1587 and a block consisting of a simple {} block.
1589 Note: Most qualified rules will be style rules,
1590 where the prelude is a selector [[SELECT]]
1591 and the block a <i title="parse a list of declarations">list of declarations</i>.
1593 <dt><dfn>declaration</dfn>
1594 <dd>
1595 A declaration has a name,
1596 a value consisting of a list of component values,
1597 and an <var>important</var> flag which is initially unset.
1599 <p class='issue'>
1600 Should we go ahead and generalize the important flag to be a list of bang values?
1601 Suggested by Zack Weinburg.
1603 Declarations are further categorized as "properties" or "descriptors",
1604 with the former typically appearing in <a>qualified rules</a>
1605 and the latter appearing in <a>at-rules</a>.
1606 (This categorization does not occur at the Syntax level;
1607 instead, it is a product of where the declaration appears,
1608 and is defined by the respective specifications defining the given rule.)
1610 <dt><dfn>component value</dfn>
1611 <dd>
1612 A component value is one of the preserved tokens,
1613 a function,
1614 or a simple block.
1616 <dt><dfn>preserved tokens</dfn>
1617 <dd>
1618 Any token produced by the tokenizer
1619 except for 〈function〉s,
1620 〈{〉s,
1621 〈(〉s,
1622 and 〈[〉s.
1624 Note: The non-preserved tokens listed above are always consumed into higher-level objects,
1625 either functions or simple blocks,
1626 and so never appear in any parser output themselves.
1628 Note: The tokens 〈}〉s, 〈)〉s, 〈]〉, 〈bad-string〉, and 〈bad-url〉 are always parse errors,
1629 but they are preserved in the token stream by this specification to allow other specs,
1630 such as Media Queries,
1631 to define more fine-grainted error-handling
1632 than just dropping an entire declaration or block.
1634 <dt><dfn>function</dfn>
1635 <dd>
1636 A function has a name
1637 and a value consisting of a list of component values.
1639 <dt><dfn>simple block</dfn>
1640 <dd>
1641 A simple block has an associated token (either a 〈[〉, 〈(〉, or 〈{〉)
1642 and a value consisting of a list of component values.
1643 </dl>
1645 <h3 id='parser-diagrams'>
1646 Parser Railroad Diagrams</h3>
1648 <em>This section is non-normative.</em>
1650 This section presents an informative view of the parser,
1651 in the form of railroad diagrams.
1652 Railroad diagrams are more compact than a state-machine,
1653 but often easier to read than a regular expression.
1655 These diagrams are <em>informative</em> and <em>incomplete</em>;
1656 they describe the grammar of "correct" stylesheets,
1657 but do not describe error-handling at all.
1658 They are provided solely to make it easier to get an intuitive grasp of the syntax.
1660 <!--
1661 The "source" of these diagrams is in ./Diagrams.src.html
1662 The generated SVG is copied here so that JavaScript is not required
1663 to view the spec.
1664 -->
1666 <dl>
1667 <dt id="stylesheet-diagram">Stylesheet</dt>
1668 <dd><svg class="railroad-diagram" width="313" height="200"><g transform="translate(.5 .5)"><path d="M 20 121 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 131h0"></path><path d="M272 131h0"></path><path d="M40 131a10 10 0 0 0 10 -10v-89a10 10 0 0 1 10 -10"></path><g><path d="M60 22h192"></path></g><path d="M252 22a10 10 0 0 1 10 10v89a10 10 0 0 0 10 10"></path><path d="M40 131h20"></path><g><path d="M60 131h0"></path><path d="M252 131h0"></path><path d="M60 131h10"></path><g><path d="M70 131h0"></path><path d="M242 131h0"></path><path d="M70 131a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><g><path d="M90 101h8"></path><path d="M214 101h8"></path><rect x="98" y="90" width="116" height="22"></rect><text x="156" y="105">〈whitespace〉</text></g><path d="M222 101a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><path d="M70 131a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10"></path><g><path d="M90 71h36"></path><path d="M186 71h36"></path><rect x="126" y="60" width="60" height="22"></rect><text x="156" y="75">〈CDC〉</text></g><path d="M222 71a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10"></path><path d="M70 131a10 10 0 0 0 10 -10v-70a10 10 0 0 1 10 -10"></path><g><path d="M90 41h36"></path><path d="M186 41h36"></path><rect x="126" y="30" width="60" height="22"></rect><text x="156" y="45">〈CDO〉</text></g><path d="M222 41a10 10 0 0 1 10 10v70a10 10 0 0 0 10 10"></path><path d="M70 131h20"></path><g><path d="M90 131h0"></path><path d="M222 131h0"></path><rect x="90" y="120" width="132" height="22"></rect><text x="156" y="135">Qualified rule</text></g><path d="M222 131h20"></path><path d="M70 131a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M90 161h28"></path><path d="M194 161h28"></path><rect x="118" y="150" width="76" height="22"></rect><text x="156" y="165">At-rule</text></g><path d="M222 161a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M242 131h10"></path><path d="M70 131a10 10 0 0 0 -10 10v29a10 10 0 0 0 10 10"></path><g><path d="M70 180h172"></path></g><path d="M242 180a10 10 0 0 0 10 -10v-29a10 10 0 0 0 -10 -10"></path></g><path d="M252 131h20"></path></g><path d="M 272 131 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1670 <dt id="rule-list-diagram">Rule list</dt>
1671 <dd><svg class="railroad-diagram" width="313" height="140"><g transform="translate(.5 .5)"><path d="M 20 61 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 71h0"></path><path d="M272 71h0"></path><path d="M40 71a10 10 0 0 0 10 -10v-29a10 10 0 0 1 10 -10"></path><g><path d="M60 22h192"></path></g><path d="M252 22a10 10 0 0 1 10 10v29a10 10 0 0 0 10 10"></path><path d="M40 71h20"></path><g><path d="M60 71h0"></path><path d="M252 71h0"></path><path d="M60 71h10"></path><g><path d="M70 71h0"></path><path d="M242 71h0"></path><path d="M70 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><g><path d="M90 41h8"></path><path d="M214 41h8"></path><rect x="98" y="30" width="116" height="22"></rect><text x="156" y="45">〈whitespace〉</text></g><path d="M222 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><path d="M70 71h20"></path><g><path d="M90 71h0"></path><path d="M222 71h0"></path><rect x="90" y="60" width="132" height="22"></rect><text x="156" y="75">Qualified rule</text></g><path d="M222 71h20"></path><path d="M70 71a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M90 101h28"></path><path d="M194 101h28"></path><rect x="118" y="90" width="76" height="22"></rect><text x="156" y="105">At-rule</text></g><path d="M222 101a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M242 71h10"></path><path d="M70 71a10 10 0 0 0 -10 10v29a10 10 0 0 0 10 10"></path><g><path d="M70 120h172"></path></g><path d="M242 120a10 10 0 0 0 10 -10v-29a10 10 0 0 0 -10 -10"></path></g><path d="M252 71h20"></path></g><path d="M 272 71 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1673 <dt id="at-rule-diagram">At-rule</dt>
1674 <dd><svg class="railroad-diagram" width="541" height="102"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M166 41h0"></path><rect x="50" y="30" width="116" height="22"></rect><text x="108" y="45">〈at-keyword〉</text></g><path d="M166 41h10"></path><g><path d="M176 41h0"></path><path d="M376 41h0"></path><path d="M176 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M196 21h160"></path></g><path d="M356 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M176 41h20"></path><g><path d="M196 41h0"></path><path d="M356 41h0"></path><path d="M196 41h10"></path><g><path d="M206 41h0"></path><path d="M346 41h0"></path><rect x="206" y="30" width="140" height="22"></rect><text x="276" y="45">Component value</text></g><path d="M346 41h10"></path><path d="M206 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M206 61h140"></path></g><path d="M346 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M356 41h20"></path></g><g><path d="M376 41h0"></path><path d="M500 41h0"></path><path d="M376 41h20"></path><g><path d="M396 41h0"></path><path d="M480 41h0"></path><rect x="396" y="30" width="84" height="22"></rect><text x="438" y="45">{} block</text></g><path d="M480 41h20"></path><path d="M376 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M396 71h28"></path><path d="M452 71h28"></path><rect x="424" y="60" width="28" height="22" rx="10" ry="10"></rect><text x="438" y="75">;</text></g><path d="M480 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M 500 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1676 <dt id="qualified-rule-diagram">Qualified rule</dt>
1677 <dd><svg class="railroad-diagram" width="385" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 41h0"></path><path d="M240 41h0"></path><path d="M40 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M60 21h160"></path></g><path d="M220 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M40 41h20"></path><g><path d="M60 41h0"></path><path d="M220 41h0"></path><path d="M60 41h10"></path><g><path d="M70 41h0"></path><path d="M210 41h0"></path><rect x="70" y="30" width="140" height="22"></rect><text x="140" y="45">Component value</text></g><path d="M210 41h10"></path><path d="M70 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M70 61h140"></path></g><path d="M210 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M220 41h20"></path></g><path d="M240 41h10"></path><g><path d="M250 41h0"></path><path d="M334 41h0"></path><rect x="250" y="30" width="84" height="22"></rect><text x="292" y="45">{} block</text></g><path d="M334 41h10"></path><path d="M 344 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1679 <dt id="declaration-list-diagram">Declaration list</dt>
1680 <dd><svg class="railroad-diagram" width="589" height="102"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M94 41h0"></path><rect x="50" y="30" width="44" height="22"></rect><text x="72" y="45">ws*</text></g><path d="M94 41h10"></path><g><path d="M104 41h0"></path><path d="M548 41h0"></path><path d="M104 41h20"></path><g><path d="M124 41h0"></path><path d="M528 41h0"></path><g><path d="M124 41h0"></path><path d="M272 41h0"></path><path d="M124 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M144 21h108"></path></g><path d="M252 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M124 41h20"></path><g><path d="M144 41h0"></path><path d="M252 41h0"></path><rect x="144" y="30" width="108" height="22"></rect><text x="198" y="45">Declaration</text></g><path d="M252 41h20"></path></g><g><path d="M272 41h0"></path><path d="M528 41h0"></path><path d="M272 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M292 21h216"></path></g><path d="M508 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M272 41h20"></path><g><path d="M292 41h0"></path><path d="M508 41h0"></path><path d="M292 41h10"></path><g><path d="M302 41h0"></path><path d="M330 41h0"></path><rect x="302" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="316" y="45">;</text></g><path d="M330 41h10"></path><path d="M340 41h10"></path><g><path d="M350 41h0"></path><path d="M498 41h0"></path><rect x="350" y="30" width="148" height="22"></rect><text x="424" y="45">Declaration list</text></g><path d="M498 41h10"></path></g><path d="M508 41h20"></path></g></g><path d="M528 41h20"></path><path d="M104 41a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M124 71h70"></path><path d="M458 71h70"></path><path d="M194 71h10"></path><g><path d="M204 71h0"></path><path d="M280 71h0"></path><rect x="204" y="60" width="76" height="22"></rect><text x="242" y="75">At-rule</text></g><path d="M280 71h10"></path><path d="M290 71h10"></path><g><path d="M300 71h0"></path><path d="M448 71h0"></path><rect x="300" y="60" width="148" height="22"></rect><text x="374" y="75">Declaration list</text></g><path d="M448 71h10"></path></g><path d="M528 71a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path></g><path d="M 548 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1682 <dt id="declaration-diagram">Declaration</dt>
1683 <dd><svg class="railroad-diagram" width="629" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M126 41h0"></path><rect x="50" y="30" width="76" height="22"></rect><text x="88" y="45">〈ident〉</text></g><path d="M126 41h10"></path><path d="M136 41h10"></path><g><path d="M146 41h0"></path><path d="M190 41h0"></path><rect x="146" y="30" width="44" height="22"></rect><text x="168" y="45">ws*</text></g><path d="M190 41h10"></path><path d="M200 41h10"></path><g><path d="M210 41h0"></path><path d="M238 41h0"></path><rect x="210" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="224" y="45">:</text></g><path d="M238 41h10"></path><g><path d="M248 41h0"></path><path d="M448 41h0"></path><path d="M248 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M268 21h160"></path></g><path d="M428 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M248 41h20"></path><g><path d="M268 41h0"></path><path d="M428 41h0"></path><path d="M268 41h10"></path><g><path d="M278 41h0"></path><path d="M418 41h0"></path><rect x="278" y="30" width="140" height="22"></rect><text x="348" y="45">Component value</text></g><path d="M418 41h10"></path><path d="M278 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M278 61h140"></path></g><path d="M418 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M428 41h20"></path></g><g><path d="M448 41h0"></path><path d="M588 41h0"></path><path d="M448 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M468 21h100"></path></g><path d="M568 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M448 41h20"></path><g><path d="M468 41h0"></path><path d="M568 41h0"></path><rect x="468" y="30" width="100" height="22"></rect><text x="518" y="45">!important</text></g><path d="M568 41h20"></path></g><path d="M 588 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1685 <dt id="important-diagram">!important</dt>
1686 <dd><svg class="railroad-diagram" width="449" height="62"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 31h10"></path><g><path d="M50 31h0"></path><path d="M78 31h0"></path><rect x="50" y="20" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="35">!</text></g><path d="M78 31h10"></path><path d="M88 31h10"></path><g><path d="M98 31h0"></path><path d="M142 31h0"></path><rect x="98" y="20" width="44" height="22"></rect><text x="120" y="35">ws*</text></g><path d="M142 31h10"></path><path d="M152 31h10"></path><g><path d="M162 31h0"></path><path d="M334 31h0"></path><rect x="162" y="20" width="172" height="22"></rect><text x="248" y="35">〈ident "important"〉</text></g><path d="M334 31h10"></path><path d="M344 31h10"></path><g><path d="M354 31h0"></path><path d="M398 31h0"></path><rect x="354" y="20" width="44" height="22"></rect><text x="376" y="35">ws*</text></g><path d="M398 31h10"></path><path d="M 408 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1688 <dt id="ws-diagram">ws*</dt>
1689 <dd><svg class="railroad-diagram" width="257" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 41h0"></path><path d="M216 41h0"></path><path d="M40 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M60 21h136"></path></g><path d="M196 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M40 41h20"></path><g><path d="M60 41h0"></path><path d="M196 41h0"></path><path d="M60 41h10"></path><g><path d="M70 41h0"></path><path d="M186 41h0"></path><rect x="70" y="30" width="116" height="22"></rect><text x="128" y="45">〈whitespace〉</text></g><path d="M186 41h10"></path><path d="M70 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M70 61h116"></path></g><path d="M186 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M196 41h20"></path></g><path d="M 216 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1691 <dt id="component-value-diagram">Component value</dt>
1692 <dd><svg class="railroad-diagram" width="261" height="182"><g transform="translate(.5 .5)"><path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><g><path d="M40 31h0"></path><path d="M220 31h0"></path><path d="M40 31h20"></path><g><path d="M60 31h0"></path><path d="M200 31h0"></path><rect x="60" y="20" width="140" height="22"></rect><text x="130" y="35">Preserved token</text></g><path d="M200 31h20"></path><path d="M40 31a10 10 0 0 1 10 10v10a10 10 0 0 0 10 10"></path><g><path d="M60 61h28"></path><path d="M172 61h28"></path><rect x="88" y="50" width="84" height="22"></rect><text x="130" y="65">{} block</text></g><path d="M200 61a10 10 0 0 0 10 -10v-10a10 10 0 0 1 10 -10"></path><path d="M40 31a10 10 0 0 1 10 10v40a10 10 0 0 0 10 10"></path><g><path d="M60 91h28"></path><path d="M172 91h28"></path><rect x="88" y="80" width="84" height="22"></rect><text x="130" y="95">() block</text></g><path d="M200 91a10 10 0 0 0 10 -10v-40a10 10 0 0 1 10 -10"></path><path d="M40 31a10 10 0 0 1 10 10v70a10 10 0 0 0 10 10"></path><g><path d="M60 121h28"></path><path d="M172 121h28"></path><rect x="88" y="110" width="84" height="22"></rect><text x="130" y="125">[] block</text></g><path d="M200 121a10 10 0 0 0 10 -10v-70a10 10 0 0 1 10 -10"></path><path d="M40 31a10 10 0 0 1 10 10v100a10 10 0 0 0 10 10"></path><g><path d="M60 151h4"></path><path d="M196 151h4"></path><rect x="64" y="140" width="132" height="22"></rect><text x="130" y="155">Function block</text></g><path d="M200 151a10 10 0 0 0 10 -10v-100a10 10 0 0 1 10 -10"></path></g><path d="M 220 31 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1694 <dt id="{}-block-diagram">{} block</dt>
1695 <dd><svg class="railroad-diagram" width="377" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M78 41h0"></path><rect x="50" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="45">{</text></g><path d="M78 41h10"></path><g><path d="M88 41h0"></path><path d="M288 41h0"></path><path d="M88 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M108 21h160"></path></g><path d="M268 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M88 41h20"></path><g><path d="M108 41h0"></path><path d="M268 41h0"></path><path d="M108 41h10"></path><g><path d="M118 41h0"></path><path d="M258 41h0"></path><rect x="118" y="30" width="140" height="22"></rect><text x="188" y="45">Component value</text></g><path d="M258 41h10"></path><path d="M118 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M118 61h140"></path></g><path d="M258 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M268 41h20"></path></g><path d="M288 41h10"></path><g><path d="M298 41h0"></path><path d="M326 41h0"></path><rect x="298" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="312" y="45">}</text></g><path d="M326 41h10"></path><path d="M 336 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1697 <dt id="()-block-diagram">() block</dt>
1698 <dd><svg class="railroad-diagram" width="377" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M78 41h0"></path><rect x="50" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="45">(</text></g><path d="M78 41h10"></path><g><path d="M88 41h0"></path><path d="M288 41h0"></path><path d="M88 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M108 21h160"></path></g><path d="M268 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M88 41h20"></path><g><path d="M108 41h0"></path><path d="M268 41h0"></path><path d="M108 41h10"></path><g><path d="M118 41h0"></path><path d="M258 41h0"></path><rect x="118" y="30" width="140" height="22"></rect><text x="188" y="45">Component value</text></g><path d="M258 41h10"></path><path d="M118 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M118 61h140"></path></g><path d="M258 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M268 41h20"></path></g><path d="M288 41h10"></path><g><path d="M298 41h0"></path><path d="M326 41h0"></path><rect x="298" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="312" y="45">)</text></g><path d="M326 41h10"></path><path d="M 336 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1700 <dt id="[]-block-diagram">[] block</dt>
1701 <dd><svg class="railroad-diagram" width="377" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M78 41h0"></path><rect x="50" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="64" y="45">[</text></g><path d="M78 41h10"></path><g><path d="M88 41h0"></path><path d="M288 41h0"></path><path d="M88 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M108 21h160"></path></g><path d="M268 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M88 41h20"></path><g><path d="M108 41h0"></path><path d="M268 41h0"></path><path d="M108 41h10"></path><g><path d="M118 41h0"></path><path d="M258 41h0"></path><rect x="118" y="30" width="140" height="22"></rect><text x="188" y="45">Component value</text></g><path d="M258 41h10"></path><path d="M118 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M118 61h140"></path></g><path d="M258 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M268 41h20"></path></g><path d="M288 41h10"></path><g><path d="M298 41h0"></path><path d="M326 41h0"></path><rect x="298" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="312" y="45">]</text></g><path d="M326 41h10"></path><path d="M 336 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1703 <dt id="function-block-diagram">Function block</dt>
1704 <dd><svg class="railroad-diagram" width="449" height="81"><g transform="translate(.5 .5)"><path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5"></path><path d="M40 41h10"></path><g><path d="M50 41h0"></path><path d="M150 41h0"></path><rect x="50" y="30" width="100" height="22"></rect><text x="100" y="45">〈function〉</text></g><path d="M150 41h10"></path><g><path d="M160 41h0"></path><path d="M360 41h0"></path><path d="M160 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10"></path><g><path d="M180 21h160"></path></g><path d="M340 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10"></path><path d="M160 41h20"></path><g><path d="M180 41h0"></path><path d="M340 41h0"></path><path d="M180 41h10"></path><g><path d="M190 41h0"></path><path d="M330 41h0"></path><rect x="190" y="30" width="140" height="22"></rect><text x="260" y="45">Component value</text></g><path d="M330 41h10"></path><path d="M190 41a10 10 0 0 0 -10 10v0a10 10 0 0 0 10 10"></path><g><path d="M190 61h140"></path></g><path d="M330 61a10 10 0 0 0 10 -10v0a10 10 0 0 0 -10 -10"></path></g><path d="M340 41h20"></path></g><path d="M360 41h10"></path><g><path d="M370 41h0"></path><path d="M398 41h0"></path><rect x="370" y="30" width="28" height="22" rx="10" ry="10"></rect><text x="384" y="45">)</text></g><path d="M398 41h10"></path><path d="M 408 41 h 20 m -10 -10 v 20 m 10 -20 v 20"></path></g></svg></dd>
1706 </dl>
1708 <h3>
1709 Definitions</h3>
1711 <dl>
1712 <dt><dfn>current input token</dfn>
1713 <dd>
1714 The token or <a>component value</a> currently being operated on, from the list of tokens produced by the tokenizer.
1716 <dt><dfn>next input token</dfn>
1717 <dd>
1718 The token or <a>component value</a> following the <a>current input token</a> in the list of tokens produced by the tokenizer.
1719 If there isn't a token following the <a>current input token</a>,
1720 the <a>next input token</a> is an 〈EOF〉.
1722 <dt><dfn>〈EOF〉</dfn>
1723 <dd>
1724 A conceptual token representing the end of the list of tokens.
1725 Whenever the list of tokens is empty,
1726 the <a>next input token</a> is always an 〈EOF〉.
1728 <dt><dfn>consume the next input token</dfn>
1729 <dd>
1730 Let the <a>current input token</a> be the current <a>next input token</a>,
1731 adjusting the <a>next input token</a> accordingly.
1733 <dt><dfn>reconsume the current input token</dfn>
1734 <dd>
1735 The next time an algorithm instructs you to <a>consume the next input token</a>,
1736 instead do nothing
1737 (retain the <a>current input token</a> unchanged).
1739 <dt><dfn>ASCII case-insensitive</dfn>
1740 <dd>
1741 When two strings are to be matched ASCII case-insensitively,
1742 temporarily convert both of them to ASCII lower-case form
1743 by adding 32 (0x20) to the value of each codepoint between
1744 U+0041 LATIN CAPITAL LETTER A (A)
1745 and U+005A LATIN CAPITAL LETTER Z (Z),
1746 inclusive,
1747 and then compare them on a codepoint-by-codepoint basis.
1748 </dl>
1752 <h3>
1753 Parser Entry Points</h3>
1755 The algorithms defined in this section produce high-level CSS objects
1756 from lower-level objects.
1757 They assume that they are invoked on a token stream,
1758 but they may also be invoked on a string;
1759 if so,
1760 first perform <a href="#preprocessing-the-input-stream">input preprocessing</a>
1761 to produce a character stream,
1762 then perform <a href="#tokenization">tokenization</a>
1763 to produce a token stream.
1765 "<a>Parse a stylesheet</a>" can also be invoked on a byte stream,
1766 in which case <a href="#the-input-byte-stream">The input byte stream</a>
1767 defines how to decode it into Unicode.
1769 Note: This specification does not define how a byte stream is decoded for other entry points.
1771 Note: Other specs can define additional entry points for their own purposes.
1773 <div class='issue'>
1774 The following notes should probably be translated into normative text in the relevant specs,
1775 hooking this spec's terms:
1777 <ul>
1778 <li>
1779 "<a>Parse a stylesheet</a>" is intended to be the normal parser entry point,
1780 for parsing stylesheets.
1782 <li>
1783 "<a>Parse a list of rules</a>" is intended for the content of at-rules such as ''@media''.
1784 It differs from "<a>Parse a stylesheet</a>" in the handling of 〈CDO〉 and 〈CDC〉.
1786 <li>
1787 "<a>Parse a rule</a>" is intended for use by the <code>CSSStyleSheet#insertRule</code> method,
1788 and similar functions which might exist,
1789 which parse text into a single rule.
1791 <li>
1792 "<a>Parse a declaration</a>" is used in ''@supports'' conditions. [[CSS3-CONDITIONAL]]
1794 <li>
1795 "<a>Parse a list of declarations</a>" is for the contents of a <code>style</code> attribute,
1796 which parses text into the contents of a single style rule.
1798 <li>
1799 "<a>Parse a component value</a>" is for things that need to consume a single value,
1800 like the parsing rules for ''attr()''.
1802 <li>
1803 "<a>Parse a list of component values</a>" is for the contents of presentational attributes,
1804 which parse text into a single declaration's value,
1805 or for parsing a stand-alone selector [[SELECT]] or list of Media Queries [[MEDIAQ]],
1806 as in <a href="http://www.w3.org/TR/selectors-api/">Selectors API</a>
1807 or the <code>media</code> HTML attribute.
1808 </ul>
1809 </div>
1811 All of the algorithms defined in this spec may be called with either a list of tokens or of component values.
1812 Either way produces an identical result.
1815 <h4>
1816 <dfn>Parse a stylesheet</dfn></h4>
1818 To <a>parse a stylesheet</a> from a stream of tokens:
1820 <ol>
1821 <li>
1822 Create a new stylesheet.
1824 <li>
1825 <a>Consume a list of rules</a> from the stream of tokens, with the <var>top-level flag</var> set.
1827 <li>
1828 Assign the returned value to the stylesheet's value.
1830 <li>
1831 Return the stylesheet.
1832 </ol>
1834 <h4>
1835 <dfn>Parse a list of rules</dfn></h4>
1837 To <a>parse a list of rules</a> from a stream of tokens:
1839 <ol>
1840 <li>
1841 <a>Consume a list of rules</a> from the stream of tokens, with the <var>top-level flag</var> unset.
1843 <li>
1844 Return the returned list.
1845 </ol>
1847 <h4>
1848 <dfn>Parse a rule</dfn></h4>
1850 To <a>parse a rule</a> from a stream of tokens:
1852 <ol>
1853 <li>
1854 <a>Consume the next input token</a>.
1856 <li>
1857 While the <a>current input token</a> is a 〈whitespace〉,
1858 <a>consume the next input token</a>.
1860 <li>
1861 If the <a>current input token</a> is an 〈EOF〉,
1862 return a syntax error.
1864 Otherwise,
1865 if the <a>current input token</a> is an 〈at-keyword〉,
1866 <a>consume an at-rule</a>.
1868 Otherwise,
1869 <a>consume a qualified rule</a>.
1870 If nothing was returned,
1871 return a syntax error.
1873 <li>
1874 While the <a>current input token</a> is a 〈whitespace〉,
1875 <a>consume the next input token</a>.
1877 <li>
1878 If the <a>current input token</a> is an 〈EOF〉,
1879 return the rule obtained in step 2.
1880 Otherwise, return a syntax error.
1881 </ol>
1883 <h4>
1884 <dfn>Parse a declaration</dfn></h4>
1886 Note: Unlike "<a>Parse a list of declarations</a>",
1887 this parses only a declaration and not an at-rule.
1889 To <a>parse a declaration</a>:
1891 <ol>
1892 <li>
1893 <a>Consume the next input token</a>.
1895 <li>
1896 While the <a>current input token</a> is a 〈whitespace〉,
1897 <a>consume the next input token</a>.
1899 <li>
1900 <a>Consume a declaration</a>.
1901 If anything was returned, return it.
1902 Otherwise, return a syntax error.
1903 </ol>
1905 <h4>
1906 <dfn>Parse a list of declarations</dfn></h4>
1908 Note: Despite the name,
1909 this actually parses a mixed list of declarations and at-rules,
1910 as CSS 2.1 does for <a href=http://www.w3.org/TR/CSS21/page.html#page-box>''@page''</a>.
1911 Unexpected at-rules (which could be all of them, in a given context)
1912 are invalid and should be ignored by the consumer.
1914 To <a>parse a list of declarations</a>:
1916 <ol>
1917 <li>
1918 <a>Consume a list of declarations</a>.
1920 <li>
1921 Return the returned list.
1922 </ol>
1924 <h4>
1925 <dfn>Parse a component value</dfn></h4>
1927 To <a>parse a component value</a>:
1929 <ol>
1930 <li>
1931 <a>Consume the next input token</a>.
1933 <li>
1934 While the <a>current input token</a> is a 〈whitespace〉,
1935 <a>consume the next input token</a>.
1937 <li>
1938 If the <a>current input token</a> is an 〈EOF〉,
1939 return a syntax error.
1941 <li>
1942 <a>Reconsume the current input token</a>.
1943 <a>Consume a component value</a>.
1944 If nothing is returned,
1945 return a syntax error.
1947 <li>
1948 While the <a>current input token</a> is a 〈whitespace〉,
1949 <a>consume the next input token</a>.
1951 <li>
1952 If the <a>current input token</a> is an 〈EOF〉,
1953 return the <a>component value</a> returned in step 3.
1954 Otherwise,
1955 return a syntax error.
1956 </ol>
1958 <h4>
1959 <dfn>Parse a list of component values</dfn></h4>
1961 To <a>parse a list of component values</a>:
1963 <ol>
1964 <li>
1965 Repeatedly <a>consume a component value</a> until an 〈EOF〉 is returned,
1966 appending the returned values (except the final 〈EOF〉) into a list.
1967 Return the list.
1968 </ol>
1970 <h3>
1971 Parser Algorithms</h3>
1973 The following algorithms comprise the parser.
1974 They are called by the parser entry points above.
1976 These algorithms may be called with a list of either tokens or of component values.
1977 (The difference being that some tokens are replaced by <a>functions</a> and <a>simple blocks</a> in a list of component values.)
1978 Similar to how the input stream returned EOF characters to represent when it was empty during the tokenization stage,
1979 the lists in this stage must return an 〈EOF〉 when the next token is requested but they are empty.
1981 An algorithm may be invoked with a specific list,
1982 in which case it consumes only that list
1983 (and when that list is exhausted,
1984 it begins returning 〈EOF〉s).
1985 Otherwise,
1986 it is implicitly invoked with the same list as the invoking algorithm.
1989 <h4>
1990 <dfn>Consume a list of rules</dfn></h4>
1992 Create an initially empty list of rules.
1994 Repeatedly consume the <a>next input token</a>:
1996 <dl>
1997 <dt>〈whitespace〉
1998 <dd>
1999 Do nothing.
2001 <dt>〈EOF〉
2002 <dd>
2003 Return the list of rules.
2005 <dt>〈CDO〉
2006 <dt>〈CDC〉
2007 <dd>
2008 If the <dfn><var>top-level flag</var></dfn> is set,
2009 do nothing.
2011 Otherwise,
2012 <a>reconsume the current input token</a>.
2013 <a>Consume a qualified rule</a>.
2014 If anything is returned,
2015 append it to the list of rules.
2017 <dt>〈at-keyword〉
2018 <dd>
2019 <a>Reconsume the current input token</a>.
2020 <a>Consume an at-rule</a>.
2021 If anything is returned,
2022 append it to the list of rules.
2024 <dt>anything else
2025 <dd>
2026 <a>Reconsume the current input token</a>.
2027 <a>Consume a qualified rule</a>.
2028 If anything is returned,
2029 append it to the list of rules.
2030 </dl>
2033 <h4>
2034 <dfn>Consume an at-rule</dfn></h4>
2036 Create a new at-rule
2037 with its name set to the value of the <a>current input token</a>,
2038 its prelude initially set to an empty list,
2039 and its value initially set to nothing.
2041 Repeatedly consume the <a>next input token</a>:
2043 <dl>
2044 <dt>〈semicolon〉
2045 <dt>〈EOF〉
2046 <dd>
2047 Return the at-rule.
2049 <dt>〈{〉
2050 <dd>
2051 <a>Consume a simple block</a>
2052 and assign it to the at-rule's block.
2053 Return the at-rule.
2055 <dt><a>simple block</a> with an associated token of 〈{〉
2056 <dd>
2057 Assign the block to the at-rule's block.
2058 Return the at-rule.
2060 <dt>anything else
2061 <dd>
2062 <a>Reconsume the current input token</a>.
2063 <a>Consume a component value</a>.
2064 Append the returned value to the at-rule's prelude.
2065 </dl>
2068 <h4>
2069 <dfn>Consume a qualified rule</dfn></h4>
2071 Create a new qualified rule
2072 with its prelude initially set to an empty list,
2073 and its value initially set to nothing.
2075 Repeatedly consume the <a>next input token</a>:
2077 <dl>
2078 <dt>〈EOF〉
2079 <dd>
2080 This is a <a>parse error</a>.
2081 Return nothing.
2083 <dt>〈{〉
2084 <dd>
2085 <a>Consume a simple block</a>
2086 and assign it to the qualified rule's block.
2087 Return the qualified rule.
2089 <dt><a>simple block</a> with an associated token of 〈{〉
2090 <dd>
2091 Assign the block to the qualified rule's block.
2092 Return the qualified rule.
2094 <dt>anything else
2095 <dd>
2096 <a>Reconsume the current input token</a>.
2097 <a>Consume a component value</a>.
2098 Append the returned value to the qualified rule's prelude.
2099 </dl>
2102 <h4>
2103 <dfn>Consume a list of declarations</dfn></h4>
2105 Create an initially empty list of declarations.
2107 Repeatedly consume the <a>next input token</a>:
2109 <dl>
2110 <dt>〈whitespace〉
2111 <dt>〈semicolon〉
2112 <dd>
2113 Do nothing.
2115 <dt>〈EOF〉
2116 <dd>
2117 Return the list of declarations.
2119 <dt>〈at-keyword〉
2120 <dd>
2121 <a>Consume an at-rule</a>.
2122 Append the returned rule to the list of declarations.
2124 <dt>〈ident〉
2125 <dd>
2126 Initialize a temporary list initially filled with the <a>current input token</a>.
2127 <a>Consume the next input token</a>.
2128 While the <a>current input token</a> is anything other than a 〈semicolon〉 or 〈EOF〉,
2129 append it to the temporary list
2130 and <a>consume the next input token</a>.
2131 <a>Consume a declaration</a> from the temporary list.
2132 If anything was returned,
2133 append it to the list of declarations.
2135 <dt>anything else</dd>
2136 <dd>
2137 This is a <a>parse error</a>.
2138 Repeatedly <a>consume a component value</a>
2139 until it is a 〈semicolon〉 or 〈EOF〉.
2140 </dl>
2143 <h4>
2144 <dfn>Consume a declaration</dfn></h4>
2146 Create a new declaration
2147 with its name set to the value of the <a>current input token</a>
2148 and its value initially set to the empty list.
2150 <ol>
2151 <li>
2152 <a>Consume the next input token</a>.
2154 <li>
2155 While the <a>current input token</a> is a 〈whitespace〉,
2156 <a>consume the next input token</a>.
2158 <li>
2159 If the <a>current input token</a> is anything other than a 〈colon〉,
2160 this is a <a>parse error</a>.
2161 Return nothing.
2163 Otherwise, <a>consume the next input token</a>.
2165 <li>
2166 While the <a>current input token</a> is anything other than an 〈EOF〉,
2167 append it to the declaration's value
2168 and <a>consume the next input token</a>.
2170 <li>
2171 If the last two non-〈whitespace〉s in the declaration's value are
2172 a 〈delim〉 with the value "!"
2173 followed by an 〈ident〉 with a value that is an <a>ASCII case-insensitive</a> match for "important",
2174 remove them from the declaration's value
2175 and set the declaration's <var>important</var> flag to true.
2177 <li>
2178 Return the declaration.
2179 </ol>
2182 <h4>
2183 <dfn>Consume a component value</dfn></h4>
2185 This section describes how to <a>consume a component value</a>.
2187 <a>Consume the next input token</a>.
2189 If the <a>current input token</a>
2190 is a 〈{〉, 〈[〉, or 〈(〉,
2191 <a>consume a simple block</a>
2192 and return it.
2194 Otherwise, if the <a>current input token</a>
2195 is a 〈function〉,
2196 <a>consume a function</a>
2197 and return it.
2199 Otherwise, return the <a>current input token</a>.
2202 <h4>
2203 <dfn>Consume a simple block</dfn></h4>
2205 This section describes how to <a>consume a simple block</a>.
2207 The <dfn>ending token</dfn> is the mirror variant of the <a>current input token</a>.
2208 (E.g. if it was called with 〈[〉, the <a>ending token</a> is 〈]〉.)
2210 Create a <a>simple block</a> with its associated token set to the <a>current input token</a>
2211 and with a value with is initially an empty list.
2213 Repeatedly consume the <a>next input token</a> and process it as follows:
2215 <dl>
2216 <dt>〈EOF〉
2217 <dt><a>ending token</a>
2218 <dd>
2219 Return the block.
2221 <dt>anything else
2222 <dd>
2223 <a>Reconsume the current input token</a>.
2224 <a>Consume a component value</a>
2225 and append it to the value of the block.
2226 </dl>
2229 <h4>
2230 <dfn>Consume a function</dfn></h4>
2232 This section describes how to <a>consume a function</a>.
2234 Create a function with a name equal to the value of the <a>current input token</a>,
2235 and with a value which is initially an empty list.
2237 Repeatedly consume the <a>next input token</a> and process it as follows:
2239 <dl>
2240 <dt>〈EOF〉
2241 <dt>〈)〉
2242 <dd>
2243 Return the function.
2245 <dt>anything else
2246 <dd>
2247 <a>Reconsume the current input token</a>.
2248 <a>Consume a component value</a>
2249 and append the returned value
2250 to the function's value.
2251 </dl>
2255 <h2 id="anb">
2256 The <var>An+B</var> microsyntax</h2>
2258 Several things in CSS,
2259 such as the '':nth-child()'' pseudoclass,
2260 need to indicate indexes in a list.
2261 The <var>An+B</var> microsyntax is useful for this,
2262 allowing an author to easily indicate single elements
2263 or all elements at regularly-spaced intervals in a list.
2265 The <dfn>An+B</dfn> notation defines an integer step (<dfn>A</dfn>) and offset (<dfn>B</dfn>),
2266 and represents the <var>An+B</var>th elements in a list,
2267 for every positive integer or zero value of <var>n</var>,
2268 with the first element in the list having index 1 (not 0).
2270 For values of <var>A</var> and <var>B</var> greater than 0,
2271 this effectively divides the list into groups of <var>A</var> elements
2272 (the last group taking the remainder),
2273 and selecting the <var>B</var>th element of each group.
2275 The <var>An+B</var> notation also accepts the ''even'' and ''odd'' keywords,
2276 which have the same meaning as ''2n'' and ''2n+1'', respectively.
2278 <div class="example">
2279 <p>Examples:
2280 <pre><!--
2281 -->2n+0 /* represents all of the even elements in the list */
<!--
2282 -->even /* same */
<!--
2283 -->4n+1 /* represents the 1st, 5th, 9th, 13th, etc. elements in the list */</pre>
2284 </div>
2286 The values of <var>A</var> and <var>B</var> can be negative,
2287 but only the positive results of <var>An+B</var>,
2288 for <var>n</var> ≥ 0,
2289 are used.
2291 <div class="example">
2292 <p>Example:
2293 <pre>-n+6 /* represents the first 6 elements of the list */</pre>
2294 </div>
2296 If both <var>A</var> and <var>B</var> are 0,
2297 the pseudo-class represents no element in the list.
2299 <h3 id='anb-syntax'>
2300 Informal Syntax Description</h3>
2302 <em>This section is non-normative.</em>
2304 When <var>A</var> is 0, the <var>An</var> part may be omitted
2305 (unless the <var>B</var> part is already omitted).
2306 When <var>An</var> is not included
2307 and <var>B</var> is non-negative,
2308 the ''+'' sign before <var>B</var> (when allowed)
2309 may also be omitted.
2310 In this case the syntax simplifies to just <var>B</var>.
2312 <div class="example">
2313 <p>Examples:
2314 <pre><!--
2315 -->0n+5 /* represents the 5th element in the list */
<!--
2316 -->5 /* same */</pre>
2317 </div>
2319 When <var>A</var> is 1 or -1,
2320 the <code>1</code> may be omitted from the rule.
2322 <div class="example">
2323 <p>Examples:
2324 <p>The following notations are therefore equivalent:
2325 <pre><!--
2326 -->1n+0 /* represents all elements in the list */
<!--
2327 -->n+0 /* same */
<!--
2328 -->n /* same */</pre>
2329 </div>
2331 If <var>B</var> is 0, then every <var>A</var>th element is picked.
2332 In such a case,
2333 the <var>+B</var> (or <var>-B</var>) part may be omitted
2334 unless the <var>A</var> part is already omitted.
2336 <div class="example">
2337 <p>Examples:
2338 <pre><!--
2339 -->2n+0 /* represents every even element in the list */
<!--
2340 -->2n /* same */</pre>
2341 </div>
2343 Whitespace is permitted on either side of the ''+'' or ''-''
2344 that separates the <var>An</var> and <var>B</var> parts when both are present.
2346 <div class="example">
2347 <p>Valid Examples with white space:
2348 <pre><!--
2349 -->3n + 1
<!--
2350 -->+3n - 2
<!--
2351 -->-n+ 6
<!--
2352 -->+6</pre>
2353 <p>Invalid Examples with white space:
2354 <pre><!--
2355 -->3 n
<!--
2356 -->+ 2n
<!--
2357 -->+ 2</pre>
2358 </div>
2361 <h3 id="the-anb-type">
2362 The <code><an+b></code> type</h3>
2364 The <var>An+B</var> notation was originally defined using a slightly different tokenizer than the rest of CSS,
2365 resulting in a somewhat odd definition when expressed in terms of CSS tokens.
2366 This section describes how to recognize the <var>An+B</var> notation in terms of CSS tokens
2367 (thus defining the <var><an+b></var> type for CSS grammar purposes),
2368 and how to interpret the CSS tokens to obtain values for <var>A</var> and <var>B</var>.
2370 The <var><an+b></var> type is defined
2371 (using the <a href="http://www.w3.org/TR/css3-values/#value-defs">Value Definition Syntax in the Values & Units spec</a>)
2372 as:
2374 <pre class='prod'>
2375 <dfn id="anb-production"><an+b></dfn> =
2376 odd | even |
2377 <var><integer></var> |
2379 <var><n-dimension></var> |
2380 '+'?<sup><a href="#anb-plus">†</a></sup> n |
2381 -n |
2383 <var><ndashdigit-dimension></var> |
2384 '+'?<sup><a href="#anb-plus">†</a></sup> <var><ndashdigit-ident></var> |
2385 <var><dashndashdigit-ident></var> |
2387 <var><n-dimension></var> <var><signed-integer></var> |
2388 '+'?<sup><a href="#anb-plus">†</a></sup> n <var><signed-integer></var> |
2389 -n <var><signed-integer></var> |
2391 <var><ndash-dimension></var> <var><signless-integer></var> |
2392 '+'?<sup><a href="#anb-plus">†</a></sup> n- <var><signless-integer></var> |
2393 -n- <var><signless-integer></var> |
2395 <var><n-dimension></var> ['+' | '-'] <var><signless-integer></var>
2396 '+'?<sup><a href="#anb-plus">†</a></sup> n ['+' | '-'] <var><signless-integer></var> |
2397 -n ['+' | '-'] <var><signless-integer></var>
2398 </pre>
2400 where:
2402 <ul>
2403 <li><dfn><code><n-dimension></code></dfn> is a 〈dimension〉 with its type flag set to "integer", and a unit that is an <a>ASCII case-insensitive</a> match for "n"
2404 <li><dfn><code><ndash-dimension></code></dfn> is a 〈dimension〉 with its type flag set to "integer", and a unit that is an <a>ASCII case-insensitive</a> match for "n-"
2405 <li><dfn><code><ndashdigit-dimension></code></dfn> is a 〈dimension〉 with its type flag set to "integer", and a unit that is an <a>ASCII case-insensitive</a> match for "n-*", where "*" is a series of one or more <a>digits</a>
2406 <li><dfn><code><ndashdigit-ident></code></dfn> is an 〈ident〉 whose value is an <a>ASCII case-insensitive</a> match for "n-*", where "*" is a series of one or more <a>digits</a>
2407 <li><dfn><code><dashndashdigit-ident></code></dfn> is an 〈ident〉 whose value is an <a>ASCII case-insensitive</a> match for "-n-*", where "*" is a series of one or more <a>digits</a>
2408 <li><dfn><code><integer></code></dfn> is a 〈number〉 with its type flag set to "integer"
2409 <li><dfn><code><signed-integer></code></dfn> is a 〈number〉 with its type flag set to "integer", and whose representation starts with "+" or "-"
2410 <li><dfn><code><signless-integer></code></dfn> is a 〈number〉 with its type flag set to "integer", and whose representation start with a <a>digit</a>
2411 </ul>
2413 <p id="anb-plus">
2414 <sup>†</sup>: When a plus sign (+) precedes an ident starting with "n", as in the cases marked above,
2415 there must be no whitespace between the two tokens,
2416 or else the tokens do not match the above grammar.
2418 The clauses of the production are interpreted as follows:
2420 <dl>
2421 <dt>''odd''
2422 <dd>
2423 <var>A</var> is 2, <var>B</var> is 1.
2425 <dt>''even''
2426 <dd>
2427 <var>A</var> is 2, <var>B</var> is 0.
2429 <dt><code><var><integer></var></code>
2430 <dd>
2431 <var>A</var> is 0, <var>B</var> is the integer’s value.
2433 <dt><code><var><n-dimension></var></code>
2434 <dt><code>'+'? n</code>
2435 <dt><code>-n</code>
2436 <dd>
2437 <var>A</var> is the dimension's value, 1, or -1, respectively.
2438 <var>B</var> is 0.
2440 <dt><code><var><ndashdigit-dimension></var></code>
2441 <dt><code>'+'? <var><ndashdigit-ident></var></code>
2442 <dd>
2443 <var>A</var> is the dimension's value or 1, respectively.
2444 <var>B</var> is the dimension's unit or ident's value, respectively,
2445 with the first character removed and the remainder interpreted as a base-10 number.
2446 <span class=note>B is negative.</span>
2448 <dt><code><var><dashndashdigit-ident></var></code>
2449 <dd>
2450 <var>A</var> is -1.
2451 <var>B</var> is the ident's value, with the first two characters removed and the remainder interpreted as a base-10 number.
2452 <span class=note>B is negative.</span>
2454 <dt><code><var><n-dimension></var> <var><signed-integer></var></code>
2455 <dt><code>'+'? n <var><signed-integer></var></code>
2456 <dt><code>-n <var><signed-integer></var></code>
2457 <dd>
2458 <var>A</var> is the dimension's value, 1, or -1, respectively.
2459 <var>B</var> is the integer’s value.
2461 <dt><code><var><ndash-dimension></var> <var><signless-integer></var></code>
2462 <dt><code>'+'? n- <var><signless-integer></var></code>
2463 <dt><code>-n- <var><signless-integer></var></code>
2464 <dd>
2465 <var>A</var> is the dimension's value, 1, or -1, respectively.
2466 <var>B</var> is the negation of the integer’s value.
2468 <dt><code><var><n-dimension></var> ['+' | '-'] <var><signless-integer></var></code>
2469 <dt><code>'+'? n ['+' | '-'] <var><signless-integer></var></code>
2470 <dt><code>-n ['+' | '-'] <var><signless-integer></var></code>
2471 <dd>
2472 <var>A</var> is the dimension's value, 1, or -1, respectively.
2473 <var>B</var> is the integer’s value.
2474 If a '-' was provided between the two, <var>B</var> is instead the negation of the integer’s value.
2475 </dl>
2479 <h2 id='rule-defs'>
2480 Defining Grammars for Rules and Other Values</h2>
2482 The <a href="http://www.w3.org/TR/css3-values/">Values</a> spec defines how to specify a grammar for properties.
2483 This section does the same, but for rules.
2485 Just like in property grammars,
2486 the notation <code><foo></code> refers to the "foo" grammar term,
2487 assumed to be defined elsewhere.
2488 Substituting the <code><foo></code> for its definition results in a semantically identical grammar.
2490 Several types of tokens are written literally, without quotes:
2492 <ul>
2493 <li>〈ident〉s (such as ''auto'', ''disc'', etc), which are simply written as their value.
2494 <li>〈at-keyword〉s, which are written as an @ character followed by the token's value, like "@media".
2495 <li>〈function〉s, which are written as the function name followed by a ( character, like "translate(".
2496 <li>The 〈colon〉 (written as <code>:</code>), 〈comma〉 (written as <code>,</code>), 〈semicolon〉 (written as <code>;</code>), 〈(〉, 〈)〉, 〈{〉, and 〈}〉s.
2497 </ul>
2499 Tokens match if their value is an <a>ASCII case-insensitive</a> match
2500 for the value defined in the grammar.
2502 <p class=note>
2503 Although it is possible, with <a>escaping</a>,
2504 to construct an 〈ident〉 whose value starts with <code>@</code> or ends with <code>(</code>,
2505 such a tokens is not an 〈at-keyword〉 or a 〈function〉
2506 and does not match corresponding grammar definitions.
2508 〈delim〉s are written with their value enclosed in single quotes.
2509 For example, a 〈delim〉 containing the "+" character is written as <code>'+'</code>.
2510 Similarly, the 〈[〉 and 〈]〉s must be written in single quotes,
2511 as they're used by the syntax of the grammar itself to group clauses.
2512 〈whitespace〉 is never indicated in the grammar;
2513 〈whitespace〉s are allowed before, after, and between any two tokens,
2514 unless explicitly specified otherwise in prose definitions.
2515 (For example, if the prelude of a rule is a selector,
2516 whitespace is significant.)
2518 When defining a function or a block,
2519 the ending token must be specified in the grammar,
2520 but if it's not present in the eventual token stream,
2521 it still matches.
2523 <div class='example'>
2524 For example, the syntax of the ''translateX()'' function is:
2526 <pre>translateX( <<translation-value>> )</pre>
2528 However, the stylesheet may end with the function unclosed, like:
2530 <pre>.foo { transform: translate(50px</pre>
2532 The CSS parser parses this as a style rule containing one declaration,
2533 whose value is a function named "translate".
2534 This matches the above grammar,
2535 even though the ending token didn't appear in the token stream,
2536 because by the time the parser is finished,
2537 the presence of the ending token is no longer possible to determine;
2538 all you have is the fact that there's a block and a function.
2539 </div>
2541 <h3 id='declaration-rule-list'>
2542 Defining Block Contents: the <<declaration-list>>, <<rule-list>>, and <<stylesheet>> productions</h3>
2544 The CSS parser is agnostic as to the contents of blocks,
2545 such as those that come at the end of some at-rules.
2546 Defining the generic grammar of the blocks in terms of tokens is non-trivial,
2547 but there are dedicated and unambiguous algorithms defined for parsing this.
2549 The <dfn><declaration-list></dfn> production represents a list of declarations.
2550 It may only be used in grammars as the sole value in a block,
2551 and represents that the contents of the block must be parsed using the <a>consume a list of declarations</a> algorithm.
2553 Similarly, the <dfn><rule-list></dfn> production represents a list of rules,
2554 and may only be used in grammars as the sole value in a block.
2555 It represents that the contents of the block must be parsed using the <a>consume a list of rules</a> algorithm.
2557 Finally, the <dfn><stylesheet></dfn> production represents a list of rules.
2558 It is identical to <<rule-list>>,
2559 except that blocks using it default to accepting all rules
2560 that aren't otherwise limited to a particular context.
2562 <div class='example'>
2563 For example, the ''@font-face'' rule is defined to have an empty prelude,
2564 and to contain a list of declarations.
2565 This is expressed with the following grammar:
2567 <pre>@font-face { <<declaration-list>> }</pre>
2569 This is a complete and sufficient definition of the rule's grammar.
2571 For another example,
2572 ''@keyframes'' rules are more complex,
2573 interpreting their prelude as a name and containing keyframes rules in their block
2574 Their grammar is:
2576 <pre>@keyframes <<keyframes-name>> { <<rule-list>> }</pre>
2577 </div>
2579 For rules that use <<declaration-list>>,
2580 the spec for the rule must define which properties, descriptors, and/or at-rules are valid inside the rule;
2581 this may be as simple as saying "The @foo rule accepts the properties/descriptors defined in this specification/section.",
2582 and extension specs may simply say "The @foo rule additionally accepts the following properties/descriptors.".
2583 Any declarations or at-rules found inside the block that are not defined as valid
2584 must be removed from the rule's value.
2586 Within a <<declaration-list>>,
2587 <code>!important</code> is automatically invalid on any descriptors.
2588 If the rule accepts properties,
2589 the spec for the rule must define whether the properties interact with the cascade,
2590 and with what specificity.
2591 If they don't interact with the cascade,
2592 properties containing <code>!important</code> are automatically invalid;
2593 otherwise using <code>!important</code> is valid and has its usual effect on the cascade origin of the property.
2595 <div class='example'>
2596 For example, the grammar for ''@font-face'' in the previous example must,
2597 in addition to what is written there,
2598 define that the allowed declarations are the descriptors defined in the Fonts spec.
2599 </div>
2601 For rules that use <<rule-list>>,
2602 the spec for the rule must define what types of rules are valid inside the rule,
2603 same as <<declaration-list>>,
2604 and unrecognized rules must similarly be removed from the rule's value.
2606 <div class='example'>
2607 For example, the grammar for ''@keyframes'' in the previous example must,
2608 in addition to what is written there,
2609 define that the only allowed rules are <<keyframe-rule>>s,
2610 which are defined as:
2612 <pre><<keyframe-rule>> = <<keyframe-selector>> { <<declaration-list>> }</pre>
2614 Keyframe rules, then,
2615 must further define that they accept as declarations all animatable CSS properties,
2616 plus the 'animation-timing-function' property,
2617 but that they do not interact with the cascade.
2618 </div>
2620 For rules that use <<stylesheet>>,
2621 all rules are allowed by default,
2622 but the spec for the rule may define what types of rules are <em>invalid</em> inside the rule.
2624 <div class='example'>
2625 For example, the ''@media'' rule accepts anything that can be placed in a stylesheet,
2626 except more ''@media'' rules.
2627 As such, its grammar is:
2629 <pre>@media <<media-query-list>> { <<stylesheet>> }</pre>
2631 It additionally defines a restriction that the <<stylesheet>> can not contain ''@media'' rules,
2632 which causes them to be dropped from the outer rule's value if they appear.
2633 </div>
2636 <h2>
2637 CSS stylesheets</h2>
2639 To parse a CSS stylesheet,
2640 first <i>parse a stylesheet</i>.
2641 Interpret all of the resulting top-level <i>qualified rules</i> as <i>style rules</i>, defined below.
2643 If any style rule is invalid,
2644 or any at-rule is not recognized or is invalid according to its grammar or context,
2645 it's a <i>parse error</i>.
2646 Discard that rule.
2648 <h3>
2649 Style rules</h3>
2651 A <dfn>style rule</dfn> is a <i>qualified rule</i>
2652 that associates a <a href="http://dev.w3.org/csswg/selectors4/#selector-list">selector list</a> [[!SELECT]]
2653 with a list of property declarations.
2654 They are also called
2655 <a href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">rule sets</a> in [[!CSS21]].
2656 CSS Cascading and Inheritance [[!CSS3CASCADE]] defines how the declarations inside of style rules participate in the cascade.
2658 The prelude of the qualified rule is parsed as a
2659 <a href="http://dev.w3.org/csswg/selectors4/#selector-list">selector list</a>.
2660 If this results in an <a href="http://dev.w3.org/csswg/selectors4/#invalid">invalid selector list</a>,
2661 the entire style rule is invalid.
2663 The content of the qualified rule’s block is parsed as a
2664 <i title="parse a list of declarations">list of declarations</i>.
2665 Unless defined otherwise by another specification or a future level of this specification,
2666 at-rules in that list are invalid
2667 and must be ignored.
2668 Declaration for an unknown CSS property
2669 or whose value does not match the syntax defined by the property are invalid
2670 and must be ignored.
2671 The validity of the style rule’s contents have no effect on the validity of the style rule itself.
2672 Unless otherwise specified, property names are <i>ASCII case-insensitive</i>.
2674 If a <i>style rule</i> contains multiple declarations with the same name,
2675 all but the last such declaration are discarded.
2677 Note: The names of Custom Properties [[CSS-VARIABLES]] are case-sensitive.
2679 <i>Qualified rules</i> at the top-level of a CSS stylesheet are style rules.
2680 Qualified rules in other contexts may or may not be style rules,
2681 as defined by the context.
2683 <p class='example'>
2684 For example, qualified rules inside ''@media'' rules [[CSS3-CONDITIONAL]] are style rules,
2685 but qualified rules inside ''@keyframes'' rules are not [[CSS3-ANIMATIONS]].
2687 <h3>
2688 The ''@charset'' Rule</h3>
2690 The <dfn>''@charset''</dfn> rule is a very special <i>at-rule</i> associated with determining the character encoding of the stylesheet.
2691 In general, its grammar is:
2693 <pre class='prod'><dfn><at-charset-rule></dfn> = @charset <<string>>;</pre>
2695 Additionally, an ''@charset'' rule is invalid if it is not at the top-level of a stylesheet,
2696 or if it is not the very first rule of a stylesheet.
2698 ''@charset'' rules have an <dfn>encoding</dfn>,
2699 given by the value of the <<string>>.
2701 The ''@charset'' rule has <strong>no effect on a stylesheet</strong>.
2703 Note: However, the algorithm to <a>determine the fallback encoding</a>
2704 looks at the first several bytes of the stylesheet
2705 to see if they're a match for the ASCII characters <code>@charset "XXX";</code>,
2706 where XXX is a sequence of bytes other than 22 (ASCII for <code>"</code>).
2707 While this resembles an ''@charset'' rule,
2708 it's not actually the same thing.
2709 For example, the necessary sequence of bytes will spell out something entirely different
2710 if the stylesheet is in an encoding that's not ASCII-compatible,
2711 such as UTF-16.
2715 <h2>
2716 Serialization</h2>
2718 This specification does not define how to serialize CSS in general,
2719 leaving that task to the CSSOM and individual feature specifications.
2720 However, there is one important facet that must be specified here regarding comments,
2721 to ensure accurate "round-tripping" of data from text to CSS objects and back.
2723 The tokenizer described in this specification does not produce tokens for comments,
2724 or otherwise preserve them in any way.
2725 Implementations may preserve the contents of comments and their location in the token stream.
2726 If they do, this preserved information must have no effect on the parsing step,
2727 but must be serialized in its position as
2728 "/*"
2729 followed by its contents
2730 followed by "*/".
2732 If the implementation does not preserve comments,
2733 it must insert the text "/**/" between the serialization of adjacent tokens
2734 when the two tokens are of the following pairs:
2736 <ul>
2737 <li>
2738 a 〈hash〉 or 〈at-keyword〉 followed by a 〈number〉, 〈percentage〉, 〈ident〉, 〈dimension〉, 〈unicode-range〉, 〈url〉, or a 〈function〉 token;
2740 <li>
2741 〈number〉s, 〈ident〉s, and 〈dimension〉s in any combination;
2743 <li>
2744 a 〈number〉, 〈ident〉, or 〈dimension〉 followed by a 〈percentage〉, 〈unicode-range〉, 〈url〉, or 〈function〉;
2746 <li>
2747 an 〈ident〉 followed by a 〈(〉;
2749 <li>
2750 a 〈delim〉 containing "#" or "@" followed by any token except 〈whitespace〉;
2752 <li>
2753 a 〈delim〉 containing "-", "+", ".", "<", ">", or "!" following or followed by any token except 〈whitespace〉;
2755 <li>
2756 a 〈delim〉 containing "/" following or followed by a 〈delim〉 containing "*".
2757 </ul>
2759 Note: The preceding pairs of tokens can only be adjacent due to comments in the original text,
2760 so the above rule reinserts the minimum number of comments into the serialized text to ensure an accurate round-trip.
2761 (Roughly. The 〈delim〉 rules are slightly too powerful, for simplicity.)
2763 <h3 id='serializing-anb'>
2764 Serializing <var><an+b></var></h3>
2766 To serialize an <var><an+b></var> value,
2767 let <var>s</var> initially be the empty string:
2769 <dl>
2770 <dt><var>A</var> and <var>B</var> are both zero
2771 <dd>
2772 Append "0" to <var>s</var>.
2774 <dt><var>A</var> is zero, <var>B</var> is non-zero
2775 <dd>
2776 Serialize <var>B</var> and append it to <var>s</var>.
2778 <dt><var>A</var> is non-zero, <var>B</var> is zero
2779 <dd>
2780 Serialize <var>A</var> and append it to <var>s</var>.
2781 Append "n" to <var>s</var>.
2783 <dt><var>A</var> and <var>B</var> are both non-zero
2784 <dd>
2785 Serialize <var>A</var> and append it to <var>s</var>.
2786 Append "n" to <var>s</var>.
2787 If <var>B</var> is positive,
2788 append "+" to <var>s</var>
2789 Serialize <var>B</var> and append it to <var>s</var>.
2790 </dl>
2792 Return <var>s</var>.
2794 <h2 id="changes">Changes from CSS 2.1 and Selectors Level 3</h2>
2796 <em>This section is non-normative.</em>
2798 Note: The point of this spec is to match reality;
2799 changes from CSS2.1 are nearly always because CSS 2.1 specified something that doesn't match actual browser behavior,
2800 or left something unspecified.
2801 If some detail doesn't match browsers,
2802 please let me know
2803 as it's almost certainly unintentional.
2805 Changes in decoding from a byte stream:
2807 <ul>
2808 <li>
2809 Only detect ''@charset'' rules in ASCII-compatible byte patterns.
2811 <li>
2812 Ignore ''@charset'' rules that specify an ASCII-incompatible encoding,
2813 as that would cause the rule itself to not decode properly.
2815 <li>
2816 Refer to the the <a href="http://encoding.spec.whatwg.org/">Encoding Standard</a>
2817 rather than the IANA registery for character encodings.
2819 </ul>
2821 Tokenization changes:
2823 <ul>
2824 <li>
2825 Any U+0000 NULL character in the CSS source is replaced with U+FFFD REPLACEMENT CHARACTER.
2827 <li>
2828 Any hexadecimal escape sequence such as ''\0'' that evaluate to zero
2829 produce U+FFFD REPLACEMENT CHARACTER rather than U+0000 NULL.
2830 <!--
2831 This covers a security issue:
2832 https://bugzilla.mozilla.org/show_bug.cgi?id=228856
2833 -->
2835 <li>
2836 The definition of <a>non-ASCII character</a> was changed
2837 to be consistent with every definition of ASCII.
2838 This affects characters U+0080 to U+009F,
2839 which are now <a>name characters</a> rather than 〈delim〉s,
2840 like the rest of <a>non-ASCII characters</a>.
2842 <li>
2843 Tokenization does not emit COMMENT or BAD_COMMENT tokens anymore.
2844 BAD_COMMENT is now considered the same as normal token (not an error.)
2845 <a href="#serialization">Serialization</a> is responsible
2846 for inserting comments as necessary between tokens that need to be separated,
2847 e.g. two consecutive 〈ident〉s.
2849 <li>
2850 The 〈unicode-range〉 token is now more restrictive.
2851 <span class="issue">Should it? I can’t find a case where this change is even testable.</span>
2852 <span class="issue">Align the definition with the Fonts spec.</span>
2854 <li>
2855 Apply the <a href="http://www.w3.org/TR/CSS21/syndata.html#unexpected-eof">EOF error handling rule</a> in the tokenizer
2856 and emit normal 〈string〉 and 〈url〉 tokens rather than BAD_STRING or BAD_URI
2857 on EOF.
2859 <li>
2860 The 〈prefix-match〉, 〈suffix-match〉, and 〈substring-match〉 tokens have been imported from Selectors 3.
2862 <li>
2863 The BAD_URI token (now 〈bad-url〉) is "self-contained".
2864 In other words, once the tokenizer realizes it's in a 〈bad-url〉 rather than a 〈url〉,
2865 it just seeks forward to look for the closing ),
2866 ignoring everything else.
2867 This behavior is simpler than treating it like a 〈function〉
2868 and paying attention to opened blocks and such.
2869 Only WebKit exhibits this behavior,
2870 but it doesn't appear that we've gotten any compat bugs from it.
2872 <li>
2873 The 〈comma〉 has been added.
2875 <li>
2876 The 〈number〉, 〈number〉, and 〈dimension〉 tokens have been changed
2877 to include the preceding +/- sign as part of their value
2878 (rather than as a separate 〈delim〉 that needs to be manually handled every time the token is mentioned in other specs).
2879 The only consequence of this is that comments can no longer be inserted between the sign and the number.
2881 <li>
2882 Scientific notation is supported for numbers/percentages/dimensions to match SVG,
2883 per WG resolution.
2885 <li>
2886 〈column〉 has been added,
2887 to keep Selectors parsing in single-token lookahead.
2889 </ul>
2891 Parsing changes:
2893 <ul>
2894 <li>
2895 Any list of declaration now also accepts at-rules, like ''@page'',
2896 per WG resolution.
2897 This makes a difference in error handling
2898 even if no such at-rules are defined yet:
2899 an at-rule, valid or not, ends and lets the next declaration being
2900 at a {} block without a 〈semicolon〉.
2902 <li>
2903 The handling of some miscellanous "special" tokens
2904 (like an unmatched 〈}〉)
2905 showing up in various places in the grammar
2906 has been specified with some reasonable behavior shown by at least one browser.
2907 Previously, stylesheets with those tokens in those places just didn't match the stylesheet grammar at all,
2908 so their handling was totally undefined.
2909 Specifically:
2911 <ul>
2912 <li>
2913 [] blocks, () blocks and functions can now contain {} blocks, 〈at-keyword〉s or 〈semicolon〉s
2915 <li>
2916 Qualified rule preludes can now contain semicolons
2918 <li>
2919 Qualified rule and at-rule preludes can now contain 〈at-keyword〉s
2920 </ul>
2922 </ul>
2924 <var>An+B</var> changes from Selectors Level 3 [[SELECT]]:
2926 <ul>
2927 <li>
2928 The <var>An+B</var> microsyntax has now been formally defined in terms of CSS tokens,
2929 rather than with a separate tokenizer.
2930 This has resulted in minor differences:
2932 <ul>
2933 <li>
2934 In some cases, "-" characters or digits can be escaped
2935 (when they appear as part of the unit of a 〈dimension〉 or 〈ident〉).
2936 </ul>
2937 </ul>
2939 <h2 class=no-num id="acknowledgments">
2940 Acknowledgments</h2>
2942 <p>
2943 Thanks for feedback and contributions from
2944 David Baron,
2945 呂康豪 (Kang-Hao Lu),
2946 and Marc O'Morain.