Skip to content

Commit

Permalink
Normative: add NumericLiteralSeparator (#2151)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored and ljharb committed Sep 7, 2020
1 parent ea10997 commit 65d5bcc
Showing 1 changed file with 85 additions and 58 deletions.
143 changes: 85 additions & 58 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -4321,7 +4321,7 @@ <h2>Syntax</h2>

StrNumericLiteral :::
StrDecimalLiteral
NonDecimalIntegerLiteral
NonDecimalIntegerLiteral[~Sep]

StrDecimalLiteral :::
StrUnsignedDecimalLiteral
Expand All @@ -4330,9 +4330,9 @@ <h2>Syntax</h2>

StrUnsignedDecimalLiteral :::
`Infinity`
DecimalDigits `.` DecimalDigits? ExponentPart?
`.` DecimalDigits ExponentPart?
DecimalDigits ExponentPart?
DecimalDigits[~Sep] `.` DecimalDigits[~Sep]? ExponentPart[~Sep]?
`.` DecimalDigits[~Sep] ExponentPart[~Sep]?
DecimalDigits[~Sep] ExponentPart[~Sep]?
</emu-grammar>
<p>All grammar symbols not explicitly defined above have the definitions used in the Lexical Grammar for numeric literals (<emu-xref href="#sec-literals-numeric-literals"></emu-xref>)</p>
<emu-note>
Expand Down Expand Up @@ -10908,83 +10908,92 @@ <h2>Syntax</h2>
<h1>Numeric Literals</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
NumericLiteralSeparator ::
`_`

NumericLiteral ::
DecimalLiteral
DecimalBigIntegerLiteral
NonDecimalIntegerLiteral
NonDecimalIntegerLiteral BigIntLiteralSuffix
NonDecimalIntegerLiteral[+Sep]
NonDecimalIntegerLiteral[+Sep] BigIntLiteralSuffix

DecimalBigIntegerLiteral ::
`0` BigIntLiteralSuffix
NonZeroDigit DecimalDigits? BigIntLiteralSuffix
NonZeroDigit DecimalDigits[+Sep]? BigIntLiteralSuffix
NonZeroDigit NumericLiteralSeparator DecimalDigits[+Sep] BigIntLiteralSuffix

NonDecimalIntegerLiteral ::
BinaryIntegerLiteral
OctalIntegerLiteral
HexIntegerLiteral
NonDecimalIntegerLiteral[Sep] ::
BinaryIntegerLiteral[?Sep]
OctalIntegerLiteral[?Sep]
HexIntegerLiteral[?Sep]

BigIntLiteralSuffix ::
`n`

DecimalLiteral ::
DecimalIntegerLiteral `.` DecimalDigits? ExponentPart?
`.` DecimalDigits ExponentPart?
DecimalIntegerLiteral ExponentPart?
DecimalIntegerLiteral `.` DecimalDigits[+Sep]? ExponentPart[+Sep]?
`.` DecimalDigits[+Sep] ExponentPart[+Sep]?
DecimalIntegerLiteral ExponentPart[+Sep]?

DecimalIntegerLiteral ::
`0`
NonZeroDigit DecimalDigits?
NonZeroDigit
NonZeroDigit NumericLiteralSeparator? DecimalDigits[+Sep]

DecimalDigits ::
DecimalDigits[Sep] ::
DecimalDigit
DecimalDigits DecimalDigit
DecimalDigits[?Sep] DecimalDigit
[+Sep] DecimalDigits[+Sep] NumericLiteralSeparator DecimalDigit

DecimalDigit :: one of
`0` `1` `2` `3` `4` `5` `6` `7` `8` `9`

NonZeroDigit :: one of
`1` `2` `3` `4` `5` `6` `7` `8` `9`

ExponentPart ::
ExponentIndicator SignedInteger
ExponentPart[Sep] ::
ExponentIndicator SignedInteger[?Sep]

ExponentIndicator :: one of
`e` `E`

SignedInteger ::
DecimalDigits
`+` DecimalDigits
`-` DecimalDigits
SignedInteger[Sep] ::
DecimalDigits[?Sep]
`+` DecimalDigits[?Sep]
`-` DecimalDigits[?Sep]

BinaryIntegerLiteral ::
`0b` BinaryDigits
`0B` BinaryDigits
BinaryIntegerLiteral[Sep] ::
`0b` BinaryDigits[?Sep]
`0B` BinaryDigits[?Sep]

BinaryDigits ::
BinaryDigits[Sep] ::
BinaryDigit
BinaryDigits BinaryDigit
BinaryDigits[?Sep] BinaryDigit
[+Sep] BinaryDigits[+Sep] NumericLiteralSeparator BinaryDigit

BinaryDigit :: one of
`0` `1`

OctalIntegerLiteral ::
`0o` OctalDigits
`0O` OctalDigits
OctalIntegerLiteral[Sep] ::
`0o` OctalDigits[?Sep]
`0O` OctalDigits[?Sep]

OctalDigits ::
OctalDigits[Sep] ::
OctalDigit
OctalDigits OctalDigit
OctalDigits[?Sep] OctalDigit
[+Sep] OctalDigits[+Sep] NumericLiteralSeparator OctalDigit

OctalDigit :: one of
`0` `1` `2` `3` `4` `5` `6` `7`

HexIntegerLiteral ::
`0x` HexDigits
`0X` HexDigits
HexIntegerLiteral[Sep] ::
`0x` HexDigits[?Sep]
`0X` HexDigits[?Sep]

HexDigits ::
HexDigits[Sep] ::
HexDigit
HexDigits HexDigit
HexDigits[?Sep] HexDigit
[+Sep] HexDigits[+Sep] NumericLiteralSeparator HexDigit

HexDigit :: one of
`0` `1` `2` `3` `4` `5` `6` `7` `8` `9` `a` `b` `c` `d` `e` `f` `A` `B` `C` `D` `E` `F`
Expand Down Expand Up @@ -11015,19 +11024,19 @@ <h1>Static Semantics: MV</h1>
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral `.`</emu-grammar> is the MV of |DecimalIntegerLiteral|.
</li>
<li>
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral `.` DecimalDigits</emu-grammar> is the MV of |DecimalIntegerLiteral| plus (the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>-<sub>ℝ</sub>_n_</sup>), where _n_ is the mathematical value of the number of code points in |DecimalDigits|.
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral `.` DecimalDigits</emu-grammar> is the MV of |DecimalIntegerLiteral| plus (the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>-<sub>ℝ</sub>_n_</sup>), where _n_ is the mathematical value of the number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
</li>
<li>
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral `.` ExponentPart</emu-grammar> is the MV of |DecimalIntegerLiteral| &times; 10<sub>ℝ</sub><sup>_e_</sup>, where _e_ is the MV of |ExponentPart|.
</li>
<li>
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral `.` DecimalDigits ExponentPart</emu-grammar> is (the MV of |DecimalIntegerLiteral| plus (the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>-<sub>ℝ</sub>_n_</sup>)) &times; 10<sub>ℝ</sub><sup>_e_</sup>, where _n_ is the mathematical integer number of code points in |DecimalDigits| and _e_ is the MV of |ExponentPart|.
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral `.` DecimalDigits ExponentPart</emu-grammar> is (the MV of |DecimalIntegerLiteral| plus (the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>-<sub>ℝ</sub>_n_</sup>)) &times; 10<sub>ℝ</sub><sup>_e_</sup>, where _n_ is the mathematical integer number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|, and _e_ is the MV of |ExponentPart|.
</li>
<li>
The MV of <emu-grammar>DecimalLiteral :: `.` DecimalDigits</emu-grammar> is the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>-<sub>ℝ</sub>_n_</sup>, where _n_ is the mathematical integer number of code points in |DecimalDigits|.
The MV of <emu-grammar>DecimalLiteral :: `.` DecimalDigits</emu-grammar> is the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>-<sub>ℝ</sub>_n_</sup>, where _n_ is the mathematical integer number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
</li>
<li>
The MV of <emu-grammar>DecimalLiteral :: `.` DecimalDigits ExponentPart</emu-grammar> is the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>_e_ -<sub>ℝ</sub> _n_</sup>, where _n_ is the mathematical integer number of code points in |DecimalDigits| and _e_ is the MV of |ExponentPart|.
The MV of <emu-grammar>DecimalLiteral :: `.` DecimalDigits ExponentPart</emu-grammar> is the MV of |DecimalDigits| &times; 10<sub>ℝ</sub><sup>_e_ -<sub>ℝ</sub> _n_</sup>, where _n_ is the mathematical integer number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|, and _e_ is the MV of |ExponentPart|.
</li>
<li>
The MV of <emu-grammar>DecimalLiteral :: DecimalIntegerLiteral</emu-grammar> is the MV of |DecimalIntegerLiteral|.
Expand All @@ -11042,14 +11051,17 @@ <h1>Static Semantics: MV</h1>
The MV of <emu-grammar>DecimalIntegerLiteral :: NonZeroDigit</emu-grammar> is the MV of |NonZeroDigit|.
</li>
<li>
The MV of <emu-grammar>DecimalIntegerLiteral :: NonZeroDigit DecimalDigits</emu-grammar> is (the MV of |NonZeroDigit| &times; 10<sub>ℝ</sub><sup>_n_</sup>) plus the MV of |DecimalDigits|, where _n_ is the mathematical integer number of code points in |DecimalDigits|.
The MV of <emu-grammar>DecimalIntegerLiteral :: NonZeroDigit NumericLiteralSeparator? DecimalDigits</emu-grammar> is (the MV of |NonZeroDigit| &times; 10<sub>ℝ</sub><sup>_n_</sup>) plus the MV of |DecimalDigits|, where _n_ is the mathematical integer number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
</li>
<li>
The MV of <emu-grammar>DecimalDigits :: DecimalDigit</emu-grammar> is the MV of |DecimalDigit|.
</li>
<li>
The MV of <emu-grammar>DecimalDigits :: DecimalDigits DecimalDigit</emu-grammar> is (the MV of |DecimalDigits| &times; 10<sub>ℝ</sub>) plus the MV of |DecimalDigit|.
</li>
<li>
The MV of <emu-grammar>DecimalDigits :: DecimalDigits NumericLiteralSeparator DecimalDigit</emu-grammar> is (the MV of |DecimalDigits| &times; 10<sub>ℝ</sub>) plus the MV of |DecimalDigit|.
</li>
<li>
The MV of <emu-grammar>ExponentPart :: ExponentIndicator SignedInteger</emu-grammar> is the MV of |SignedInteger|.
</li>
Expand Down Expand Up @@ -11122,6 +11134,9 @@ <h1>Static Semantics: MV</h1>
<li>
The MV of <emu-grammar>BinaryDigits :: BinaryDigits BinaryDigit</emu-grammar> is (the MV of |BinaryDigits| &times; 2<sub>ℝ</sub>) plus the MV of |BinaryDigit|.
</li>
<li>
The MV of <emu-grammar>BinaryDigits :: BinaryDigits NumericLiteralSeparator BinaryDigit</emu-grammar> is (the MV of |BinaryDigits| &times; 2<sub>ℝ</sub>) plus the MV of |BinaryDigit|.
</li>
<li>
The MV of <emu-grammar>OctalIntegerLiteral :: `0o` OctalDigits</emu-grammar> is the MV of |OctalDigits|.
</li>
Expand All @@ -11134,6 +11149,9 @@ <h1>Static Semantics: MV</h1>
<li>
The MV of <emu-grammar>OctalDigits :: OctalDigits OctalDigit</emu-grammar> is (the MV of |OctalDigits| &times; 8<sub>ℝ</sub>) plus the MV of |OctalDigit|.
</li>
<li>
The MV of <emu-grammar>OctalDigits :: OctalDigits NumericLiteralSeparator OctalDigit</emu-grammar> is (the MV of |OctalDigits| &times; 8<sub>ℝ</sub>) plus the MV of |OctalDigit|.
</li>
<li>
The MV of <emu-grammar>HexIntegerLiteral :: `0x` HexDigits</emu-grammar> is the MV of |HexDigits|.
</li>
Expand All @@ -11146,6 +11164,9 @@ <h1>Static Semantics: MV</h1>
<li>
The MV of <emu-grammar>HexDigits :: HexDigits HexDigit</emu-grammar> is (the MV of |HexDigits| &times; 16<sub>ℝ</sub>) plus the MV of |HexDigit|.
</li>
<li>
The MV of <emu-grammar>HexDigits :: HexDigits NumericLiteralSeparator HexDigit</emu-grammar> is (the MV of |HexDigits| &times; 16<sub>ℝ</sub>) plus the MV of |HexDigit|.
</li>
<li>
The MV of <emu-grammar>Hex4Digits :: HexDigit HexDigit HexDigit HexDigit</emu-grammar> is (0x1000<sub>ℝ</sub> times the MV of the first |HexDigit|) plus (0x100<sub>ℝ</sub> times the MV of the second |HexDigit|) plus (0x10<sub>ℝ</sub> times the MV of the third |HexDigit|) plus the MV of the fourth |HexDigit|.
</li>
Expand Down Expand Up @@ -11184,9 +11205,13 @@ <h1>Static Semantics: NumericValue</h1>
<emu-alg>
1. Return the BigInt value that represents the MV of |NonZeroDigit|.
</emu-alg>
<emu-grammar>DecimalBigIntegerLiteral :: NonZeroDigit DecimalDigits BigIntLiteralSuffix</emu-grammar>
<emu-grammar>
DecimalBigIntegerLiteral ::
NonZeroDigit DecimalDigits BigIntLiteralSuffix
NonZeroDigit NumericLiteralSeparator DecimalDigits BigIntLiteralSuffix
</emu-grammar>
<emu-alg>
1. Let _n_ be the mathematical integer number of code points in |DecimalDigits|.
1. Let _n_ be the mathematical integer number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
1. Let _mv_ be (the MV of |NonZeroDigit| &times; 10<sub>ℝ</sub><sup>_n_</sup>) plus the MV of |DecimalDigits|.
1. Return the BigInt value that represents _mv_.
</emu-alg>
Expand Down Expand Up @@ -11625,10 +11650,10 @@ <h2>Syntax</h2>
`u` `{` CodePoint [lookahead &lt;! HexDigit] [lookahead != `}`]

NotCodePoint ::
HexDigits [> but only if MV of |HexDigits| &gt; 0x10FFFF]
HexDigits[~Sep] [> but only if MV of |HexDigits| &gt; 0x10FFFF]

CodePoint ::
HexDigits [> but only if MV of |HexDigits| &le; 0x10FFFF]
HexDigits[~Sep] [> but only if MV of |HexDigits| &le; 0x10FFFF]
</emu-grammar>
<p>A conforming implementation must not use the extended definition of |EscapeSequence| described in <emu-xref href="#sec-additional-syntax-string-literals"></emu-xref> when parsing a |TemplateCharacter|.</p>
<emu-note>
Expand Down Expand Up @@ -30824,9 +30849,9 @@ <h2>Syntax</h2>
`*`
`+`
`?`
`{` DecimalDigits `}`
`{` DecimalDigits `,` `}`
`{` DecimalDigits `,` DecimalDigits `}`
`{` DecimalDigits[~Sep] `}`
`{` DecimalDigits[~Sep] `,` `}`
`{` DecimalDigits[~Sep] `,` DecimalDigits[~Sep] `}`

Atom[U, N] ::
PatternCharacter
Expand Down Expand Up @@ -30920,7 +30945,7 @@ <h2>Syntax</h2>
[~U] SourceCharacter but not UnicodeIDContinue

DecimalEscape ::
NonZeroDigit DecimalDigits? [lookahead &lt;! DecimalDigit]
NonZeroDigit DecimalDigits[~Sep]? [lookahead &lt;! DecimalDigit]

CharacterClassEscape[U] ::
`d`
Expand Down Expand Up @@ -41760,6 +41785,7 @@ <h1>Lexical Grammar</h1>
<emu-prodref name="RightBracePunctuator"></emu-prodref>
<emu-prodref name="NullLiteral"></emu-prodref>
<emu-prodref name="BooleanLiteral"></emu-prodref>
<emu-prodref name="NumericLiteralSeparator"></emu-prodref>
<emu-prodref name="NumericLiteral"></emu-prodref>
<emu-prodref name="DecimalBigIntegerLiteral"></emu-prodref>
<emu-prodref name="NonDecimalIntegerLiteral"></emu-prodref>
Expand Down Expand Up @@ -42140,8 +42166,8 @@ <h2>Syntax</h2>
NumericLiteral ::
DecimalLiteral
DecimalBigIntegerLiteral
NonDecimalIntegerLiteral
NonDecimalIntegerLiteral BigIntLiteralSuffix
NonDecimalIntegerLiteral[+Sep]
NonDecimalIntegerLiteral[+Sep] BigIntLiteralSuffix
LegacyOctalIntegerLiteral

LegacyOctalIntegerLiteral ::
Expand All @@ -42150,7 +42176,8 @@ <h2>Syntax</h2>

DecimalIntegerLiteral ::
`0`
NonZeroDigit DecimalDigits?
NonZeroDigit
NonZeroDigit NumericLiteralSeparator? DecimalDigits[+Sep]
NonOctalDecimalIntegerLiteral

NonOctalDecimalIntegerLiteral ::
Expand Down Expand Up @@ -42375,9 +42402,9 @@ <h2>Syntax</h2>
ExtendedPatternCharacter

InvalidBracedQuantifier ::
`{` DecimalDigits `}`
`{` DecimalDigits `,` `}`
`{` DecimalDigits `,` DecimalDigits `}`
`{` DecimalDigits[~Sep] `}`
`{` DecimalDigits[~Sep] `,` `}`
`{` DecimalDigits[~Sep] `,` DecimalDigits[~Sep] `}`

ExtendedPatternCharacter ::
SourceCharacter but not one of `^` `$` `\` `.` `*` `+` `?` `(` `)` `[` `|`
Expand Down Expand Up @@ -42674,7 +42701,7 @@ <h1>unescape ( _string_ )</h1>
1. Else if _k_ &le; _length_ - 3, then
1. Set _hexEscape_ to the substring of _string_ from _k_ + 1 to _k_ + 3.
1. Set _skip_ to 2.
1. If _hexEscape_ can be interpreted as an expansion of |HexDigits|, then
1. If _hexEscape_ can be interpreted as an expansion of |HexDigits[~Sep]|, then
1. Let _hexIntegerLiteral_ be the string-concatenation of *"0x"* and _hexEscape_.
1. Let _n_ be ! ToNumber(_hexIntegerLiteral_).
1. Set _c_ to the code unit whose value is _n_.
Expand Down

0 comments on commit 65d5bcc

Please sign in to comment.