Add support for single-quoted strings in mojangson parser #53
+100
−2
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.
Fixes parsing errors when NBT data contains strings surrounded by single quotes instead of double quotes.
Problem
The parser was failing to parse valid Minecraft NBT strings that use single quotes (
') instead of double quotes ("). According to the Minecraft NBT format specification, single quotes are valid string delimiters.This was causing errors like:
Examples that were failing:
{key:'value'}{"minecraft:custom_name":'":!!: book :!!:"'}Solution
Extended the grammar to support single-quoted strings while maintaining backward compatibility:
Added
SINGLE_QUOTED_STRINGgrammar rule - Handles single-quoted strings with proper escape sequence support (including\',\",\n,\r,\t,\b,\f,\/,\\, and unicode escapes)Implemented disambiguation logic - When single-quoted content can be parsed as either a plain string or a compound object (e.g.,
'{"text":"..."}'), the parser now prefers the structured interpretation (compound), matching Minecraft's behaviorAdded comprehensive tests - 7 new test cases covering various single-quote scenarios
Examples
Now works correctly:
Testing
Original prompt
Fixes #52
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.