Skip to content

Commit f6f432e

Browse files
committed
:let throws E15 if an expression doesn't parse
1 parent c0655d3 commit f6f432e

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/cmd_line/commands/let.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line id-denylist
2-
import { alt, optWhitespace, Parser, sepBy, seq, seqMap, string, whitespace } from 'parsimmon';
2+
import { all, alt, optWhitespace, Parser, sepBy, seq, seqMap, string, whitespace } from 'parsimmon';
33
import { VimState } from '../../state/vimState';
44
import { StatusBar } from '../../statusBar';
55
import { ExCommand } from '../../vimscript/exCommand';
@@ -130,16 +130,22 @@ export class LetCommand extends ExCommand {
130130
letVarParser,
131131
),
132132
operationParser.trim(optWhitespace),
133-
expressionParser,
134-
).map(
135-
([variable, operation, expression]) =>
136-
new LetCommand({
137-
operation,
138-
variable,
139-
expression,
140-
lock,
141-
}),
142-
),
133+
expressionParser.fallback(undefined),
134+
all,
135+
).map(([variable, operation, expression, trailing]) => {
136+
if (expression === undefined) {
137+
throw VimError.InvalidExpression(trailing);
138+
}
139+
if (trailing) {
140+
throw VimError.TrailingCharacters(trailing);
141+
}
142+
return new LetCommand({
143+
operation,
144+
variable,
145+
expression,
146+
lock,
147+
});
148+
}),
143149
),
144150
// `:let`
145151
// `:let {var-name} ...`

src/vimscript/exCommandParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,11 @@ export const exCommandParser: Parser<{ lineRange: LineRange | undefined; command
691691
}
692692
throw VimError.InvalidArgument474();
693693
}
694-
const [command, remaining] = result.value;
695-
if (remaining) {
694+
const [command, trailing] = result.value;
695+
if (trailing) {
696696
// TODO: Implement `:help :bar`
697697
// TODO: Implement `:help :comment`
698-
throw VimError.TrailingCharacters(remaining);
698+
throw VimError.TrailingCharacters(trailing);
699699
}
700700
return { lineRange, command };
701701
});

0 commit comments

Comments
 (0)