Skip to content

Commit 3560680

Browse files
committed
[css-syntax-3][editorial] Remove the concept of 'representation' from number tokens, now that urange doesn't need it. Record whether a number had a sign, instead.
1 parent afaa732 commit 3560680

File tree

1 file changed

+36
-108
lines changed

1 file changed

+36
-108
lines changed

css-syntax-3/Overview.bs

Lines changed: 36 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,10 @@ Tokenization</h2>
491491
<<delim-token>> has a value composed of a single <a>code point</a>.
492492

493493
<li>
494-
<<number-token>>, <<percentage-token>>, and <<dimension-token>> have a numeric value.
494+
<<number-token>>, <<percentage-token>>, and <<dimension-token>> have a numeric value,
495+
and an optional sign character
496+
set to either "+" or "-" (or nothing).
497+
495498
<<number-token>> and <<dimension-token>> additionally have a type flag set to either "integer" or "number". The type flag defaults to "integer" if not otherwise set.
496499
<<dimension-token>> additionally have a unit composed of one or more <a>code points</a>.
497500

@@ -927,34 +930,6 @@ Definitions</h3>
927930
the part of a <<function-token>> before the "(",
928931
and the unit of a <<dimension-token>>
929932
are all [=ident sequences=].
930-
931-
<dt><dfn>representation</dfn>
932-
<dd>
933-
The <a>representation</a> of a token
934-
is the subsequence of the <a>input stream</a>
935-
consumed by the invocation of the [=tokenizer/consume a token=] algorithm
936-
that produced it.
937-
This is preserved for a few algorithms that rely on subtle details of the input text,
938-
which a simple "re-serialization" of the tokens might disturb.
939-
940-
The <a>representation</a> is only consumed by internal algorithms,
941-
and never directly exposed,
942-
so it's not actually required to preserve the exact text;
943-
equivalent methods,
944-
such as associating each token with offsets into the source text,
945-
also suffice.
946-
947-
Note: In particular, the <a>representation</a> preserves details
948-
such as whether .009 was written as ''.009'' or ''9e-3'',
949-
and whether a character was written literally
950-
or as a CSS escape.
951-
The former is necessary to properly parse <<urange>> productions;
952-
the latter is basically an accidental leak of the tokenizing abstraction,
953-
but allowed because it makes the impl easier to define.
954-
955-
If a token is ever produced by an algorithm directly,
956-
rather than thru the tokenization algorithm in this specification,
957-
its representation is the empty string.
958933
</dl>
959934

960935
<!--
@@ -1217,7 +1192,7 @@ Consume a numeric token</h4>
12171192
then:
12181193

12191194
<ol>
1220-
<li>Create a <<dimension-token>> with the same value and type flag as |number|,
1195+
<li>Create a <<dimension-token>> with the same value, type flag, and sign character as |number|,
12211196
and a unit set initially to the empty string.
12221197

12231198
<li><a>Consume an ident sequence</a>.
@@ -1229,11 +1204,11 @@ Consume a numeric token</h4>
12291204
Otherwise,
12301205
if the <a>next input code point</a> is U+0025 PERCENTAGE SIGN (%),
12311206
consume it.
1232-
Create a <<percentage-token>> with the same value as |number|,
1207+
Create a <<percentage-token>> with the same value and sign character as |number|,
12331208
and return it.
12341209

12351210
Otherwise,
1236-
create a <<number-token>> with the same value and type flag as |number|,
1211+
create a <<number-token>> with the same value, type flag, and sign character as |number|,
12371212
and return it.
12381213

12391214

@@ -1612,7 +1587,8 @@ Consume a number</h4>
16121587

16131588
This section describes how to <dfn>consume a number</dfn> from a stream of <a>code points</a>.
16141589
It returns a numeric |value|,
1615-
and a |type| which is either "integer" or "number".
1590+
a string |type| which is either "integer" or "number",
1591+
and an optional |sign character| which is either "+", "-", or missing.
16161592

16171593
Note: This algorithm does not do the verification of the first few <a>code points</a>
16181594
that are necessary to ensure a number can be obtained from the stream.
@@ -1623,27 +1599,29 @@ Consume a number</h4>
16231599

16241600
<ol>
16251601
<li>
1626-
Initially set <var>type</var> to "integer".
1627-
Let |repr| be the empty string.
1602+
Let |type| be the string "integer".
1603+
Let |number part|
1604+
and |exponent part| be the empty string.
16281605

16291606
<li>
16301607
If the <a>next input code point</a> is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
1631-
consume it and append it to <var>repr</var>.
1608+
consume it.
1609+
Append it to |number part|
1610+
and set |sign character| to it.
16321611

16331612
<li>
16341613
While the <a>next input code point</a> is a <a>digit</a>,
1635-
consume it and append it to <var>repr</var>.
1614+
consume it and append it to |number part|.
16361615

16371616
<li>
16381617
If the <a lt="next input code point">next 2 input code points</a> are
16391618
U+002E FULL STOP (.) followed by a <a>digit</a>,
16401619
then:
16411620

16421621
<ol>
1643-
<li>Consume them.
1644-
<li>Append them to <var>repr</var>.
1645-
<li>Set <var>type</var> to "number".
1646-
<li>While the <a>next input code point</a> is a <a>digit</a>, consume it and append it to <var>repr</var>.
1622+
<li>Consume the [=next input code point=] and append it to |number part|.
1623+
<li>While the <a>next input code point</a> is a <a>digit</a>, consume it and append it to |number part|.
1624+
<li>Set |type| to "number".
16471625
</ol>
16481626

16491627
<li>
@@ -1654,77 +1632,27 @@ Consume a number</h4>
16541632
then:
16551633

