sketch out backslash escape handling

This commit is contained in:
Tangent Wantwight 2024-06-08 00:03:17 -04:00
parent b2c5f7ea90
commit b536d30420

View file

@ -189,11 +189,53 @@ class Parser {
case "]":
return wip.finishScript();
case "backslash": {
this.advance();
const [type, chars, pos] = this.next;
switch (type) {
case "newline":
wip.finishWord();
break;
case "whitespace":
case "semicolon":
case "{":
case "}":
case "[":
case "]":
case "quote":
case "backslash":
case "comment":
wip.addWordPiece({ text: chars });
break;
case "text":
switch (chars) {
case "n":
wip.addWordPiece({ text: "\n" });
break;
default:
throw new Error(`Unknown backslash escape: ${chars}`);
}
break;
case "EOF":
throw new Error(
"Reached end of input while parsing a backslash escape"
);
case "ERROR":
throw new Error(chars);
default:
throw new Error(
`Unhandled case: ${type satisfies never} (${chars})`
);
}
break;
}
case "quote":
case "backslash":
case "comment":
case "ERROR":
throw new Error(`Unhandled case: ${type} (${chars})`);
case "ERROR":
throw new Error(chars);
default:
throw new Error(`Unhandled case: ${type satisfies never} (${chars})`);
}