Permalink
Browse files

[osh2oil] Tweaks to avoid crashes.

- Avoid a crash in the special case of the empty file.
  - The line_id is -1 only in that case, which makes logical sense, but
    caused a crash.
  - We might want to have no zero-length spans then?  Or say that
    Eof_Real doesn't produce a span?

- Don't crash on ExtGlobPart.  Though I'm not sure exactly how to
  translate this.

Also: categorize a few more wild errors.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 8, 2018
1 parent 1aae97c commit fedbf4c5a390507d8df7dfc5c6f8a2987a2359e5
Showing with 26 additions and 0 deletions.
  1. +6 −0 test/wild-not-osh.txt
  2. +3 −0 test/wild-not-shell.txt
  3. +17 −0 tools/osh2oil.py
View
@@ -11,3 +11,9 @@ esoteric/setup.shl/bin/setup # associative array ambiguity (key should be quote
exp/shootout/timing.sh # the $(( )) ambiguity
linux-4.8.7/tools/perf/perf-with-kcore.sh # another $(( )) ambiguity
# These four have unexpected arguments to exit. We statically parse that.
shell/modernish/uninstall.sh
shell/modernish/share/doc/modernish/examples/get-firefox.sh
shell/modernish/share/doc/modernish/examples/copy-timestamps.sh
shell/modernish/share/doc/modernish/examples/testshells.sh
View
@@ -18,3 +18,6 @@ freebsd-11.1/usr.bin/tr/tests/regress.sh
freebsd-11.1/usr.bin/sed/tests/regress.sh
freebsd-11.1/usr.bin/join/tests/regress.sh
linux-4.8.7/tools/perf/perf-completion.sh
# This is awk, not shell!
linux-4.8.7/scripts/ld-version.sh
View
@@ -70,6 +70,11 @@ def PrintArena(arena):
def PrintSpans(arena):
"""Just to see spans."""
if len(arena.spans) == 1: # Special case for line_id == -1
print('Empty file with EOF span on invalid line:')
print('%s' % arena.spans[0])
return
for i, span in enumerate(arena.spans):
line = arena.GetLine(span.line_id)
piece = line[span.col : span.col + span.length]
@@ -78,6 +83,10 @@ def PrintSpans(arena):
def PrintAsOil(arena, node, debug_spans):
if len(arena.spans) == 1: # Special case for line_id == -1
# Nothing to print; would crash otherwise.
return
#print node
#print(spans)
if debug_spans:
@@ -1277,6 +1286,14 @@ def DoWordPart(self, node, local_symbols, quoted=False):
elif node.tag == word_part_e.EmptyPart:
pass
elif node.tag == word_part_e.ExtGlobPart:
# Change this into a function? It depends whether it is used as
# a glob or fnmatch.
#
# Example of glob:
# cloud/sandstorm/make-bundle.sh
pass
else:
raise AssertionError(node.__class__.__name__)

0 comments on commit fedbf4c

Please sign in to comment.