test(compiler): Demonstrate recoverable parsing of unterminated pipes (#39113)

There is no actionable change in this commit other than to pretty-print
EOF tokens. Actual parsing of unterminated pipes is already supported,
this just adds a test for it.

Part of #38596

PR Close #39113
This commit is contained in:
ayazhafiz 2020-10-04 23:31:22 -05:00 committed by Alex Rickabaugh
parent 6085d2acc9
commit 3f00c6150b
2 changed files with 11 additions and 2 deletions

View File

@ -491,10 +491,14 @@ export class _ParseAST {
this.error(`Missing expected operator ${operator}`);
}
prettyPrintToken(tok: Token): string {
return tok === EOF ? 'end of input' : `token ${tok}`;
}
expectIdentifierOrKeyword(): string {
const n = this.next;
if (!n.isIdentifier() && !n.isKeyword()) {
this.error(`Unexpected token ${n}, expected identifier or keyword`);
this.error(`Unexpected ${this.prettyPrintToken(n)}, expected identifier or keyword`);
return '';
}
this.advance();
@ -504,7 +508,7 @@ export class _ParseAST {
expectIdentifierOrKeywordOrString(): string {
const n = this.next;
if (!n.isIdentifier() && !n.isKeyword() && !n.isString()) {
this.error(`Unexpected token ${n}, expected identifier, keyword, or string`);
this.error(`Unexpected ${this.prettyPrintToken(n)}, expected identifier, keyword, or string`);
return '';
}
this.advance();

View File

@ -393,6 +393,11 @@ describe('parser', () => {
checkBinding('a | b:(c | d)', '(a | b:(c | d))');
});
it('should parse incomplete pipes', () => {
checkBinding('a | b | ', '((a | b) | )');
expectBindingError('a | b | ', 'Unexpected end of input, expected identifier or keyword');
});
it('should only allow identifier or keyword as formatter names', () => {
expectBindingError('"Foo"|(', 'identifier or keyword');
expectBindingError('"Foo"|1234', 'identifier or keyword');