Factor out backslash parse helper

This commit is contained in:
Tangent Wantwight 2024-06-08 13:11:46 -04:00
parent fa3be1e003
commit a2c8eb66b9

View file

@ -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 {