Split Number Scientific into Number NumberValue#168
Open
Split Number Scientific into Number NumberValue#168
Number Scientific into Number NumberValue#168Conversation
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
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.
JBeam (like JSON) has no semantic distinction between
1and1.0, BeamNG reads both identically. However, authors do write them differently, and the old formatter collapsed everything intoScientific, silently rewriting1as1.0on every format pass. This was unexpected.This PR introduces
NumberValueto track the distinction through the AST:Number ScientificbecomesNumber NumberValue. The formatter rendersIntValuewithshow(producing1) andDecimalValuewithformatScientific(producing1.0), so the output matches what the author wrote.Parser
intDecimalParserusesnotFollowedByon./e/EafterL.decimal, so1.5fails the integer branch and falls through toL.scientific. Both branches share the samenumberParsercombinator that handles the leading-.Representation
NumberValuefollows the same pattern asInternalComment, a dedicated type nested inside a singleNodeconstructor, keepingNode's pattern match surface flat while allowing finer-grained matching where needed.numberValueToScientificinCore/Node.hsprovides the canonical conversion for code that only needs a number.