Be strict about trailing characters after braces. Don't give mid-word braces magic meaning.
This commit is contained in:
parent
c1ce90fd63
commit
c61496fcc3
1 changed files with 19 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue