Permalink
Browse files

Fix osh2oil.sh tests.

'test/osh2oil.sh all-passing' now passes again.

- Fix basic breakage
- Fix breakages due to osh.asdl schema change: brace group, subshell,
  while, if, case
  • Loading branch information...
Andy Chu
Andy Chu committed Jul 28, 2017
1 parent 82aa68f commit 61ba42dce214628e4db556b9f65f4f67b56e5256
Showing with 21 additions and 13 deletions.
  1. +2 −0 bin/oil.py
  2. +1 −1 test/osh2oil.sh
  3. +18 −12 tools/osh2oil.py
View
@@ -371,6 +371,8 @@ def OshMain(argv):
if do_exec:
tlog('Execute(node)')
status = ex.Execute(node)
else:
status = 0
return status
View
@@ -8,7 +8,7 @@ set -o pipefail
set -o errexit
osh-to-oil() {
bin/osh --no-exec --fix "$@"
bin/osh --fix "$@"
}
fail() {
View
@@ -554,7 +554,7 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
elif node.tag == command_e.Sentence:
# 'ls &' to 'fork ls'
# Keep ; the same.
self.DoCommand(node.command, local_symbols)
self.DoCommand(node.child, local_symbols)
# This has to be different in the function case.
elif node.tag == command_e.BraceGroup:
@@ -580,8 +580,7 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
self.cursor.SkipUntil(left_spid + 1)
self.f.write('shell {')
for c in node.children:
self.DoCommand(c, local_symbols)
self.DoCommand(node.child, local_symbols)
#self._DebugSpid(right_spid)
#self._DebugSpid(right_spid + 1)
@@ -636,7 +635,8 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
self.cursor.SkipUntil(do_spid + 1)
self.f.write('{')
self.DoCommand(node.child, local_symbols)
for child in node.children:
self.DoCommand(child, local_symbols)
self.cursor.PrintUntil(done_spid)
self.cursor.SkipUntil(done_spid + 1)
@@ -673,8 +673,9 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
pass
elif node.tag == command_e.While:
if node.cond.tag == command_e.Sentence:
spid = node.cond.terminator.span_id
cond = node.cond
if len(cond) == 1 and cond[0].tag == command_e.Sentence:
spid = cond[0].terminator.span_id
self.cursor.PrintUntil(spid)
self.cursor.SkipUntil(spid + 1)
@@ -691,22 +692,25 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
self.cursor.PrintUntil(elif_spid)
self.f.write('} ')
if arm.cond.tag == command_e.Sentence:
sentence = arm.cond
cond = arm.cond
if len(cond) == 1 and cond[0].tag == command_e.Sentence:
sentence = cond[0]
self.DoCommand(sentence, local_symbols)
# Remove semi-colon
semi_spid = sentence.terminator.span_id
self.cursor.PrintUntil(semi_spid)
self.cursor.SkipUntil(semi_spid + 1)
else:
self.DoCommand(arm.cond, local_symbols)
for child in arm.cond:
self.DoCommand(child, local_symbols)
self.cursor.PrintUntil(then_spid)
self.cursor.SkipUntil(then_spid + 1)
self.f.write('{')
self.DoCommand(arm.action, local_symbols)
for child in arm.action:
self.DoCommand(child, local_symbols)
# else -> } else {
if node.else_action:
@@ -715,7 +719,8 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
self.cursor.PrintUntil(else_spid + 1)
self.f.write(' {')
self.DoCommand(node.else_action, local_symbols)
for child in node.else_action:
self.DoCommand(child, local_symbols)
# fi -> }
self.cursor.PrintUntil(fi_spid)
@@ -760,7 +765,8 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
self.cursor.SkipUntil(rparen_spid + 1)
self.f.write(' {') # surround it with { }
self.DoCommand(arm.action, local_symbols)
for child in arm.action:
self.DoCommand(child, local_symbols)
if dsemi_spid != -1:
self.cursor.PrintUntil(dsemi_spid)

0 comments on commit 61ba42d

Please sign in to comment.