Skip to content

Commit eab6ac4

Browse files
committed
[css-values-4][css-syntax-3] Consolidate valdef syntax definition.
1 parent 5aa57c8 commit eab6ac4

File tree

2 files changed

+47
-79
lines changed

2 files changed

+47
-79
lines changed

css-syntax-3/Overview.bs

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,30 @@ Error Handling</h3>
230230
and seek forward until it finds a semicolon (or the end of the block).
231231
It then starts fresh, trying to parse a declaration again.
232232

233-
<li>
233+
<li id=autoclosing>
234234
If the stylesheet ends while any rule, declaration, function, string, etc. are still open,
235235
everything is automatically closed.
236236
This doesn't make them invalid,
237237
though they may be incomplete
238238
and thus thrown away when they are verified against their grammar.
239+
240+
<div class='example'>
241+
For example, the syntax of the ''translateX()'' function is:
242+
243+
<pre>translateX( <<translation-value>> )</pre>
244+
245+
However, the stylesheet may end with the function unclosed, like:
246+
247+
<pre>.foo { transform: translate(50px</pre>
248+
249+
The CSS parser parses this as a style rule containing one declaration,
250+
whose value is a function named "translate".
251+
This matches the above grammar,
252+
even though the ending token didn't appear in the token stream,
253+
because by the time the parser is finished,
254+
the presence of the ending token is no longer possible to determine;
255+
all you have is the fact that there's a block and a function.
256+
</div>
239257
</ul>
240258

241259
After each construct (declaration, style rule, at-rule) is parsed,
@@ -3444,67 +3462,7 @@ The <code>&lt;an+b></code> type</h3>
34443462
<h2 id='rule-defs'>
34453463
Defining Grammars for Rules and Other Values</h2>
34463464

3447-
[[css-values-4#value-defs]] defines how to specify a grammar for properties.
3448-
This section extends those definitions
3449-
to also allow specifying a grammar for rules.
3450-
3451-
Non-terminals representing the entire grammar of an [=at-rule=]
3452-
are written as an @ character followed by the at-rule's name,
3453-
between <css>&lt;</css> and <css>></css>,
3454-
e.g. <<@media>> to represent the ''@media'' rule.
3455-
3456-
The [[css-values-4#numeric-ranges|bracketed range notation]] can be used on
3457-
any of the numeric token non-terminals.
3458-
3459-
Several types of tokens are written literally, without quotes:
3460-
3461-
<ul>
3462-
<li><<ident-token>>s (such as <code>auto</code>, <code>disc</code>, etc), which are simply written as their value.
3463-
<li><<at-keyword-token>>s, which are written as an @ character followed by the token's value, like <code>@media</code>.
3464-
<li><<function-token>>s, which are written as the function name followed by a ( character, like <code>translate(</code>.
3465-
<li>The <<colon-token>> (written as <code>:</code>), <<comma-token>> (written as <code>,</code>), <<semicolon-token>> (written as <code>;</code>), <a href="#tokendef-open-paren">&lt;(-token></a>, <a href="#tokendef-close-paren">&lt;)-token></a>, <a href="#tokendef-open-curly">&lt;{-token></a>, and <a href="#tokendef-close-curly">&lt;}-token></a>s.
3466-
</ul>
3467-
3468-
Tokens match if their value is a match for the value defined in the grammar.
3469-
Unless otherwise specified, all matches are <a>ASCII case-insensitive</a>.
3470-
3471-
Note: Although it is possible, with <a>escaping</a>,
3472-
to construct an <<ident-token>> whose value ends with <code>(</code> or starts with <code>@</code>,
3473-
such a tokens is not a <<function-token>> or an <<at-keyword-token>>
3474-
and does not match corresponding grammar definitions.
3475-
3476-
<<delim-token>>s are written with their value enclosed in single quotes.
3477-
For example, a <<delim-token>> containing the "+" <a>code point</a> is written as <code>'+'</code>.
3478-
Similarly, the <a href="#tokendef-open-square">&lt;[-token></a> and <a href="#tokendef-close-square">&lt;]-token></a>s must be written in single quotes,
3479-
as they're used by the syntax of the grammar itself to group clauses.
3480-
<<whitespace-token>> is never indicated in the grammar;
3481-
<<whitespace-token>>s are allowed before, after, and between any two tokens,
3482-
unless explicitly specified otherwise in prose definitions.
3483-
(For example, if the prelude of a rule is a selector,
3484-
whitespace is significant.)
3485-
3486-
When defining a function or a block,
3487-
the ending token must be specified in the grammar,
3488-
but if it's not present in the eventual token stream,
3489-
it still matches.
3490-
3491-
<div class='example'>
3492-
For example, the syntax of the ''translateX()'' function is:
3493-
3494-
<pre>translateX( <<translation-value>> )</pre>
3495-
3496-
However, the stylesheet may end with the function unclosed, like:
3497-
3498-
<pre>.foo { transform: translate(50px</pre>
3499-
3500-
The CSS parser parses this as a style rule containing one declaration,
3501-
whose value is a function named "translate".
3502-
This matches the above grammar,
3503-
even though the ending token didn't appear in the token stream,
3504-
because by the time the parser is finished,
3505-
the presence of the ending token is no longer possible to determine;
3506-
all you have is the fact that there's a block and a function.
3507-
</div>
3465+
[[css-values-4#value-defs]] defines how to specify a grammar for properties and other CSS syntactic constructions.
35083466

35093467
<h3 id='block-contents'>
35103468
Defining Block Contents: the <<block-contents>>, <<declaration-list>>, <<qualified-rule-list>>, <<declaration-rule-list>>, and <<rule-list>> productions</h3>

css-values-4/Overview.bs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,17 @@ Component Value Types</h3>
116116

117117
Component value types are designated in several ways:
118118

119-
1. <a href="#keywords">Keyword</a> values (such as <css>auto</css>, ''disc'', etc.),
120-
which appear literally, without quotes (e.g. <code>auto</code>).
119+
1. <a href="#keywords">Keyword</a> values (such as <code>auto</code>, ''disc'', etc.)
120+
and at-keywords representing the start of an [=at-rule=],
121+
which appear literally, without quotes (e.g. <code>auto</code> or <code>@media</code>).
122+
123+
Note: It is possible, with <a spec=css-syntax-3>escaping</a>, to construct a [=CSS identifier=]
124+
whose value ends with <code>(</code> or starts with <code>@</code>.
125+
Such a token is an <<ident-token>> (i.e. a [=keyword=]),
126+
not a <<function-token>> or an <<at-keyword-token>>.
121127

122128
2. Basic data types,
123-
which appear between <css>&lt;</css> and <css>></css>
129+
which appear between <code>&lt;</code> and <code>></code>
124130
(e.g., <<length>>, <<percentage>>, etc.).
125131
For <a>numeric data types</a>,
126132
this type notation can annotate any range restrictions
@@ -130,7 +136,7 @@ Component Value Types</h3>
130136
which represent the same pattern of values as a property bearing the same name.
131137
These are written as the property name,
132138
surrounded by single quotes,
133-
between <css>&lt;</css> and <css>></css>,
139+
between <code>&lt;</code> and <code>></code>,
134140
e.g., <<'border-width'>>, <<'background-attachment'>>, etc.
135141

136142
These types <em>do not</em> include <a href="#common-keywords">CSS-wide keywords</a> such as ''inherit''.
@@ -139,9 +145,9 @@ Component Value Types</h3>
139145
is a <a lt=# grammar>comma-separated repetition</a>,
140146
the corresponding type
141147
does not include the top-level <a lt=# grammar>comma-separated list multiplier</a>.
142-
(E.g. if a property named <css>pairing</css> is defined as <css>[ <<custom-ident>> <<integer>>? ]#</css>,
143-
then <css>&lt;\'pairing'></css> is equivalent to <css>[ <<custom-ident>> <<integer>>? ]</css>,
144-
not <css>[ <<custom-ident>> <<integer>>? ]#</css>.)\
148+
(E.g. if a property named <code>pairing</code> is defined as <code>[ <<custom-ident>> <<integer>>? ]#</code>,
149+
then <code>&lt;\'pairing'></code> is equivalent to <code>[ <<custom-ident>> <<integer>>? ]</code>,
150+
not <code>[ <<custom-ident>> <<integer>>? ]#</code>.)\
145151

146152
<details class=note>
147153
<summary>Why remove the multiplier?</summary>
@@ -160,28 +166,32 @@ Component Value Types</h3>
160166
</details>
161167

162168
4. Functional notations and their arguments.
163-
These are written as the function's name,
169+
These may be written literally as defined in [[#component-functions]],
170+
or referenced by a non-terminal using the function's name,
164171
followed by an empty parentheses pair,
165-
between <css>&lt;</css> and <css>></css>,
172+
between <code>&lt;</code> and <code>></code>,
166173
e.g. <<calc()>>,
167174
and references the correspondingly-named [=functional notation=].
168175

169176
5. Other non-terminals.
170177
These are written as the name of the non-terminal
171-
between <css>&lt;</css> and <css>></css>,
178+
between <code>&lt;</code> and <code>></code>,
172179
as in <<spacing-limit>>.
173180
Notice the distinction between <<border-width>> and <<'border-width'>>:
174181
the latter represents the grammar of the 'border-width' property,
175182
the former requires an explicit expansion elsewhere.
176183
The definition of a non-terminal is typically located near its first appearance in the specification.
177184

178-
Some property value definitions also include the slash (/),
179-
the comma (,),
180-
and/or parentheses as literals.
181-
These represent their corresponding tokens.
182-
Other non-keyword literal characters that may appear in a component value,
183-
such as “+”,
184-
must be written enclosed in single quotes.
185+
6. Delimiters, which represent their corresponding tokens.
186+
Slashes (<code>/</code>),
187+
<a lt="," grammar>commas</a> (<code>,</code>),
188+
colons (<code>:</code>),
189+
semicolons (<code>;</code>),
190+
parentheses (<code>(</code> and <code>)</code>),
191+
and braces (<code>{</code> and <code>}</code>)
192+
are written literally.
193+
Other delimiters must be written enclosed in single quotes
194+
(such as <code>'+'</code>).
185195

186196
<strong><dfn lt="," id='comb-comma' export grammar>Commas</dfn> specified in the grammar are implicitly omissible</strong> in some circumstances,
187197
when used to separate optional terms in the grammar.

0 commit comments

Comments
 (0)