Do not handle ampersand as an argument in subprocess mode

This removes ambiguity of ampersand string literal. Allows for
passing a single quoted ampersand as the last subprocess argument.
This commit is contained in:
David Strobach 2020-04-01 02:44:33 +02:00
parent 0d8c0b613a
commit 5236239078
2 changed files with 13 additions and 7 deletions

View file

@ -887,9 +887,6 @@ def cmds_to_specs(cmds, captured=False):
if isinstance(cmd, str):
redirects.append(cmd)
else:
if cmd[-1] == "&":
cmd = cmd[:-1]
redirects.append("&")
spec = SubprocSpec.build(cmd, captured=captured)
spec.pipeline_index = i
specs.append(spec)
@ -903,7 +900,7 @@ def cmds_to_specs(cmds, captured=False):
specs[i].stdout = w
specs[i + 1].stdin = r
elif redirect == "&" and i == len(redirects) - 1:
specs[-1].background = True
specs[i].background = True
else:
raise XonshError("unrecognized redirect {0!r}".format(redirect))
# Apply boundary conditions

View file

@ -2984,6 +2984,14 @@ class BaseParser(object):
"""
p[0] = ast.Str(s="|", lineno=self.lineno, col_offset=self.col)
def p_amper(self, p):
"""amper : AMPERSAND
| WS AMPERSAND
| AMPERSAND WS
| WS AMPERSAND WS
"""
p[0] = ast.Str(s="&", lineno=self.lineno, col_offset=self.col)
def p_subproc_s2(self, p):
"""subproc : subproc_atoms
| subproc_atoms WS
@ -2991,10 +2999,10 @@ class BaseParser(object):
p1 = p[1]
p[0] = [self._subproc_cliargs(p1, lineno=self.lineno, col=self.col)]
def p_subproc_amp(self, p):
"""subproc : subproc AMPERSAND"""
def p_subproc_amper(self, p):
"""subproc : subproc amper"""
p1 = p[1]
p[0] = p1 + [ast.Str(s=p[2], lineno=self.lineno, col_offset=self.col)]
p[0] = p1 + [p[2]]
def p_subproc_pipe(self, p):
"""subproc : subproc pipe subproc_atoms
@ -3257,6 +3265,7 @@ class BaseParser(object):
"DOLLAR_LBRACE",
"DOLLAR_LBRACKET",
"ATDOLLAR_LPAREN",
"AMPERSAND",
}
ts = "\n | ".join(sorted([t.lower() + "_tok" for t in toks]))
doc = "subproc_arg_part : " + ts + "\n"