Small scanner fix
This commit is contained in:
parent
eb6ade5a3d
commit
d382b16e6d
1 changed files with 4 additions and 7 deletions
|
|
@ -248,20 +248,17 @@ export class Scanner {
|
|||
case char("0"): value += "\0"; break;
|
||||
case char('"'): value += '"'; this.next(); break;
|
||||
// Unicode Escape: \u{XXXX}
|
||||
case char('v'): {
|
||||
const braceStart = 123123;
|
||||
}
|
||||
case char('u'): {
|
||||
this.next(); // consume 'u'
|
||||
|
||||
// 1. Expect '{'
|
||||
// Expect '{'
|
||||
const braceStart = this.currentLocation();
|
||||
if (this.peek() !== char('{')) {
|
||||
throw <LexError>{ tag: "InvalidEscape", reason: "Expected '{' after \\u", span: this.makeSpan(braceStart) };
|
||||
}
|
||||
this.next(); // consume '{'
|
||||
|
||||
// 2. Consume Hex Digits
|
||||
// Consume Hex Digits
|
||||
const hexStart = this.i;
|
||||
const hexCount = this.consumeWhile(c =>
|
||||
(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) };
|
||||
}
|
||||
|
||||
// 3. Expect '}'
|
||||
// Expect '}'
|
||||
if (this.peek() !== char("}")) {
|
||||
throw <LexError>{ tag: "InvalidEscape", reason: "Expected '}' closing unicode escape", span: this.makeSpan(braceStart) };
|
||||
}
|
||||
this.next(); // consume '}'
|
||||
|
||||
// 4. Convert & Append
|
||||
// Convert & Append
|
||||
const hexStr = this.text.sliceByCp(hexStart, hexStart + hexCount);
|
||||
const codePoint = parseInt(hexStr, 16);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue