fix(grammar): support single-quoted keys in compound pairs - #64
Open
AnonymoDGH wants to merge 1 commit into
Open
fix(grammar): support single-quoted keys in compound pairs#64AnonymoDGH wants to merge 1 commit into
AnonymoDGH wants to merge 1 commit into
Conversation
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.
Related to #63
Investigation of #63
The exact payload from the issue parses correctly on current master — single-quoted string values were already fixed by #53 (merged 2025-12-22). The reporter's stack trace (
index.js:94,offset: 42,token: { value: 's' }) matches the published npm package 2.0.4 (2023-06-03), which predates that fix. I verified this by installingmojangson@2.0.4and feeding it the issue's payload: it fails with the identical error, while master parses it fine.So the main fix for #63 is already on master — it just hasn't been published (npm
latestis still 2.0.4, master is 2.1.0). Publishing 2.1.0 would resolve the report.What this PR fixes
While verifying, I found a genuine remaining gap: single-quoted keys still fail, even though Minecraft SNBT allows them:
The
PAIRrule only acceptedSTRINGas a key, andSTRING's unquoted branch excludes'. This adds aSINGLE_QUOTED_STRINGalternative toPAIR, so single-quoted keys work everywhere double-quoted keys do (including keys with spaces, colons, and escaped quotes).Verified
{'key':'value'},{'key':"value"},{'a':1,"b":2},{'my key':'v'},{'minecraft:id':'x'}, nested{'outer':{'inner':'v'}}all parse correctly.npm test: 140 passing (standard lint + mocha), including 6 new single-quoted-key cases.Note:
grammar.jsis a gitignored build artifact regenerated fromgrammar.nevianearleyc(prepublish), so onlygrammar.neis changed here.