Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: Simplify the |NumericLiteral| grammar #3096

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 12 additions & 23 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -16548,14 +16548,11 @@ <h2>Syntax</h2>
NumericLiteral ::
DecimalLiteral
DecimalBigIntegerLiteral
NonDecimalIntegerLiteral[+Sep]
NonDecimalIntegerLiteral[+Sep] BigIntLiteralSuffix
NonDecimalIntegerLiteral[+Sep] BigIntLiteralSuffix?
LegacyOctalIntegerLiteral

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

NonDecimalIntegerLiteral[Sep] ::
BinaryIntegerLiteral[?Sep]
Expand All @@ -16573,10 +16570,13 @@ <h2>Syntax</h2>
DecimalFraction[~Empty]

DecimalIntegerLiteral ::
CanonicalDecimalIntegerLiteral
NonOctalDecimalIntegerLiteral

CanonicalDecimalIntegerLiteral ::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might there be a better name than CanonicalDecimalIntegerLiteral? It makes me think “canonical numeric string”, which corresponds to neither a superset nor subset of the sequences this production matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, suggestions welcome. But the similarity to "canonical numeric string" is intentional, and the two concepts do mostly agree where they intersect—not for power-of-two numbers large enough that Number::toString uses exponential notation, but I'm willing to chalk that up as a difference between canonicalized numeric strings vs. integer literals (numeric strings and integer literals already being distinct with respect to e.g. supporting _ separators).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for power-of-two numbers large enough that Number::toString uses exponential notation

Even without exponential notation, stuff beyond safe integer range won’t always be canonical in the CNS sense, right? For example the source text literal 9007199254740993 evaluates to the Number value whose canonical string representation is 9007199254740992.

the similarity to "canonical numeric string" is intentional

In that case, perhaps I’m alone in thinking the word might be misleading there, so unless others have an opinion it’s probably not worth changing.

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

DecimalFraction[Empty] ::
`.` DecimalDigits[+Sep]
Expand Down Expand Up @@ -16684,10 +16684,10 @@ <h1>Static Semantics: MV</h1>
The MV of <emu-grammar>DecimalBasePart :: DecimalIntegerLiteral DecimalFraction</emu-grammar> is the MV of |DecimalIntegerLiteral| plus the MV of |DecimalFraction|.
</li>
<li>
The MV of <emu-grammar>DecimalIntegerLiteral :: `0`</emu-grammar> is 0.
The MV of <emu-grammar>CanonicalDecimalIntegerLiteral :: `0`</emu-grammar> is 0.
</li>
<li>
The MV of <emu-grammar>DecimalIntegerLiteral :: NonZeroDigit NumericLiteralSeparator? DecimalDigits</emu-grammar> is (the MV of |NonZeroDigit| × 10<sup>_n_</sup>) plus the MV of |DecimalDigits|, where _n_ is the number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
The MV of <emu-grammar>CanonicalDecimalIntegerLiteral :: NonZeroDigit NumericLiteralSeparator? DecimalDigits</emu-grammar> is (the MV of |NonZeroDigit| × 10<sup>_n_</sup>) plus the MV of |DecimalDigits|, where _n_ is the number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
</li>
<li>
The MV of <emu-grammar>DecimalFraction :: `.` DecimalDigits</emu-grammar> is the MV of |DecimalDigits| × 10<sup>-_n_</sup>, where _n_ is the number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
Expand Down Expand Up @@ -16805,22 +16805,10 @@ <h1>Static Semantics: NumericValue ( ): a Number or a BigInt</h1>
<emu-alg>
1. Return the BigInt value that represents the MV of |NonDecimalIntegerLiteral|.
</emu-alg>
<emu-grammar>DecimalBigIntegerLiteral :: `0` BigIntLiteralSuffix</emu-grammar>
<emu-alg>
1. Return *0*<sub>ℤ</sub>.
</emu-alg>
<emu-grammar>DecimalBigIntegerLiteral :: NonZeroDigit BigIntLiteralSuffix</emu-grammar>
<emu-alg>
1. Return the BigInt value that represents the MV of |NonZeroDigit|.
</emu-alg>
<emu-grammar>
DecimalBigIntegerLiteral ::
NonZeroDigit DecimalDigits BigIntLiteralSuffix
NonZeroDigit NumericLiteralSeparator DecimalDigits BigIntLiteralSuffix
</emu-grammar>
<emu-grammar>DecimalBigIntegerLiteral :: CanonicalDecimalIntegerLiteral BigIntLiteralSuffix</emu-grammar>
<emu-alg>
1. Let _n_ be the number of code points in |DecimalDigits|, excluding all occurrences of |NumericLiteralSeparator|.
1. Let _mv_ be (the MV of |NonZeroDigit| × 10<sup>_n_</sup>) plus the MV of |DecimalDigits|.
1. Let _mv_ be the MV of |CanonicalDecimalIntegerLiteral|.
1. Assert: _mv_ is an integer.
1. Return ℤ(_mv_).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -47443,6 +47431,7 @@ <h1>Lexical Grammar</h1>
<emu-prodref name="DecimalLiteral"></emu-prodref>
<emu-prodref name="DecimalBasePart"></emu-prodref>
<emu-prodref name="DecimalIntegerLiteral"></emu-prodref>
<emu-prodref name="CanonicalDecimalIntegerLiteral"></emu-prodref>
<emu-prodref name="DecimalFraction"></emu-prodref>
<emu-prodref name="DecimalDigits"></emu-prodref>
<emu-prodref name="DecimalDigit"></emu-prodref>
Expand Down