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

Commit

Permalink
fix(parser): changes parser to throw an error when it encounters an u…
Browse files Browse the repository at this point in the history
…nexpected 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
  • Loading branch information
vsavkin authored and mhevery committed Apr 17, 2014
1 parent 19d61f7 commit 80f3ad4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/core/parser/dynamic_parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class DynamicParserImpl {
if (isChain && expr is Filter) {
error('Cannot have a filter in a chain');
}
if (!isChain && index < tokens.length) {
error("'${next}' is an unexpected token", index);
}
}
return (expressions.length == 1)
? expressions.first
Expand Down
4 changes: 4 additions & 0 deletions test/core/parser/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ main() {
expectEval("4()").toThrow('4 is not a function');
});

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

it('should fail gracefully when invoking non-function', () {
expect(() {
Expand Down

0 comments on commit 80f3ad4

Please sign in to comment.