Skip to content

fix number parsing - #370

Merged
wpbonelli merged 2 commits into
modflowpy:developfrom
wpbonelli:roundtrip-iso-datetime
Sep 25, 2026
Merged

wpbonelli merged 2 commits into
modflowpy:developfrom
wpbonelli:roundtrip-iso-datetime

Conversation

@wpbonelli

Copy link
Copy Markdown
Member

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:30 gave [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 Fortran D exponents, 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

wpbonelli and others added 2 commits September 25, 2026 09:29
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 wpbonelli added this to the MVP milestone Sep 25, 2026
@wpbonelli wpbonelli added bug Something isn't working IO Related to loading/writing input/output files labels Sep 25, 2026
@wpbonelli
wpbonelli marked this pull request as ready for review September 25, 2026 14:04
@wpbonelli
wpbonelli merged commit d017146 into modflowpy:develop Sep 25, 2026
16 checks passed
@wpbonelli
wpbonelli deleted the roundtrip-iso-datetime branch September 25, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working IO Related to loading/writing input/output files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant