Permalink
Browse files

Fix bug in last commit. Both branches need assign_op.

  • Loading branch information...
Andy Chu
Andy Chu committed Aug 8, 2017
1 parent 9914e82 commit 91bdb8afc364aa8d5f197d61496670bfab5240c3
Showing with 11 additions and 9 deletions.
  1. +3 −1 core/completion_test.py
  2. +8 −8 osh/cmd_parse.py
View
@@ -23,6 +23,8 @@
from osh import ast_ as ast
from osh import parse_lib
assign_op = ast.assign_op
A1 = completion.WordsAction(['foo.py', 'foo', 'bar.py'])
@@ -78,7 +80,7 @@ def testShellFuncExecution(self):
w.parts.append(a)
# Set global COMPREPLY=(f1 f2)
pairs = [ast.assign_pair(ast.LhsName('COMPREPLY'), w)]
pairs = [ast.assign_pair(ast.LhsName('COMPREPLY'), assign_op.Equal, w)]
body_node = ast.Assignment(Id.Assign_None, [], pairs)
func_node.body = body_node
View
@@ -445,10 +445,8 @@ def _MakeSimpleCommand(self, prefix_bindings, suffix_words, redirects):
return node
def _MakeAssignment(self, assign_kw, suffix_words):
flags = []
bindings = []
# First parse flags, e.g. -r -x -a -A. None of the flags have arguments.
flags = []
n = len(suffix_words)
i = 1
while i < n:
@@ -464,6 +462,7 @@ def _MakeAssignment(self, assign_kw, suffix_words):
i += 1
# Now parse bindings or variable names
assignments = []
while i < n:
w = suffix_words[i]
left_spid = word.LeftMostSpanForWord(w)
@@ -473,9 +472,9 @@ def _MakeAssignment(self, assign_kw, suffix_words):
t = word.TildeDetect(v)
if t:
# t is an unevaluated word with TildeSubPart
pair = (k, op, t, left_spid)
a = (k, op, t, left_spid)
else:
pair = (k, op, v, left_spid) # v is unevaluated word
a = (k, op, v, left_spid) # v is unevaluated word
else:
# In aboriginal in variables/sources: export_if_blank does export "$1".
# We should allow that.
@@ -489,18 +488,19 @@ def _MakeAssignment(self, assign_kw, suffix_words):
'Variable names must be constant strings, got %s', w, word=w)
return None
pair = (static_val, None, left_spid) # No value is equivalent to ''
# No value is equivalent to ''
m = VAR_NAME_RE.match(static_val)
if not m:
self.AddErrorContext('Invalid variable name %r', static_val, word=w)
return None
a = (static_val, assign_op.Equal, None, left_spid)
bindings.append(pair)
assignments.append(a)
i += 1
# TODO: Also make with LhsIndexedName
pairs = []
for lhs, op, rhs, spid in bindings:
for lhs, op, rhs, spid in assignments:
p = ast.assign_pair(ast.LhsName(lhs), op, rhs)
p.spids.append(spid)
pairs.append(p)

0 comments on commit 91bdb8a

Please sign in to comment.