ReviewOS

zig-utils/zig-js

Parser: retain unterminated RegExp literal diagnostics

#967
Closed chris opened this 9 days ago ·
9 days ago

Parent: #899

Problem

An unterminated regular-expression literal is lexed through the string error tag and reaches consumers as UnterminatedString plus an end position. JavaScriptCore reports the unterminated literal itself:

sourcezig-jsJavaScriptCore 625.1.22
/aeval: UnterminatedString at 1:3Unterminated regular expression literal '/a'
/[aeval: UnterminatedString at 1:4Unterminated regular expression literal '/[a'
/a\\eval: UnterminatedString at 1:4Unterminated regular expression literal '/a\'
/a\n/eval: UnterminatedString at 1:3Unterminated regular expression literal '/a'

The same result occurs after control heads and in initializers.

Implementation shape

The parser already owns the lexical-goal decision and knows when a failed slash reinterpretation was a RegExp scan. At that boundary, retain the source slice from the opening slash to the lexer failure offset and attach a dedicated diagnostic reason. Do not change successful RegExp scanning or add an additional source scan.

Verification

  • exact JSC differential for EOF, character-class, escape, line-terminator, control-head, and initializer forms;
  • parser diagnostic and focused evaluator tests;
  • standalone parser module;
  • exact-parent test262 comparison across RegExp literal subtrees.
9 days ago

Implemented and pushed to main in 244d841.

Validation:

  • 8/8 direct probes match JavaScriptCore 625.1.22 exactly across EOF, character-class, escape, line-terminator, control-head, and initializer forms
  • standalone parser module: 241/241 passed
  • focused evaluator matrix: 1/1 passed
  • exact-parent corpus: 14 historical lexical-negative RegExp cases plus all 8 Annex B literal cases produced 21 pass / 1 known fail with byte-identical inventories and 0 flips

The parser reuses the existing failed RegExp scan's source offset and source slice. Accepted RegExp literals retain their existing single lexer pass and allocation behavior.

Sign in to comment on this issue.