Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 80f3ad4

Browse files
vsavkinmhevery
authored andcommitted
fix(parser): changes parser to throw an error when it encounters an unexpected token
Change the handling of unexpected tokens. Make the parser throw the "is an unexpected token" exception, so ExpressionVisitor won't throw confusing "Can not watch expression containing ';'". Closes #830 Closes #905
1 parent 19d61f7 commit 80f3ad4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/core/parser/dynamic_parser_impl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class DynamicParserImpl {
4040
if (isChain && expr is Filter) {
4141
error('Cannot have a filter in a chain');
4242
}
43+
if (!isChain && index < tokens.length) {
44+
error("'${next}' is an unexpected token", index);
45+
}
4346
}
4447
return (expressions.length == 1)
4548
? expressions.first

test/core/parser/parser_spec.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ main() {
194194
expectEval("4()").toThrow('4 is not a function');
195195
});
196196

197+
it("should throw on an unexpected token", (){
198+
expectEval("[1,2] trac")
199+
.toThrow('Parser Error: \'trac\' is an unexpected token at column 7 in [[1,2] trac]');
200+
});
197201

198202
it('should fail gracefully when invoking non-function', () {
199203
expect(() {

0 commit comments

Comments
 (0)