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

fix(parser): changes parser to throw an error when it encounters an unexpected token #905

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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