Skip to content

Conversation

@hi-cannon
Copy link

Small fix for typo in the number rule:

[eE] [-+]? [0-9] [1-9]{0,15}

This would allow one leading zero and no trailing zeros; e.g. forbidding e+10, e+100 etc. I assume the reverse was intended

Fix minor typo
Old grammar would allow exponents with a leading zero, and no trailing zeros
@CISC
Copy link
Collaborator

CISC commented Nov 24, 2025

e+01 or even e+0 is also valid notation.

@hi-cannon
Copy link
Author

hi-cannon commented Nov 24, 2025

e+01 or even e+0 is also valid notation.

It is valid, but arbitrary. E+10 is also valid and very much not arbitrary. The rule could be [0-9] [0-9]{0,15} instead, if that behavior is truly desired. However the number rule in json_arr.gbnf would suggest this was not the intention:

number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws

This reflects the change I proposed, and covers all valid scientific notation, unlike the existing rule which forbids a significant number of valid outputs.

@CISC
Copy link
Collaborator

CISC commented Nov 24, 2025

It used to be ([eE] [-+]? [0-9]+), it was @ochafik that changed it to what it is today in #7841.

@hi-cannon
Copy link
Author

If this rule isn't wrong then the one in json_arr.gbnf must be. But I'm assuming it's the rule that forbids e+10 (or any zeros other than the first digit) that was unintended

@hi-cannon
Copy link
Author

Just to lay it out clearly

json.gbnf:
number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws

json_arr.gbnf:
number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws

The rules are exactly the same except for the last two character groups, so that's why I figure it was a typo. The json_arr.gbnf version looks more correct to me, but do tell me if I am mistaken

@CISC
Copy link
Collaborator

CISC commented Nov 24, 2025

Just to lay it out clearly

json.gbnf:
number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws

json_arr.gbnf:
number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws

The rules are exactly the same except for the last two character groups, so that's why I figure it was a typo. The json_arr.gbnf version looks more correct to me, but do tell me if I am mistaken

Both changed in the aforementioned PR, one (or both) of them must be wrong, they used to be [0-9]+. :) @ochafik?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants