Skip to content

require a token boundary after keyword, hex and Infinity/NaN literals - #168

Merged
dpranke merged 1 commit into
dpranke:mainfrom
iefa-m:literal-token-boundary
Nov 30, 2026
Merged

dpranke merged 1 commit into
dpranke:mainfrom
iefa-m:literal-token-boundary

Conversation

@iefa-m

@iefa-m iefa-m commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

The grammar only checks the token boundary after decimal literals (dec_literal:d ~id_start). The null/true/false alternatives of value and the hex, Infinity and NaN alternatives of unsigned_lit match a prefix and stop, so parse(..., consume_trailing=False), the documented way to read several values out of one string, returns None for 'nullable', True for 'truex', 10 and then None for '0xAnull', and two NaNs for 'NaNNaN'. None of these are JSON5 values: ES5.1 section 7.8.3 says the character after a numeric literal can't be an IdentifierStart or digit, and nullable is a single identifier. With the default consume_trailing=True the same inputs already fail, just one character later than '1true' does.

Add the missing lookahead in the grammar: ~id_start after hex_literal to match dec_literal, and ~id_continue after null, true, false, Infinity and NaN so a keyword only matches as a whole word. Keeping the rule in the grammar means every entry point gets it; parser.py is regenerated with glop 0.9.0 and the diff there is limited to these rules.

Only dec_literal checked that no identifier character follows it, so
with consume_trailing=False parse() returned None for 'nullable', True
for 'truex', 10 for '0xAnull' and inf for 'Infinitytrue'. Add the same
negative lookahead to the other literal alternatives and regenerate
parser.py with glop.

@dpranke dpranke left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, looks right. Good catch!

@dpranke
dpranke merged commit af2cc70 into dpranke:main Nov 30, 2026
9 checks passed
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.

2 participants