fix: lex .5 and 5. as numbers, and not 5E and 5e+ - #59
Merged
Conversation
Fix three misreadings of number forms, inconsistent with Excel: - A numeric literal with no integer part (`.95`, `-.5`) was lexed as `unknown` followed by an integer number. The `.` can now start a number. A lone `.` without a digit on at least one side stays `unknown`. - A numeric literal with a dot but no fractional part (`1.`, `1.*2`, `1.E5`) was lexed as a number only at the end of the input (accidentally, because of a NaN gotcha, see below) and `unknown` elsewhere. Now a number everywhere. - An unfinished exponent at the end of the input (`1E`, `1.5e+`) was lexed as a number, because of a NaN gotcha in `advDigits`. The NaN gotcha in `advDigits`: it used a do-while loop, so didn't check string length before the first iteration. So if `pos` was after the end of the string, `str.charCodeAt` returned NaN. The result of `c < 48 || c > 57` (false for NaN) was then misunderstood as meaning that `c` was in the 0-9 range.
The tail guard that keeps a number from swallowing a sheet or range operator applies to the new form; pin it, per review.
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix three misreadings of number forms, inconsistent with Excel:
A numeric literal with no integer part (
.95,-.5) was lexed asunknownfollowed by an integer number. The.can now start a number. A lone.without a digit on at least one side staysunknown.A numeric literal with a dot but no fractional part (
1.,1.*2,1.E5) was lexed as a number only at the end of the input (accidentally, because of a NaN gotcha, see below) andunknownelsewhere. Now a number everywhere.An unfinished exponent at the end of the input (
1E,1.5e+) was lexed as a number, because of a NaN gotcha inadvDigits.The NaN gotcha in
advDigits: it used a do-while loop, so didn't check string length before the first iteration. So ifposwas after the end of the string,str.charCodeAtreturned NaN. The result ofc < 48 || c > 57(false for NaN) was then misunderstood as meaning thatcwas in the 0-9 range.