diff --git a/src/parser2.ts b/src/parser2.ts index 75f9842..163ed25 100644 --- a/src/parser2.ts +++ b/src/parser2.ts @@ -66,15 +66,20 @@ class WipScript { script: Command[] = []; wipCommand: Word[] = []; wipWord: InterpolatedPiece[] = []; + wordPos: number | undefined = undefined; // TODO: thing to fail {}a & ""a - addWordPiece(piece: InterpolatedPiece) { + addWordPiece(piece: InterpolatedPiece, pos?: number) { + if (this.wipWord.length == 0) { + this.wordPos = pos; + } this.wipWord.push(piece); } finishWord() { if (this.wipWord.length > 0) { - this.wipCommand.push(SimplifyWord(this.wipWord)); + this.wipCommand.push(SimplifyWord(this.wipWord, this.wordPos)); this.wipWord = []; + this.wordPos = undefined; } } finishCommand() { @@ -123,7 +128,7 @@ class Parser { const [type, chars, pos] = this.next; switch (type) { case "text": - wip.addWordPiece({ bare: chars, pos }); + wip.addWordPiece({ bare: chars }, pos); break; case "whitespace": @@ -147,6 +152,8 @@ class Parser { case "comment": case "ERROR": throw new Error(`Unhandled case: ${type} (${chars})`); + default: + throw new Error(`Unhandled case: ${type satisfies never} (${chars})`); } this.advance();