Permalink
Browse files

Remove the older form of parse error handling.

Simplify parsing of $PS4 as well.

All unit tests and spec tests pass.
  • Loading branch information...
Andy Chu
Andy Chu committed Aug 30, 2018
1 parent cae0c27 commit fd737dd1cf408af2dbc1cc770184aa3a89cfcfca
Showing with 14 additions and 50 deletions.
  1. +3 −28 bin/oil.py
  2. +2 −22 core/cmd_exec.py
  3. +9 −0 osh/word_parse.py
View
@@ -127,20 +127,7 @@ def InteractiveLoop(opts, ex, c_parser, arena):
c_parser.Reset()
c_parser.ResetInputObjects()
continue
#log('parsed node: %s', node)
# Failed parse.
# TODO: Need an error for an empty command, which we ignore? GetLine
# could do that in the first position?
# ParseSimpleCommand fails with '\n' token?
if not node:
e = c_parser.Error()
# NOTE: This is a bit verbose.
ui.PrintErrorStack(e, arena)
c_parser.Reset()
c_parser.ResetInputObjects()
continue
assert node is not None
if ast_f:
ast_lib.PrettyPrint(node)
@@ -333,13 +320,7 @@ def OshMain(argv0, argv, login_shell):
except util.ParseError as e:
ui.PrettyPrintError(e, arena, sys.stderr)
return 2
else:
# TODO: Remove this older form of error handling.
if not node:
err = c_parser.Error()
assert err, err # can't be empty
ui.PrintErrorStack(err, arena)
return 2 # parse error is code 2
assert node is not None
do_exec = True
if opts.fix:
@@ -506,13 +487,7 @@ def OshCommandMain(argv):
except util.ParseError as e:
ui.PrettyPrintError(e, arena, sys.stderr)
return 2
else:
# TODO: Remove this older form of error handling.
if not node:
err = c_parser.Error()
assert err, err # can't be empty
ui.PrintErrorStack(err, arena)
return 2 # parse error is code 2
assert node is not None
f.close()
View
@@ -218,19 +218,11 @@ def ParseTrapCode(self, code_str):
self.arena.PushSource(source_name)
try:
# TODO: Get rid of duplicate error handling:
err = None
try:
node = c_parser.ParseWholeFile()
except util.ParseError as e:
err = e
else:
if not node:
err = c_parser.Error()
if err:
util.error('Parse error in %r:', source_name)
ui.PrintErrorStack(err, self.arena, sys.stderr)
ui.PrettyPrintError(e, self.arena, sys.stderr)
return None
finally:
@@ -1482,21 +1474,9 @@ def _EvalPS4(self):
# We have to parse this at runtime. PS4 should usually remain constant.
w_parser = parse_lib.MakeWordParserForPlugin(ps4, self.arena)
# NOTE: Reading PS4 is just like reading a here doc line. "\n" is
# allowed too. The OUTER mode would stop at spaces, and ReadWord
# doesn't allow lex_mode_e.DQ.
ok = True
ps4_word = ast.CompoundWord()
try:
w_parser.ReadHereDocBody(ps4_word.parts)
ps4_word = w_parser.ReadPS()
except util.ParseError as e:
ok = False
else:
# TODO: Get rid of duplicate forms of error handling.
if not ps4_word:
ok = False
if not ok:
error_str = '<ERROR: cannot parse PS4>'
t = ast.token(Id.Lit_Chars, error_str, const.NO_INTEGER)
ps4_word = ast.CompoundWord([ast.LiteralPart(t)])
View
@@ -1160,3 +1160,12 @@ def ReadHereDocBody(self, parts):
"""
self._ReadLikeDQ(None, parts)
# Returns nothing
def ReadPS(self):
"""For $PS1, $PS4, etc."""
# NOTE: Reading PS4 is just like reading a here doc line. "\n" is allowed
# too. The OUTER mode would stop at spaces, and ReadWord doesn't allow
# lex_mode_e.DQ.
w = ast.CompoundWord()
self._ReadLikeDQ(None, w.parts)
return w

0 comments on commit fd737dd

Please sign in to comment.