rearrange, and make pathsearch work in subproc mode

This commit is contained in:
adam j hartz 2016-06-16 00:46:06 -04:00
parent c88a49227f
commit 478f1451f3

View file

@ -112,12 +112,23 @@ def xonsh_superhelp(x, lineno=None, col=None):
return xonsh_call('__xonsh_superhelp__', [x], lineno=lineno, col=col)
def xonsh_pathsearch(func, s, pymode=False, lineno=None, col=None):
def xonsh_pathsearch(pattern, pymode=False, lineno=None, col=None):
"""Creates the AST node for calling the __xonsh_pathsearch__() function.
The pymode argument indicate if it is called from subproc or python mode"""
pymode = ast.NameConstant(value=pymode, lineno=lineno, col_offset=col)
return xonsh_call('__xonsh_pathsearch__', args=[func, s, pymode], lineno=lineno,
col=col)
searchfunc, pattern = re.match(SearchPath, pattern).groups()
pattern = ast.Str(s=pattern, lineno=lineno,
col_offset=col)
if searchfunc in {'r', ''}:
func = '__xonsh_regexsearch__'
elif searchfunc == 'g':
func = '__xonsh_globsearch__'
else:
func = searchfunc[1:] # remove the '@' character
func = ast.Name(id=func, ctx=ast.Load(), lineno=lineno,
col_offset=col)
return xonsh_call('__xonsh_pathsearch__', args=[func, pattern, pymode],
lineno=lineno, col=col)
def load_ctx(x):
@ -1714,19 +1725,8 @@ class BaseParser(object):
def p_atom_pathsearch(self, p):
"""atom : SEARCHPATH"""
searchfunc, pattern = re.match(SearchPath, p[1]).groups()
pattern = ast.Str(s=pattern, lineno=self.lineno,
col_offset=self.col)
if searchfunc in {'r', ''}:
func = '__xonsh_regexsearch__'
elif searchfunc == 'g':
func = '__xonsh_globsearch__'
else:
func = searchfunc[1:] # remove the '@' character
func = ast.Name(id=func, ctx=ast.Load(), lineno=self.lineno,
col_offset=self.col)
p[0] = xonsh_pathsearch(func, pattern, pymode=True,
lineno=self.lineno, col=self.col)
p[0] = xonsh_pathsearch(p[1], pymode=True, lineno=self.lineno,
col=self.col)
def p_atom_dname(self, p):
"""atom : DOLLAR_NAME"""
@ -2225,9 +2225,7 @@ class BaseParser(object):
def p_subproc_atom_re(self, p):
"""subproc_atom : SEARCHPATH"""
p1 = ast.Str(s=p[1], lineno=self.lineno,
col_offset=self.col)
p0 = xonsh_pathsearch(p1, pymode=False, lineno=self.lineno,
p0 = xonsh_pathsearch(p[1], pymode=False, lineno=self.lineno,
col=self.col)
p0._cliarg_action = 'extend'
p[0] = p0