Skip to content

Commit cfdb571

Browse files
Added support for redirect nodes
1 parent ccadb01 commit cfdb571

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

bashparser/ast.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, root):
2020
self.no_children = {'operator', 'reservedword', 'pipe', 'parameter', 'tilde', 'heredoc'}
2121
self.parts_children = {'list', 'pipeline', 'if', 'for', 'while', 'until', 'command', 'function', 'word', 'assignment'}
2222
self.command_children = {'commandsubstitution', 'processsubstitution'}
23-
self.passable_nodes = {'command', 'list', 'compound', 'for', 'parameter', 'function', 'pipeline', 'if', 'while'}
23+
self.passable_nodes = {'command', 'list', 'for', 'parameter', 'function', 'pipeline', 'if', 'while'}
2424
self.list_children = {}
2525
self.contains_variable_text = {'word', 'assignment'}
2626

@@ -38,6 +38,15 @@ def apply_fn(node):
3838
if node.kind in self.passable_nodes: return CONT
3939
elif node.kind == 'operator': word = node.op
4040
elif node.kind == 'pipe': word = node.pipe
41+
elif node.kind == 'redirect': word = node.type + ' '
42+
elif node.kind == 'compound':
43+
for part in node.list:
44+
word += str(NodeVisitor(part)) + ' '
45+
if hasattr(node, 'redirects'):
46+
for part in node.redirects:
47+
word += str(NodeVisitor(part)) + ' '
48+
self._string = self._string + word + ' '
49+
return DONT_DESCEND
4150
elif node.kind == 'commandsubstitution':
4251
word = '$('
4352
cmd = node.command

0 commit comments

Comments
 (0)