Skip to content

Split Number Scientific into Number NumberValue#168

Open
webdevred wants to merge 4 commits intomasterfrom
split-number-type
Open

Split Number Scientific into Number NumberValue#168
webdevred wants to merge 4 commits intomasterfrom
split-number-type

Conversation

@webdevred
Copy link
Owner

JBeam (like JSON) has no semantic distinction between 1 and 1.0, BeamNG reads both identically. However, authors do write them differently, and the old formatter collapsed everything into Scientific, silently rewriting 1 as 1.0 on every format pass. This was unexpected.

This PR introduces NumberValue to track the distinction through the AST:

data NumberValue
  = IntValue Integer
  | DecimalValue Scientific

Number Scientific becomes Number NumberValue. The formatter renders IntValue with show (producing 1) and DecimalValue with formatScientific (producing 1.0), so the output matches what the author wrote.

Parser

intDecimalParser uses notFollowedBy on ./e/E after L.decimal, so 1.5 fails the integer branch and falls through to L.scientific. Both branches share the same numberParser combinator that handles the leading -.

Representation

NumberValue follows the same pattern as InternalComment, a dedicated type nested inside a single Node constructor, keeping Node's pattern match surface flat while allowing finer-grained matching where needed. numberValueToScientific in Core/Node.hs provides the canonical conversion for code that only needs a number.

Replace the single `Number Scientific` constructor with `Number NumberValue`
where `NumberValue = IntValue Integer | DecimalValue Scientific`. This preserves
the int/float distinction from source JBeam files so integers round-trip as `1`
rather than `1.0`.

- Add `NumberValue` type and `numberValueToScientific` to `Core/Node.hs`
- Parser uses `notFollowedBy` on `.`/`e`/`E` to distinguish int from decimal
- Formatter renders `IntValue` via `show`, `DecimalValue` via `formatScientific`
- Refactor `newVertex`/`nodeScientific` in `VertexExtraction` using the new utility
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.

1 participant