16561634
<ol>
1657-
<li>Consume them.
1658-
<li>Append them to <var>repr</var>.
1659-
<li>Set <var>type</var> to "number".
1660-
<li>While the <a>next input code point</a> is a <a>digit</a>, consume it and append it to <var>repr</var>.
1635+
<li>Consume the [=next input code point=].
1636+
<li>If the [=next input code point=] is "+" or "-",
1637+
consume it and append it to |exponent part|.
1638+
<li>While the <a>next input code point</a> is a <a>digit</a>, consume it and append it to |exponent part|.
1639+
<li>Set |type| to "number".
16611640
</ol>
16621641

16631642
<li>
1664-
<a lt="convert a string to a number">Convert <var>repr</var> to a number</a>,
1665-
and set the <var>value</var> to the returned value.
1666-
1667-
<li>
1668-
Return <var>value</var> and <var>type</var>.
1669-
</ol>
1670-
1643+
Let |value| be the result of interpreting |number part|
1644+
as a base-10 number.
16711645

1672-
<h4 id="convert-string-to-number">
1673-
Convert a string to a number</h4>
1646+
If |exponent part| is non-empty,
1647+
interpret it as a base-10 integer,
1648+
then raise 10 to the power of the result,
1649+
multiply it by |value|,
1650+
and set |value| to that result.
16741651

1675-
This section describes how to <dfn>convert a string to a number</dfn>.
1676-
It returns a number.
1677-
1678-
Note: This algorithm does not do any verification to ensure that the string contains only a number.
1679-
Ensure that the string contains only a valid CSS number
1680-
before calling this algorithm.
1681-
1682-
Divide the string into seven components,
1683-
in order from left to right:
1684-
1685-
<ol>
1686-
<li>A <b>sign</b>:
1687-
a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
1688-
or the empty string.
1689-
Let <var>s</var> be the number -1 if the sign is U+002D HYPHEN-MINUS (-);
1690-
otherwise, let <var>s</var> be the number 1.
1691-
1692-
<li>An <b>integer part</b>:
1693-
zero or more <a>digits</a>.
1694-
If there is at least one digit,
1695-
let <var>i</var> be the number formed by interpreting the digits as a base-10 integer;
1696-
otherwise, let <var>i</var> be the number 0.
1697-
1698-
<li>A <b>decimal point</b>:
1699-
a single U+002E FULL STOP (.),
1700-
or the empty string.
1701-
1702-
<li>A <b>fractional part</b>:
1703-
zero or more <a>digits</a>.
1704-
If there is at least one digit,
1705-
let <var>f</var> be the number formed by interpreting the digits as a base-10 integer
1706-
and <var>d</var> be the number of digits;
1707-
otherwise, let <var>f</var> and <var>d</var> be the number 0.
1708-
1709-
<li>An <b>exponent indicator</b>:
1710-
a single U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e),
1711-
or the empty string.
1712-
1713-
<li>An <b>exponent sign</b>:
1714-
a single U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-),
1715-
or the empty string.
1716-
Let <var>t</var> be the number -1 if the sign is U+002D HYPHEN-MINUS (-);
1717-
otherwise, let <var>t</var> be the number 1.
1718-
1719-
<li>An <b>exponent</b>:
1720-
zero or more <a>digits</a>.
1721-
If there is at least one digit,
1722-
let <var>e</var> be the number formed by interpreting the digits as a base-10 integer;
1723-
otherwise, let <var>e</var> be the number 0.
1652+
<li>
1653+
Return |value|, |type|, and |sign character|.
17241654
</ol>
17251655

1726-
Return the number <code>s·(i + f·10<sup>-d</sup>)·10<sup>te</sup></code>.
1727-
17281656

17291657
<h4 id="consume-unicode-range-token">
17301658
Consume a unicode-range token</h4>
@@ -3278,8 +3206,8 @@ The <code>&lt;an+b></code> type</h3>
32783206
<li><dfn><code>&lt;ndashdigit-ident></code></dfn> is an <<ident-token>> whose value is an <a>ASCII case-insensitive</a> match for "n-*", where "*" is a series of one or more <a>digits</a>
32793207
<li><dfn><code>&lt;dashndashdigit-ident></code></dfn> is an <<ident-token>> whose value is an <a>ASCII case-insensitive</a> match for "-n-*", where "*" is a series of one or more <a>digits</a>
32803208
<li><dfn><code>&lt;integer></code></dfn> is a <<number-token>> with its type flag set to "integer"
3281-
<li><dfn><code>&lt;signed-integer></code></dfn> is a <<number-token>> with its type flag set to "integer", and whose <a>representation</a> starts with "+" or "-"
3282-
<li><dfn><code>&lt;signless-integer></code></dfn> is a <<number-token>> with its type flag set to "integer", and whose <a>representation</a> starts with a <a>digit</a>
3209+
<li><dfn><code>&lt;signed-integer></code></dfn> is a <<number-token>> with its type flag set to "integer", and a sign character
3210+
<li><dfn><code>&lt;signless-integer></code></dfn> is a <<number-token>> with its type flag set to "integer", and no sign character
32833211
</ul>
32843212

32853213
<p id="anb-plus">
@@ -3912,7 +3840,7 @@ Changes from the 20 February 2014 Candidate Recommendation</h3>
39123840

39133841
* Don't serialize the digit in an <<an+b>> when A is 1 or -1.
39143842

3915-
* Define all tokens to have a <a>representation</a>.
3843+
* Define all tokens to have a representation.
39163844

39173845
* Fixed minor bug in <a>check if two code points are a valid escape</a>--
39183846
a <code>\</code> followed by an EOF is now correctly reported as <em>not</em> a valid escape.

0 commit comments

Comments
 (0)