Skip to content

Commit

Permalink
Clarify Number parsing, expand exponent grammar
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
leebyron committed Jul 16, 2015
1 parent 5bb2bb5 commit d04ea22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Section 2 -- Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ contain variables.

**Int**

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

**Float**

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

**Boolean**

Expand Down
30 changes: 18 additions & 12 deletions Section 8 -- Grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,30 @@ Punctuator : one of ! $ ( ) ... : = @ [ ] { | }

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

IntValue : Sign? IntegerPart
IntValue : IntegerPart

FloatValue : Sign? IntegerPart . Digit+ ExponentPart?

Sign : -
FloatValue :
- IntegerPart FractionalPart
- IntegerPart ExponentPart
- IntegerPart FractionalPart ExponentPart

IntegerPart :
- 0
- NonZeroDigit
- NonZeroDigit Digit+
- NegativeSign? 0
- NegativeSign? NonZeroDigit Digit+?

FractionalPart : . Digit+

ExponentPart : ExponentIndicator Sign? Digit+

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

NonZeroDigit : Digit but not `0`

ExponentPart : e Sign? Digit+
Sign : one of + -

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

Digit :
- 0
- NonZeroDigit
ExponentIndicator : one of `e` `E`

StringValue :
- `""`
Expand Down

0 comments on commit d04ea22

Please sign in to comment.