Permalink
Browse files

Prettify error messages in the BoolParser.

There is less detail now, but the messages look better.  We don't have a
great way to print an arbitrary word, so we just point to a position.

Addresses issue #27 and #103.
  • Loading branch information...
Andy Chu
Andy Chu committed Aug 22, 2018
1 parent e19cee4 commit ec4582f2b4de7ae81a122d2c318cd1979eaee889
Showing with 6 additions and 10 deletions.
  1. +6 −9 osh/bool_parse.py
  2. +0 −1 osh/cmd_parse.py
View
@@ -43,6 +43,7 @@
lex_mode_e = types.lex_mode_e
log = util.log
p_die = util.p_die
class BoolParser(object):
@@ -125,9 +126,8 @@ def Parse(self):
node = self.ParseExpr()
if self.op_id != Id.Lit_DRightBracket:
self.AddErrorContext("Unexpected extra word %r", self.cur_word,
word=self.cur_word)
return None
#p_die("Expected ]], got %r", self.cur_word, word=self.cur_word)
p_die('Expected ]]', word=self.cur_word)
return node
def _TestAtEnd(self):
@@ -247,8 +247,7 @@ def ParseFactor(self):
# doesn't contain $foo, etc.
if ok and not libc.regex_parse(regex_str):
self.AddErrorContext("Invalid regex: %r" % regex_str, word=right)
return None
p_die("Invalid regex: %r" % regex_str, word=right)
if not self._Next(): return None
return ast.BoolBinary(op, left, right)
@@ -268,7 +267,5 @@ def ParseFactor(self):
if not self._Next(): return None
return node
# TODO: A proper error, e.g. for [[ && ]] or [[ ]]
self.AddErrorContext(
'Unexpected token: %s' % self.cur_word, word=self.cur_word)
return None
# It's not WORD, UNARY_OP, or '('
p_die('Unexpected token in boolean expression', word=self.cur_word)
View
@@ -1219,7 +1219,6 @@ def ParseDBracket(self):
if not bnode:
error_stack = b_parser.Error()
self.error_stack.extend(error_stack)
self.AddErrorContext("Error parsing [[", word=maybe_error_word)
return None
return ast.DBracket(bnode)

0 comments on commit ec4582f

Please sign in to comment.