You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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.
<<delim-token>> has a value composed of a single <a>code point</a>.
492
492
493
493
<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
+
495
498
<<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.
496
499
<<dimension-token>> additionally have a unit composed of one or more <a>code points</a>.
497
500
@@ -927,34 +930,6 @@ Definitions</h3>
927
930
the part of a <<function-token>> before the "(",
928
931
and the unit of a <<dimension-token>>
929
932
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.
958
933
</dl>
959
934
960
935
<!--
@@ -1217,7 +1192,7 @@ Consume a numeric token</h4>
1217
1192
then:
1218
1193
1219
1194
<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|,
1221
1196
and a unit set initially to the empty string.
1222
1197
1223
1198
<li><a>Consume an ident sequence</a>.
@@ -1229,11 +1204,11 @@ Consume a numeric token</h4>
1229
1204
Otherwise,
1230
1205
if the <a>next input code point</a> is U+0025 PERCENTAGE SIGN (%),
1231
1206
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|,
1233
1208
and return it.
1234
1209
1235
1210
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|,
1237
1212
and return it.
1238
1213
1239
1214
@@ -1612,7 +1587,8 @@ Consume a number</h4>
1612
1587
1613
1588
This section describes how to <dfn>consume a number</dfn> from a stream of <a>code points</a>.
1614
1589
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.
1616
1592
1617
1593
Note: This algorithm does not do the verification of the first few <a>code points</a>
1618
1594
that are necessary to ensure a number can be obtained from the stream.
@@ -1623,27 +1599,29 @@ Consume a number</h4>
1623
1599
1624
1600
<ol>
1625
1601
<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.
1628
1605
1629
1606
<li>
1630
1607
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.
1632
1611
1633
1612
<li>
1634
1613
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|.
1636
1615
1637
1616
<li>
1638
1617
If the <a lt="next input code point">next 2 input code points</a> are
1639
1618
U+002E FULL STOP (.) followed by a <a>digit</a>,
1640
1619
then:
1641
1620
1642
1621
<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".
1647
1625
</ol>
1648
1626
1649
1627
<li>
@@ -1654,77 +1632,27 @@ Consume a number</h4>
1654
1632
then:
1655
1633
1656
1634
<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".
1661
1640
</ol>
1662
1641
1663
1642
<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.
1671
1645
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.
1674
1651
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|.
1724
1654
</ol>
1725
1655
1726
-
Return the number <code>s·(i + f·10<sup>-d</sup>)·10<sup>te</sup></code>.
1727
-
1728
1656
1729
1657
<h4 id="consume-unicode-range-token">
1730
1658
Consume a unicode-range token</h4>
@@ -3278,8 +3206,8 @@ The <code><an+b></code> type</h3>
3278
3206
<li><dfn><code><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>
3279
3207
<li><dfn><code><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>
3280
3208
<li><dfn><code><integer></code></dfn> is a <<number-token>> with its type flag set to "integer"
3281
-
<li><dfn><code><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><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><signed-integer></code></dfn> is a <<number-token>> with its type flag set to "integer", and a sign character
3210
+
<li><dfn><code><signless-integer></code></dfn> is a <<number-token>> with its type flag set to "integer", and no sign character
3283
3211
</ul>
3284
3212
3285
3213
<p id="anb-plus">
@@ -3912,7 +3840,7 @@ Changes from the 20 February 2014 Candidate Recommendation</h3>
3912
3840
3913
3841
* Don't serialize the digit in an <<an+b>> when A is 1 or -1.
3914
3842
3915
-
* Define all tokens to have a <a>representation</a>.
3843
+
* Define all tokens to have a representation.
3916
3844
3917
3845
* Fixed minor bug in <a>check if two code points are a valid escape</a>--
3918
3846
a <code>\</code> followed by an EOF is now correctly reported as <em>not</em> a valid escape.
0 commit comments