fix number parsing - #370
Merged
Merged
Conversation
A token that started like a number lexed as a NUMBER followed by a word: `START_DATE_TIME 1997-07-16T19:20:30` gave `[1997, '-07-16T19:20:30']`, and TDIS then failed to write. The same applied to any token with a leading digit, such as a file name `1model.ts`. Lark's lexer takes the first terminal that matches, not the longest match, and NUMBER sorted ahead of word. Every whitespace-delimited token now lexes as a single TOKEN terminal, and the transformer makes it a number if the whole token is one. This also reads signed numbers (`-5`) as numbers instead of strings, and Fortran `D` exponents (`1D-5`) as floats. 21 corpus models now write. 5 round-trip cleanly; the other 16 show the single-name AUXILIARY bug, and test001h_rch_array3 also drops a TAS period array. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The typed grammar had the same problem as the basic one: a token that started like a number lexed as a number followed by more tokens. TDIS `START_DATE_TIME 1997-07-16T19:20:30.45+01:00` split into `1997`, `-07`, `-16` and `T19:20:30.45+01:00`, and the transformer kept only `1997`. The typed rules branch on whether a token is a number, so it can't lex every token as one terminal like the basic grammar does. Instead INT, SIGNED_INT, NUMBER and SIGNED_NUMBER now have to be followed by whitespace, a comma, a comment or the end of input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wpbonelli
marked this pull request as ready for review
September 25, 2026 14:04
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 free
to 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.
The basic parser lexed a not-solely-numeric token starting with numeric characters as a number followed by a word, e.g.
1997-07-16T19:20:30gave[1997, '-07-16T19:20:30']. Lex each whitespace-separated token as a single terminal, and have the transformer decide if it's a number. This also fixes signed numbers, which used to lex as strings, and FortranDexponents, which used to incorrectly split the token.The typed grammar had a similar problem, but the fix is different: define number terminals as followed by whitespace, a comma, a comment or the end of input.
This fixes 21 models currently xfailed in the roundtrip tests from #369