Accept an insignificant comma where an array element would be - #238
Draft
webdevred wants to merge 1 commit into
Draft
Accept an insignificant comma where an array element would be#238webdevred wants to merge 1 commit into
webdevred wants to merge 1 commit 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.
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 freeto 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.
Part of #230. A failing spec only, no fix yet, so it stays a draft until the question at the end is settled.
BeamNG treats a comma as insignificant, closer to whitespace than to structure. Stock files rely on that, and one of the shapes is a stray comma where an array element would be:
Our grammar allows exactly one comma between elements, and
separatorParserruns only between them, so a second one has nowhere to sit. The parse stops at it.The spec asserts only that the input is accepted. What the formatter writes back for the empty slot is a separate decision, and it needs its own spec once it is made. Two ways to go:
Drop it. The file means the same thing to the game, and the formatter already normalises whitespace, indentation and padding, so a comma carrying nothing falls in the same category.
collectElementsskips it and nothing else changes.Keep it.
ArrayValueholdsVector (Node, Bool)where the flag means "this element was followed by a comma", so a comma with no element has nowhere to live. Preserving it needs either a node that renders as nothing or a second field, andAutoPadderives column widths from the elements, so it would also have to learn that the slot is not a column.I lean towards dropping it.