Permalink
Browse files

Add location info to error message.

Found in setup.sh of Nix.

  for i in "${nativePkgs[@]}"; do
            ^~
osh failed: Can't index string with @: (Str s:"")
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 7, 2017
1 parent 8dde7f4 commit eca488a8568d4a9f67431d3cc939bea64a40ad46
Showing with 10 additions and 7 deletions.
  1. +2 −0 core/ui.py
  2. +1 −0 core/util.py
  3. +5 −5 core/word.py
  4. +2 −2 core/word_eval.py
View
@@ -93,6 +93,8 @@ def PrettyPrintError(parse_error, arena, f):
#print(parse_error)
if parse_error.token:
span_id = parse_error.token.span_id
elif parse_error.part:
span_id = word.LeftMostSpanForPart(parse_error.part)
elif parse_error.word:
# Can be -1
span_id = word.LeftMostSpanForWord(parse_error.word)
View
@@ -38,6 +38,7 @@ def __init__(self, msg, *args, **kwargs):
# NOTE: We use a kwargs dict because Python 2 doesn't have keyword-only
# args.
self.token = kwargs.pop('token', None)
self.part = kwargs.pop('part', None)
self.word = kwargs.pop('word', None)
self.exit_status = kwargs.pop('status', None)
if kwargs:
View
@@ -95,7 +95,7 @@ def StaticEval(w):
return True, ret, quoted
def _LeftMostSpanForPart(part):
def LeftMostSpanForPart(part):
# TODO: Write unit tests in ui.py for error values
#from core.id_kind import IdName
@@ -119,7 +119,7 @@ def _LeftMostSpanForPart(part):
elif part.tag == word_part_e.DoubleQuotedPart:
if part.parts:
return _LeftMostSpanForPart(part.parts[0])
return LeftMostSpanForPart(part.parts[0])
else:
# We need the double quote location
return -1
@@ -169,7 +169,7 @@ def _RightMostSpanForPart(part):
elif part.tag == word_part_e.DoubleQuotedPart:
if part.parts:
return _LeftMostSpanForPart(part.parts[-1])
return LeftMostSpanForPart(part.parts[-1])
else:
# We need the double quote location
return -1
@@ -215,12 +215,12 @@ def LeftMostSpanForWord(w):
if len(w.parts) == 0:
return -1
elif len(w.parts) == 1:
return _LeftMostSpanForPart(w.parts[0])
return LeftMostSpanForPart(w.parts[0])
else:
begin = w.parts[0]
# TODO: We need to combine LineSpan()? If they're both on the same line,
# return them both. If they're not, then just use "begin"?
return _LeftMostSpanForPart(begin)
return LeftMostSpanForPart(begin)
# It's a TokenWord?
return w.token.span_id
View
@@ -707,7 +707,7 @@ def _EvalBracedVarSub(self, part, quoted):
if val.tag == value_e.Undef:
val = self._EmptyStrArrayOrError(part.token)
elif val.tag == value_e.Str:
raise RuntimeError("Can't index string with @")
e_die("Can't index string with @: %r", val, part=part)
elif val.tag == value_e.StrArray:
val = runtime.StrArray(val.strs)
@@ -716,7 +716,7 @@ def _EvalBracedVarSub(self, part, quoted):
if val.tag == value_e.Undef:
val = self._EmptyStrArrayOrError(part.token)
elif val.tag == value_e.Str:
raise RuntimeError("Can't index string with *")
e_die("Can't index string with *: %r", val, part=part)
elif val.tag == value_e.StrArray:
# Always decay_array with ${a[*]} or "${a[*]}"
val = runtime.StrArray(val.strs)

0 comments on commit eca488a

Please sign in to comment.