mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 17:30:59 +01:00
some clean up
This commit is contained in:
parent
a78ada5c3f
commit
699d6ae714
2 changed files with 37 additions and 23 deletions
|
@ -736,7 +736,7 @@ def convert_macro_arg(raw_arg, kind, glbs, locs, *, name='<arg>',
|
||||||
"""
|
"""
|
||||||
# munge kind and mode to start
|
# munge kind and mode to start
|
||||||
mode = None
|
mode = None
|
||||||
if isinstance(kind, abc.Sequence) and not isinstance(kind, str):
|
if isinstance(kind, cabc.Sequence) and not isinstance(kind, str):
|
||||||
# have (kind, mode) tuple
|
# have (kind, mode) tuple
|
||||||
kind, mode = kind
|
kind, mode = kind
|
||||||
if isinstance(kind, str):
|
if isinstance(kind, str):
|
||||||
|
@ -823,6 +823,7 @@ def call_macro(f, raw_args, glbs, locs):
|
||||||
empty = inspect.Parameter.empty
|
empty = inspect.Parameter.empty
|
||||||
macroname = f.__name__
|
macroname = f.__name__
|
||||||
args = []
|
args = []
|
||||||
|
print(raw_args)
|
||||||
for (key, param), raw_arg in zip(sig.parameters.items(), raw_args):
|
for (key, param), raw_arg in zip(sig.parameters.items(), raw_args):
|
||||||
kind = param.annotation
|
kind = param.annotation
|
||||||
if kind is empty or kind is None:
|
if kind is empty or kind is None:
|
||||||
|
|
|
@ -429,7 +429,7 @@ class BaseParser(object):
|
||||||
return ''.join(lines)
|
return ''.join(lines)
|
||||||
|
|
||||||
def _parse_error(self, msg, loc):
|
def _parse_error(self, msg, loc):
|
||||||
if self.xonsh_code is None:
|
if self.xonsh_code is None or loc is None:
|
||||||
err_line_pointer = ''
|
err_line_pointer = ''
|
||||||
else:
|
else:
|
||||||
col = loc.column + 1
|
col = loc.column + 1
|
||||||
|
@ -1672,11 +1672,13 @@ class BaseParser(object):
|
||||||
p0 = ast.Call(func=leader,
|
p0 = ast.Call(func=leader,
|
||||||
lineno=leader.lineno,
|
lineno=leader.lineno,
|
||||||
col_offset=leader.col_offset, **trailer)
|
col_offset=leader.col_offset, **trailer)
|
||||||
elif isinstance(trailer, ast.Tuple):
|
elif isinstance(trailer, (ast.Tuple, tuple)):
|
||||||
# call macro functions
|
# call macro functions
|
||||||
l, c = leader.lineno, leader.col_offset
|
l, c = leader.lineno, leader.col_offset
|
||||||
gblcall = xonsh_call('globals', [], lineno=l, col=c)
|
gblcall = xonsh_call('globals', [], lineno=l, col=c)
|
||||||
loccall = xonsh_call('locals', [], lineno=l, col=c)
|
loccall = xonsh_call('locals', [], lineno=l, col=c)
|
||||||
|
if isinstance(trailer, tuple):
|
||||||
|
trailer, arglist = trailer
|
||||||
margs = [leader, trailer, gblcall, loccall]
|
margs = [leader, trailer, gblcall, loccall]
|
||||||
p0 = xonsh_call('__xonsh_call_macro__', margs, lineno=l, col=c)
|
p0 = xonsh_call('__xonsh_call_macro__', margs, lineno=l, col=c)
|
||||||
elif isinstance(trailer, str):
|
elif isinstance(trailer, str):
|
||||||
|
@ -1860,17 +1862,18 @@ class BaseParser(object):
|
||||||
p[0] = [p[2] or dict(args=[], keywords=[], starargs=None, kwargs=None)]
|
p[0] = [p[2] or dict(args=[], keywords=[], starargs=None, kwargs=None)]
|
||||||
|
|
||||||
def p_trailer_bang_lparen(self, p):
|
def p_trailer_bang_lparen(self, p):
|
||||||
"""trailer : bang_lparen_tok macroarglist_opt rparen_tok"""
|
"""trailer : bang_lparen_tok macroarglist_opt rparen_tok
|
||||||
|
| bang_lparen_tok nocomma comma_tok rparen_tok
|
||||||
|
| bang_lparen_tok nocomma comma_tok WS rparen_tok
|
||||||
|
| bang_lparen_tok macroarglist comma_tok rparen_tok
|
||||||
|
| bang_lparen_tok macroarglist comma_tok WS rparen_tok
|
||||||
|
"""
|
||||||
p1, p2, p3 = p[1], p[2], p[3]
|
p1, p2, p3 = p[1], p[2], p[3]
|
||||||
begins = [(p1.lineno, p1.lexpos + 2)]
|
begins = [(p1.lineno, p1.lexpos + 2)]
|
||||||
ends = [(p3.lineno, p3.lexpos)]
|
ends = [(p3.lineno, p3.lexpos)]
|
||||||
if p2:
|
if p2:
|
||||||
if p2[-1][-1] == 'trailing': # handle trailing comma
|
begins.extend([(x[0], x[1] + 1) for x in p2])
|
||||||
begins.extend([(x[0], x[1] + 1) for x in p2[:-1]])
|
ends = p2 + ends
|
||||||
ends = [x[:2] for x in p2]
|
|
||||||
else:
|
|
||||||
begins.extend([(x[0], x[1] + 1) for x in p2])
|
|
||||||
ends = [x[:2] for x in p2] + ends
|
|
||||||
elts = []
|
elts = []
|
||||||
for beg, end in zip(begins, ends):
|
for beg, end in zip(begins, ends):
|
||||||
s = self.source_slice(beg, end).strip()
|
s = self.source_slice(beg, end).strip()
|
||||||
|
@ -1886,6 +1889,15 @@ class BaseParser(object):
|
||||||
col_offset=p1.lexpos)
|
col_offset=p1.lexpos)
|
||||||
p[0] = [p0]
|
p[0] = [p0]
|
||||||
|
|
||||||
|
#def p_trailer_bang_lparen_star(self, p):
|
||||||
|
# """trailer : bang_lparen_tok macroarglist comma_tok TIMES COMMA arglist rparen_tok"""
|
||||||
|
# self.p_trailer_bang_lparen(p)
|
||||||
|
# assert False
|
||||||
|
#if len(p) == 7:
|
||||||
|
# p[0] = [(p0, p[6])]
|
||||||
|
#else:
|
||||||
|
|
||||||
|
|
||||||
def p_trailer_p3(self, p):
|
def p_trailer_p3(self, p):
|
||||||
"""trailer : LBRACKET subscriptlist RBRACKET
|
"""trailer : LBRACKET subscriptlist RBRACKET
|
||||||
| PERIOD NAME
|
| PERIOD NAME
|
||||||
|
@ -1903,7 +1915,7 @@ class BaseParser(object):
|
||||||
toks -= {'COMMA', 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'LBRACKET',
|
toks -= {'COMMA', 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE', 'LBRACKET',
|
||||||
'RBRACKET', 'AT_LPAREN', 'BANG_LPAREN', 'BANG_LBRACKET',
|
'RBRACKET', 'AT_LPAREN', 'BANG_LPAREN', 'BANG_LBRACKET',
|
||||||
'DOLLAR_LPAREN', 'DOLLAR_LBRACE', 'DOLLAR_LBRACKET',
|
'DOLLAR_LPAREN', 'DOLLAR_LBRACE', 'DOLLAR_LBRACKET',
|
||||||
'ATDOLLAR_LPAREN'}
|
'ATDOLLAR_LPAREN', 'TIMES'}
|
||||||
ts = '\n | '.join(sorted(toks))
|
ts = '\n | '.join(sorted(toks))
|
||||||
doc = 'nocomma_tok : ' + ts + '\n'
|
doc = 'nocomma_tok : ' + ts + '\n'
|
||||||
self.p_nocomma_tok.__func__.__doc__ = doc
|
self.p_nocomma_tok.__func__.__doc__ = doc
|
||||||
|
@ -1938,6 +1950,12 @@ class BaseParser(object):
|
||||||
"""nocomma_part : nocomma_tok"""
|
"""nocomma_part : nocomma_tok"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def p_nocomma_part_times(self, p):
|
||||||
|
"""nocomma_part : TIMES nocomma_part
|
||||||
|
| nocomma_part TIMES
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def p_nocomma_part_any(self, p):
|
def p_nocomma_part_any(self, p):
|
||||||
"""nocomma_part : LPAREN any_raw_toks_opt RPAREN
|
"""nocomma_part : LPAREN any_raw_toks_opt RPAREN
|
||||||
| LBRACE any_raw_toks_opt RBRACE
|
| LBRACE any_raw_toks_opt RBRACE
|
||||||
|
@ -1963,20 +1981,15 @@ class BaseParser(object):
|
||||||
def p_comma_nocomma(self, p):
|
def p_comma_nocomma(self, p):
|
||||||
"""comma_nocomma : comma_tok nocomma"""
|
"""comma_nocomma : comma_tok nocomma"""
|
||||||
p1 = p[1]
|
p1 = p[1]
|
||||||
p[0] = [(p1.lineno, p1.lexpos, None)]
|
p[0] = [(p1.lineno, p1.lexpos)]
|
||||||
|
|
||||||
def p_comma_trailing_nocomma(self, p):
|
def p_macroarglist_single(self, p):
|
||||||
"""comma_nocomma : comma_tok
|
"""macroarglist : nocomma"""
|
||||||
| comma_tok WS
|
p[0] = []
|
||||||
"""
|
|
||||||
p1 = p[1]
|
|
||||||
p[0] = [(p1.lineno, p1.lexpos, 'trailing')]
|
|
||||||
|
|
||||||
def p_macroarglist(self, p):
|
def p_macroarglist_many(self, p):
|
||||||
"""macroarglist : nocomma comma_nocomma_list_opt"""
|
"""macroarglist : nocomma comma_nocomma_list"""
|
||||||
p2 = p[2]
|
p[0] = p[2]
|
||||||
pos = [] if p2 is None else p2
|
|
||||||
p[0] = pos
|
|
||||||
|
|
||||||
def p_subscriptlist(self, p):
|
def p_subscriptlist(self, p):
|
||||||
"""subscriptlist : subscript comma_subscript_list_opt comma_opt"""
|
"""subscriptlist : subscript comma_subscript_list_opt comma_opt"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue