Skip to content

Commit d04ea22

Browse files
committed
Clarify Number parsing, expand exponent grammar
This makes Number parsing match the JSON spec for numbers, reducing the chances for naive error. It also hopefully clarifies the non-zero leading case for numbers in `IntegerPart`.
1 parent 5bb2bb5 commit d04ea22

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Section 2 -- Language.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ contain variables.
222222

223223
**Int**
224224

225-
Int is a number specified without a decimal point (ex. `1`).
225+
Int is a number specified without a decimal point or exponent (ex. `1`).
226226

227227
**Float**
228228

229-
A Float numbers always includes a decimal point (ex. `1.0`) and may optionally
230-
also include an exponent (ex. `6.0221413e23`).
229+
A Float number includes either a decimal point (ex. `1.0`) or an exponent
230+
(ex. `1e50`) or both (ex. `6.0221413e23`).
231231

232232
**Boolean**
233233

Section 8 -- Grammar.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,30 @@ Punctuator : one of ! $ ( ) ... : = @ [ ] { | }
158158

159159
Name : /[_A-Za-z][_0-9A-Za-z]*/
160160

161-
IntValue : Sign? IntegerPart
161+
IntValue : IntegerPart
162162

163-
FloatValue : Sign? IntegerPart . Digit+ ExponentPart?
164-
165-
Sign : -
163+
FloatValue :
164+
- IntegerPart FractionalPart
165+
- IntegerPart ExponentPart
166+
- IntegerPart FractionalPart ExponentPart
166167

167168
IntegerPart :
168-
- 0
169-
- NonZeroDigit
170-
- NonZeroDigit Digit+
169+
- NegativeSign? 0
170+
- NegativeSign? NonZeroDigit Digit+?
171+
172+
FractionalPart : . Digit+
173+
174+
ExponentPart : ExponentIndicator Sign? Digit+
175+
176+
Digit : one of 0 1 2 3 4 5 6 7 8 9
177+
178+
NonZeroDigit : Digit but not `0`
171179

172-
ExponentPart : e Sign? Digit+
180+
Sign : one of + -
173181

174-
NonZeroDigit : one of 1 2 3 4 5 6 7 8 9
182+
NegativeSign : -
175183

176-
Digit :
177-
- 0
178-
- NonZeroDigit
184+
ExponentIndicator : one of `e` `E`
179185

180186
StringValue :
181187
- `""`

0 commit comments

Comments
 (0)