Skip to content

Accept the insignificant commas and trailing dots that stock files use - #238

Open
webdevred wants to merge 7 commits into
masterfrom
tolerate-insignificant-commas
Open

Accept the insignificant commas and trailing dots that stock files use#238
webdevred wants to merge 7 commits into
masterfrom
tolerate-insignificant-commas

Conversation

@webdevred

@webdevred webdevred commented Aug 23, 2026

Copy link
Copy Markdown
Owner

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.sh gives about 4900 files, of which 35 contain two commas in a row, 41 occurrences in total, and every one of them is exactly two. separatorParser is the exception and takes any number, which is wider than anything that occurs.

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 webdevred changed the title Accept an insignificant comma where an array element would be Accept the insignificant commas and trailing dots that stock files use Aug 25, 2026
@webdevred
webdevred marked this pull request as ready for review August 25, 2026 18:17
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.

Cannot parse valid jbeam that the game reads

1 participant