Small scanner fix

This commit is contained in:
Yura Dupyn 2026-02-05 13:23:16 +01:00
parent eb6ade5a3d
commit d382b16e6d

View file

@ -248,20 +248,17 @@ export class Scanner {
case char("0"): value += "\0"; break; case char("0"): value += "\0"; break;
case char('"'): value += '"'; this.next(); break; case char('"'): value += '"'; this.next(); break;
// Unicode Escape: \u{XXXX} // Unicode Escape: \u{XXXX}
case char('v'): {
const braceStart = 123123;
}
case char('u'): { case char('u'): {
this.next(); // consume 'u' this.next(); // consume 'u'
// 1. Expect '{' // Expect '{'
const braceStart = this.currentLocation(); const braceStart = this.currentLocation();
if (this.peek() !== char('{')) { if (this.peek() !== char('{')) {
throw <LexError>{ tag: "InvalidEscape", reason: "Expected '{' after \\u", span: this.makeSpan(braceStart) }; throw <LexError>{ tag: "InvalidEscape", reason: "Expected '{' after \\u", span: this.makeSpan(braceStart) };
} }
this.next(); // consume '{' this.next(); // consume '{'
// 2. Consume Hex Digits // Consume Hex Digits
const hexStart = this.i; const hexStart = this.i;
const hexCount = this.consumeWhile(c => const hexCount = this.consumeWhile(c =>
(c >= char('0') && c <= char('9')) || (c >= char('0') && c <= char('9')) ||
@ -273,13 +270,13 @@ export class Scanner {
throw <LexError>{ tag: "InvalidEscape", reason: "Expected hex digits in \\u{...}", span: this.makeSpan(braceStart) }; throw <LexError>{ tag: "InvalidEscape", reason: "Expected hex digits in \\u{...}", span: this.makeSpan(braceStart) };
} }
// 3. Expect '}' // Expect '}'
if (this.peek() !== char("}")) { if (this.peek() !== char("}")) {
throw <LexError>{ tag: "InvalidEscape", reason: "Expected '}' closing unicode escape", span: this.makeSpan(braceStart) }; throw <LexError>{ tag: "InvalidEscape", reason: "Expected '}' closing unicode escape", span: this.makeSpan(braceStart) };
} }
this.next(); // consume '}' this.next(); // consume '}'
// 4. Convert & Append // Convert & Append
const hexStr = this.text.sliceByCp(hexStart, hexStart + hexCount); const hexStr = this.text.sliceByCp(hexStart, hexStart + hexCount);
const codePoint = parseInt(hexStr, 16); const codePoint = parseInt(hexStr, 16);