Skip to content

Commit 5004a01

Browse files
committed
:eval throws E15 if an expression doesn't parse
1 parent f6f432e commit 5004a01

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/cmd_line/commands/eval.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import { optWhitespace, Parser } from 'parsimmon';
1+
import { all, optWhitespace, Parser, seq } from 'parsimmon';
22
import { VimState } from '../../state/vimState';
33
import { ExCommand } from '../../vimscript/exCommand';
44
import { expressionParser, functionCallParser } from '../../vimscript/expression/parser';
55
import { Expression } from '../../vimscript/expression/types';
66
import { EvaluationContext } from '../../vimscript/expression/evaluate';
7+
import { VimError } from '../../error';
78

89
export class EvalCommand extends ExCommand {
910
public static argParser: Parser<EvalCommand> = optWhitespace
10-
.then(expressionParser)
11-
.map((expression) => new EvalCommand(expression));
11+
.then(seq(expressionParser.fallback(undefined), all))
12+
.map(([expression, trailing]) => {
13+
if (expression === undefined) {
14+
throw VimError.InvalidExpression(trailing);
15+
}
16+
if (trailing) {
17+
throw VimError.TrailingCharacters(trailing);
18+
}
19+
return new EvalCommand(expression);
20+
});
1221

1322
private expression: Expression;
1423
private constructor(expression: Expression) {

0 commit comments

Comments
 (0)