Be strict about trailing characters after braces. Don't give mid-word braces magic meaning.

This commit is contained in:
Tangent Wantwight 2024-06-05 20:44:13 -04:00
parent c1ce90fd63
commit c61496fcc3

View file

@ -71,24 +71,31 @@ class WipScript {
wipCommand: Word[] = []; wipCommand: Word[] = [];
wipWord: InterpolatedPiece[] = []; wipWord: InterpolatedPiece[] = [];
wordPos: number | undefined = undefined; wordPos: number | undefined = undefined;
// TODO: thing to fail {}a & ""a endOfWordError: string | undefined = undefined;
startOfWord(): boolean { startOfWord(): boolean {
return this.wipWord.length == 0; return this.wipWord.length == 0;
} }
addWordPiece(piece: InterpolatedPiece, pos?: number) { addWordPiece(piece: InterpolatedPiece, pos?: number) {
if (this.endOfWordError) {
throw new Error(this.endOfWordError);
}
if (this.startOfWord()) { if (this.startOfWord()) {
this.wordPos = pos; this.wordPos = pos;
} }
this.wipWord.push(piece); this.wipWord.push(piece);
} }
freezeWord(error: string) {
this.endOfWordError = error;
}
finishWord() { finishWord() {
if (this.wipWord.length > 0) { if (this.wipWord.length > 0) {
this.wipCommand.push(SimplifyWord(this.wipWord, this.wordPos)); this.wipCommand.push(SimplifyWord(this.wipWord, this.wordPos));
this.wipWord = [];
this.wordPos = undefined;
} }
this.wipWord = [];
this.wordPos = undefined;
this.endOfWordError = undefined;
} }
finishCommand() { finishCommand() {
this.finishWord(); this.finishWord();
@ -149,10 +156,15 @@ class Parser {
break; break;
case "{": { case "{": {
this.advance(); if (wip.startOfWord()) {
const text = this.parseBrace(); this.advance();
wip.addWordPiece({ text }, pos); const text = this.parseBrace();
this.expect("}"); wip.addWordPiece({ text }, pos);
this.expect("}");
wip.freezeWord("Extra characters after closing brace");
} else {
wip.addWordPiece({ bare: chars }, pos);
}
break; break;
} }