Support quoted words
This commit is contained in:
parent
ac1a38e75f
commit
6b1c2c48ef
1 changed files with 61 additions and 1 deletions
|
@ -178,6 +178,19 @@ class Parser {
|
|||
break;
|
||||
}
|
||||
|
||||
case "quote": {
|
||||
if (wip.startOfWord()) {
|
||||
wip.addWordPiece({ text: "" }, pos);
|
||||
this.advance();
|
||||
this.parseQuoteWord(wip);
|
||||
this.expect("quote");
|
||||
wip.freezeWord("Extra characters after quoted word");
|
||||
} else {
|
||||
wip.addWordPiece({ bare: chars }, pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "[": {
|
||||
this.advance();
|
||||
const script = this.parseScript();
|
||||
|
@ -225,8 +238,55 @@ class Parser {
|
|||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new ParseError(
|
||||
`Unhandled case: ${type satisfies never} (${chars})`,
|
||||
pos
|
||||
);
|
||||
}
|
||||
|
||||
this.advance();
|
||||
}
|
||||
}
|
||||
|
||||
parseQuoteWord(wip: WipScript) {
|
||||
while (true) {
|
||||
const [type, chars, pos] = this.next;
|
||||
switch (type) {
|
||||
case "text":
|
||||
case "{":
|
||||
case "}":
|
||||
case "]":
|
||||
case "whitespace":
|
||||
case "newline":
|
||||
case "semicolon":
|
||||
case "comment":
|
||||
wip.addWordPiece({ text: chars }, pos);
|
||||
break;
|
||||
|
||||
case "[": {
|
||||
this.advance();
|
||||
const script = this.parseScript();
|
||||
wip.addWordPiece({ script }, pos);
|
||||
this.expect("]");
|
||||
break;
|
||||
}
|
||||
|
||||
case "EOF":
|
||||
throw new ParseError(
|
||||
"Reached end of input while parsing a quoted word",
|
||||
pos
|
||||
);
|
||||
|
||||
case "backslash": {
|
||||
this.advance();
|
||||
this.parseBackslashEscape(wip, "quote");
|
||||
break;
|
||||
}
|
||||
|
||||
case "quote":
|
||||
throw new Error(`Unhandled case: ${type} (${chars})`);
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new ParseError(
|
||||
`Unhandled case: ${type satisfies never} (${chars})`,
|
||||
|
|
Loading…
Reference in a new issue