From 9ef3670ea247df0e5d55bf27954fc69c6c130b61 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Mon, 13 Mar 2017 11:04:07 +0200 Subject: [PATCH] Improved error messages --- lark/load_grammar.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index b4838f7..dc4cacb 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -542,9 +542,11 @@ class GrammarLoader: except UnexpectedInput as e: raise GrammarError("Unexpected input %r at line %d column %d in %s" % (e.context, e.line, e.column, name)) except UnexpectedToken as e: - if '_COLON' in e.expected: + if e.expected == ['_COLON']: raise GrammarError("Missing colon at line %s column %s" % (e.line, e.column)) - elif 'literal' in e.expected: + elif e.expected == ['RULE']: + raise GrammarError("Missing alias at line %s column %s" % (e.line, e.column)) + elif 'STRING' in e.expected: raise GrammarError("Expecting a value at line %s column %s" % (e.line, e.column)) elif e.expected == ['_OR']: raise GrammarError("Newline without starting a new option (Expecting '|') at line %s column %s" % (e.line, e.column))