Factor out backslash parse helper
This commit is contained in:
parent
fa3be1e003
commit
a2c8eb66b9
1 changed files with 43 additions and 37 deletions
|
@ -217,10 +217,31 @@ class Parser {
|
|||
|
||||
case "backslash": {
|
||||
this.advance();
|
||||
this.parseBackslashEscape(wip, "bare");
|
||||
break;
|
||||
}
|
||||
|
||||
case "quote":
|
||||
throw new Error(`Unhandled case: ${type} (${chars})`);
|
||||
case "ERROR":
|
||||
throw new Error(chars);
|
||||
default:
|
||||
throw new Error(`Unhandled case: ${type satisfies never} (${chars})`);
|
||||
}
|
||||
|
||||
this.advance();
|
||||
}
|
||||
}
|
||||
|
||||
parseBackslashEscape(wip: WipScript, wordType: "bare" | "quote") {
|
||||
const [type, chars, pos] = this.next;
|
||||
switch (type) {
|
||||
case "newline":
|
||||
if (wordType == "bare") {
|
||||
wip.finishWord();
|
||||
} else {
|
||||
// ignore newline
|
||||
}
|
||||
break;
|
||||
|
||||
case "whitespace":
|
||||
|
@ -249,24 +270,9 @@ class Parser {
|
|||
);
|
||||
case "ERROR":
|
||||
throw new Error(chars);
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled case: ${type satisfies never} (${chars})`
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "quote":
|
||||
throw new Error(`Unhandled case: ${type} (${chars})`);
|
||||
case "ERROR":
|
||||
throw new Error(chars);
|
||||
default:
|
||||
throw new Error(`Unhandled case: ${type satisfies never} (${chars})`);
|
||||
}
|
||||
|
||||
this.advance();
|
||||
}
|
||||
}
|
||||
|
||||
parseBrace(): string {
|
||||
|
|
Loading…
Reference in a new issue