Accept the insignificant commas and trailing dots that stock files use - #238
Open
webdevred wants to merge 7 commits into
Open
Accept the insignificant commas and trailing dots that stock files use#238webdevred wants to merge 7 commits into
webdevred wants to merge 7 commits into
Conversation
BeamNG treats a comma as insignificant, so an array with a stray one where an element would be is a file the game reads. The grammar allows exactly one comma between elements and has nowhere to put a second, so the parse stops.
numberParser now optionally consumes a lone "." following a number with no decimal digits (e.g. "3." parses as 3, period discarded). Previously the period was left unconsumed.
The parser rejects four more shapes that BeamNG reads: a comma after a key colon, one before it, one after the root object, and a number ending on its decimal point. Each spec asserts only that the input is accepted, since what the formatter writes back is undecided.
It was exported so a spec could run a parser and look at the input left over, but the already exported parseNodesState does that on its own.
webdevred
marked this pull request as ready for review
August 25, 2026 18:17
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.
Closes #230.
BeamNG treats a comma as insignificant, closer to whitespace than to structure, and accepts a number that ends on its decimal point. Stock files use both, and our grammar rejected five shapes because of it: a stray comma where an array element would be, one on either side of a key's colon, one after the root object, and a number written as
0..None of it survives formatting. Every insignificant comma and the trailing dot are dropped, so a file that had them comes out normalised. The file means the same thing to the game, and the formatter already rewrites whitespace, indentation and padding, so a comma carrying nothing falls in the same category.
The tolerance in the two key positions is deliberately a single comma rather than a run. Extracting every jbeam from the shipped vehicle zips with
tools/extract-and-format-jbeam/corpus-extract.shgives about 4900 files, of which 35 contain two commas in a row, 41 occurrences in total, and every one of them is exactly two.separatorParseris the exception and takes any number, which is wider than anything that occurs.