Permalink
Browse files

Work on osh2oil

- Add support for time block translation
  - Make note of failing case
- Stub out here doc translation
  • Loading branch information...
Andy Chu
Andy Chu committed Jul 30, 2017
1 parent 1c85bfc commit a6bc98eb244adf407c518b361156963621486445
Showing with 68 additions and 21 deletions.
  1. +33 −0 test/osh2oil.sh
  2. +35 −21 tools/osh2oil.py
View
@@ -853,6 +853,38 @@ echo "$HOME/name with spaces"
OIL
}
time-block() {
osh0-oil3 << 'OSH' 3<< 'OIL'
time ls
OSH
time ls
OIL
osh0-oil3 << 'OSH' 3<< 'OIL'
time while false; do
echo $i
done
OSH
time while false {
echo $i
}
OIL
return
# TODO: The "do" has to be removed
osh0-oil3 << 'OSH' 3<< 'OIL'
time {
echo one
echo two
}
OSH
time {
echo one
echo two
}
OIL
}
all-passing() {
simple-command
more-env
@@ -883,6 +915,7 @@ all-passing() {
for-loop
empty-for-loop
args-for-loop
time-block
# Builtins
bracket-builtin
View
@@ -16,6 +16,7 @@
log = util.log
command_e = ast.command_e
redir_e = ast.redir_e
word_e = ast.word_e
word_part_e = ast.word_part_e
arith_expr_e = ast.arith_expr_e
@@ -237,29 +238,39 @@ def DoRedirect(self, node, local_symbols):
# - How to handle here docs and here docs?
# - >> becomes >+ or >-, or maybe >>>
if node.fd == -1:
if node.op_id == Id.Redir_Great:
self.f.write('>') # Allow us to replace the operator
self.cursor.SkipUntil(node.spids[0] + 1)
elif node.op_id == Id.Redir_GreatAnd:
self.f.write('> !') # Replace >& 2 with > !2
spid = word.LeftMostSpanForWord(node.arg_word)
self.cursor.SkipUntil(spid)
#self.DoWordInCommand(node.arg_word)
if node.tag == redir_e.Redir:
if node.fd == -1:
if node.op_id == Id.Redir_Great:
self.f.write('>') # Allow us to replace the operator
self.cursor.SkipUntil(node.spids[0] + 1)
elif node.op_id == Id.Redir_GreatAnd:
self.f.write('> !') # Replace >& 2 with > !2
spid = word.LeftMostSpanForWord(node.arg_word)
self.cursor.SkipUntil(spid)
#self.DoWordInCommand(node.arg_word)
else:
# NOTE: Spacing like !2>err.txt vs !2 > err.txt can be done in the
# formatter.
self.f.write('!%d ' % node.fd)
if node.op_id == Id.Redir_Great:
self.f.write('>')
self.cursor.SkipUntil(node.spids[0] + 1)
elif node.op_id == Id.Redir_GreatAnd:
self.f.write('> !') # Replace 1>& 2 with !1 > !2
spid = word.LeftMostSpanForWord(node.arg_word)
self.cursor.SkipUntil(spid)
self.DoWordInCommand(node.arg_word, local_symbols)
elif node.tag == redir_e.HereDoc:
# TODO:
# If do_expansion, then """, else '''
# HereDoc LST node needs spids for both opening and closing delimiter.
raise NotImplementedError
else:
# NOTE: Spacing like !2>err.txt vs !2 > err.txt can be done in the
# formatter.
self.f.write('!%d ' % node.fd)
if node.op_id == Id.Redir_Great:
self.f.write('>')
self.cursor.SkipUntil(node.spids[0] + 1)
elif node.op_id == Id.Redir_GreatAnd:
self.f.write('> !') # Replace 1>& 2 with !1 > !2
spid = word.LeftMostSpanForWord(node.arg_word)
self.cursor.SkipUntil(spid)
self.DoWordInCommand(node.arg_word, local_symbols)
raise AssertionError(node.tag)
# <<< 'here word'
# << 'here word'
@@ -791,6 +802,9 @@ def DoCommand(self, node, local_symbols, at_top_level=False):
elif node.tag == command_e.NoOp:
pass
elif node.tag == command_e.TimeBlock:
self.DoCommand(node.pipeline, local_symbols)
else:
log('Command not handled: %s', node)
raise AssertionError(node.tag)

0 comments on commit a6bc98e

Please sign in to comment.