Skip to content

Commit f7d21ea

Browse files
committed
[selectors] Fix the grammar.
--HG-- extra : rebase_source : 9359cd357ed47d98e1e58ae4798676c3e56c1900
1 parent dc8253b commit f7d21ea

2 files changed

Lines changed: 117 additions & 303 deletions

File tree

selectors/Overview.html

Lines changed: 61 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,6 @@ <h2 class="no-num no-toc" id=contents>Table of Contents</h2>
441441
Syntax</a>
442442
<ul class=toc>
443443
<li><a href="#grammar"><span class=secno>16.1. </span> Grammar</a>
444-
445-
<li><a href="#lex"><span class=secno>16.2. </span> Lexical scanner</a>
446444
</ul>
447445

448446
<li><a href="#profiling"><span class=secno>17. </span> Profiles</a>
@@ -3814,15 +3812,15 @@ <h2 id=specificity><span class=secno>15. </span> Calculating a selector's
38143812

38153813
<h2 id=formal-syntax><span class=secno>16. </span> Formal Syntax</h2>
38163814

3817-
<p class=issue>This section needs to be updated.
3818-
38193815
<h3 id=grammar><span class=secno>16.1. </span> Grammar</h3>
38203816

3821-
<p>The grammar below defines the syntax of Selectors. It is globally LL(1)
3822-
and can be locally LL(2) (but note that most UAs should not use it
3823-
directly, since it doesn't express the parsing conventions). The format of
3824-
the productions is optimized for human consumption and some shorthand
3825-
notations beyond Yacc (see <a href="#YACC"
3817+
<p> The grammar below defines the syntax of Selectors. It is applied to a
3818+
stream of tokens, as returned by the tokenizer defined in <a
3819+
href="#CSS3SYN" rel=biblioentry>[CSS3SYN]<!--{{!CSS3SYN}}--></a>. It is
3820+
globally LL(1) and can be locally LL(2) (but note that most UAs should not
3821+
use it directly, since it doesn't express the parsing conventions). The
3822+
format of the productions is optimized for human consumption and some
3823+
shorthand notations beyond Yacc (see <a href="#YACC"
38263824
rel=biblioentry>[YACC]<!--{{!YACC}}--></a>) are used:
38273825

38283826
<ul>
@@ -3837,59 +3835,80 @@ <h3 id=grammar><span class=secno>16.1. </span> Grammar</h3>
38373835
<li><b>[ ]</b>: grouping
38383836
</ul>
38393837

3838+
<p> The productions in uppercase are defined by CSS Syntax <a
3839+
href="#CSS3SYN" rel=biblioentry>[CSS3SYN]<!--{{!CSS3SYN}}--></a>, and
3840+
correspond to the tokens of the same name. Literal strings correspond to
3841+
delim tokens with the given value. The production "S" represents a
3842+
whitespace token. The wqname_prefix production comes from the Namespaces
3843+
spec <a href="#CSS3NAMESPACE"
3844+
rel=biblioentry>[CSS3NAMESPACE]<!--{{!CSS3NAMESPACE}}--></a> The
3845+
38403846
<p>The productions are:
38413847

38423848
<pre>
3843-
selectors_group
3844-
: selector [ COMMA S* selector ]*
3849+
complex_selector_list
3850+
: complex_selector [ COMMA S* complex_selector ]*
38453851
;
38463852

3847-
selector
3848-
: compound_selector [ combinator simple_selector_sequence ]*
3853+
complex_selector
3854+
: compound_selector [ combinator compound_selector ]* S*
38493855
;
38503856

38513857
combinator
38523858
/* combinators can be surrounded by whitespace */
3853-
: PLUS S* | GREATER S* | TILDE S* | S+
3859+
: S+ | S* [ '>' | '+' | '~' | COLUMN | '/' IDENT '/' ] S*
38543860
;
38553861

3856-
simple_selector_sequence
3857-
: [ type_selector | universal ]
3858-
[ HASH | class | attrib | pseudo | negation ]*
3859-
| [ HASH | class | attrib | pseudo | negation ]+
3860-
;
3862+
compound_selector_list
3863+
: compound_selector S* [ COMMA S* compound_selector ]* S*
38613864

3862-
type_selector
3863-
: [ namespace_prefix ]? element_name
3865+
compound_selector
3866+
: type_selector [ id | class | attrib | pseudo ]*
3867+
| [ id | class | attrib | pseudo ]+
38643868
;
38653869

3866-
namespace_prefix
3867-
: [ IDENT | '*' ]? '|'
3870+
simple_selector_list
3871+
: simple_selector S* [ COMMA S* simple_selector ] S*
3872+
3873+
simple_selector
3874+
: type_selector | id | class | attrib | pseudo
3875+
3876+
type_selector
3877+
: wqname_prefix? element_name
38683878
;
38693879

38703880
element_name
3871-
: IDENT
3881+
: IDENT | '*'
38723882
;
38733883

3874-
universal
3875-
: [ namespace_prefix ]? '*'
3884+
id
3885+
: HASH
38763886
;
38773887

38783888
class
38793889
: '.' IDENT
38803890
;
38813891

38823892
attrib
3883-
: '[' S* [ namespace_prefix ]? IDENT S*
3884-
[ [ PREFIXMATCH |
3885-
SUFFIXMATCH |
3886-
SUBSTRINGMATCH |
3887-
'=' |
3888-
INCLUDES |
3889-
DASHMATCH ] S* [ IDENT | STRING ] S* [IDENT S*]?
3890-
]? ']'
3893+
: '[' S* attrib_name ']'
3894+
| '[' S* attrib_name attrib_match [ IDENT | STRING ] S* attrib_flags? ']'
38913895
;
38923896

3897+
attrib_name
3898+
: wqname_prefix? IDENT S*
3899+
3900+
attrib_match
3901+
: [ '=' |
3902+
PREFIX-MATCH |
3903+
SUFFIX-MATCH |
3904+
SUBSTRING-MATCH |
3905+
INCLUDE-MATCH |
3906+
DASH-MATCH
3907+
] S*
3908+
3909+
attrib_flags
3910+
: IDENT S*
3911+
38933912
pseudo
38943913
/* '::' starts a pseudo-element, ':' a pseudo-class */
38953914
/* Exceptions: :first-line, :first-letter, :before and :after. */
@@ -3899,146 +3918,9 @@ <h3 id=grammar><span class=secno>16.1. </span> Grammar</h3>
38993918
;
39003919

39013920
functional_pseudo
3902-
: FUNCTION S* expression ')'
3903-
;
3904-
3905-
expression
3906-
/* In CSS3, the expressions are identifiers, strings, */
3907-
/* or of the form "an+b" */
3908-
: [ [ PLUS | '-' | DIMENSION | NUMBER | STRING | IDENT ] S* ]+
3909-
;
3910-
3911-
negation
3912-
: NOT S* negation_arg S* ')'
3913-
;
3914-
3915-
negation_arg
3916-
: type_selector | universal | HASH | class | attrib | pseudo
3921+
: FUNCTION S* value ')'
39173922
;</pre>
39183923

3919-
<h3 id=lex><span class=secno>16.2. </span> Lexical scanner</h3>
3920-
3921-
<p>The following is the tokenizer, written in Flex (see <a href="#FLEX"
3922-
rel=biblioentry>[FLEX]<!--{{!FLEX}}--></a>) notation. The tokenizer is
3923-
case-insensitive.
3924-
3925-
<p>The two occurrences of "\377" represent the highest character number
3926-
that current versions of Flex can deal with (decimal 255). They should be
3927-
read as "\4177777" (decimal 1114111), which is the highest possible code
3928-
point in Unicode/ISO-10646. <a href="#UNICODE"
3929-
rel=biblioentry>[UNICODE]<!--{{!UNICODE}}--></a>
3930-
3931-
<pre><!--
3932-
-->%option case-insensitive
3933-
<!--
3934-
-->
3935-
<!--
3936-
-->ident [-]?{nmstart}{nmchar}*
3937-
<!--
3938-
-->name {nmchar}+
3939-
<!--
3940-
-->nmstart [_a-z]|{nonascii}|{escape}
3941-
<!--
3942-
-->nonascii [^\0-\177]
3943-
<!--
3944-
-->unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
3945-
<!--
3946-
-->escape {unicode}|\\[^\n\r\f0-9a-f]
3947-
<!--
3948-
-->nmchar [_a-z0-9-]|{nonascii}|{escape}
3949-
<!--
3950-
-->num [0-9]+|[0-9]*\.[0-9]+
3951-
<!--
3952-
-->string {string1}|{string2}
3953-
<!--
3954-
-->string1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*\"
3955-
<!--
3956-
-->string2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*\'
3957-
<!--
3958-
-->invalid {invalid1}|{invalid2}
3959-
<!--
3960-
-->invalid1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*
3961-
<!--
3962-
-->invalid2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*
3963-
<!--
3964-
-->nl \n|\r\n|\r|\f
3965-
<!--
3966-
-->w [ \t\r\n\f]*
3967-
<!--
3968-
-->
3969-
<!--
3970-
-->D d|\\0{0,4}(44|64)(\r\n|[ \t\r\n\f])?
3971-
<!--
3972-
-->E e|\\0{0,4}(45|65)(\r\n|[ \t\r\n\f])?
3973-
<!--
3974-
-->N n|\\0{0,4}(4e|6e)(\r\n|[ \t\r\n\f])?|\\n
3975-
<!--
3976-
-->O o|\\0{0,4}(4f|6f)(\r\n|[ \t\r\n\f])?|\\o
3977-
<!--
3978-
-->T t|\\0{0,4}(54|74)(\r\n|[ \t\r\n\f])?|\\t
3979-
<!--
3980-
-->V v|\\0{0,4}(58|78)(\r\n|[ \t\r\n\f])?|\\v
3981-
<!--
3982-
-->
3983-
<!--
3984-
-->%%
3985-
<!--
3986-
-->
3987-
<!--
3988-
-->[ \t\r\n\f]+ return S;
3989-
<!--
3990-
-->
3991-
<!--
3992-
-->"~=" return INCLUDES;
3993-
<!--
3994-
-->"|=" return DASHMATCH;
3995-
<!--
3996-
-->"^=" return PREFIXMATCH;
3997-
<!--
3998-
-->"$=" return SUFFIXMATCH;
3999-
<!--
4000-
-->"*=" return SUBSTRINGMATCH;
4001-
<!--
4002-
-->{ident} return IDENT;
4003-
<!--
4004-
-->{string} return STRING;
4005-
<!--
4006-
-->{ident}"(" return FUNCTION;
4007-
<!--
4008-
-->{num} return NUMBER;
4009-
<!--
4010-
-->"#"{name} return HASH;
4011-
<!--
4012-
-->{w}"+" return PLUS;
4013-
<!--
4014-
-->{w}">" return GREATER;
4015-
<!--
4016-
-->{w}"," return COMMA;
4017-
<!--
4018-
-->{w}"~" return TILDE;
4019-
<!--
4020-
-->":"{N}{O}{T}"(" return NOT;
4021-
<!--
4022-
-->@{ident} return ATKEYWORD;
4023-
<!--
4024-
-->{invalid} return INVALID;
4025-
<!--
4026-
-->{num}% return PERCENTAGE;
4027-
<!--
4028-
-->{num}{ident} return DIMENSION;
4029-
<!--
4030-
-->"&lt;!--" return CDO;
4031-
<!--
4032-
-->"-->" return CDC;
4033-
<!--
4034-
-->
4035-
<!--
4036-
-->\/\*[^*]*\*+([^/*][^*]*\*+)*\/ /* ignore comments */
4037-
<!--
4038-
-->
4039-
<!--
4040-
-->. return *yytext;</pre>
4041-
40423924
<h2 id=profiling><span class=secno>17. </span> Profiles</h2>
40433925

40443926
<p>Each specification using Selectors must define the subset of Selectors
@@ -4324,10 +4206,14 @@ <h3 id=normative-references><span class=secno>20.1. </span> Normative
43244206
</dd>
43254207
<!---->
43264208

4327-
<dt id=FLEX>[FLEX]
4209+
<dt id=CSS3SYN>[CSS3SYN]
43284210

4329-
<dd><cite>Flex: The Lexical Scanner Generator.</cite> Version 2.3.7, ISBN
4330-
1882114213</dd>
4211+
<dd>L. David Baron. <a
4212+
href="http://www.w3.org/TR/2003/WD-css3-syntax-20030813"><cite>CSS3
4213+
module: Syntax.</cite></a> 13 August 2003. W3C Working Draft. (Work in
4214+
progress.) URL: <a
4215+
href="http://www.w3.org/TR/2003/WD-css3-syntax-20030813">http://www.w3.org/TR/2003/WD-css3-syntax-20030813</a>
4216+
</dd>
43314217
<!---->
43324218

43334219
<dt id=RFC2119>[RFC2119]
@@ -4348,18 +4234,6 @@ <h3 id=normative-references><span class=secno>20.1. </span> Normative
43484234
</dd>
43494235
<!---->
43504236

4351-
<dt id=UNICODE>[UNICODE]
4352-
4353-
<dd>The Unicode Consortium. <a
4354-
href="http://www.unicode.org/standard/versions/enumeratedversions.html"><cite>The
4355-
Unicode Standard.</cite></a> 2012. Defined by: The Unicode Standard,
4356-
Version 6.2.0 (Mountain View, CA: The Unicode Consortium, 2012. ISBN
4357-
978-1-936213-07-8), as updated from time to time by the publication of
4358-
new versions URL: <a
4359-
href="http://www.unicode.org/standard/versions/enumeratedversions.html">http://www.unicode.org/standard/versions/enumeratedversions.html</a>
4360-
</dd>
4361-
<!---->
4362-
43634237
<dt id=YACC>[YACC]
43644238

43654239
<dd>S. C. Johnson. <cite>YACC - Yet another compiler compiler.</cite>

0 commit comments

Comments
 (0)