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