From e8c3dc7ce668a469a66a781d557e4d94dca13aa5 Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Tue, 15 Apr 2014 14:20:41 -0400 Subject: [PATCH] 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 --- lib/core/parser/dynamic_parser_impl.dart | 3 +++ test/core/parser/parser_spec.dart | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/core/parser/dynamic_parser_impl.dart b/lib/core/parser/dynamic_parser_impl.dart index a7b5ab8af..743d6b877 100644 --- a/lib/core/parser/dynamic_parser_impl.dart +++ b/lib/core/parser/dynamic_parser_impl.dart @@ -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 diff --git a/test/core/parser/parser_spec.dart b/test/core/parser/parser_spec.dart index e00f04813..b14aa8c3c 100644 --- a/test/core/parser/parser_spec.dart +++ b/test/core/parser/parser_spec.dart @@ -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(() {