mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
have simple generator
This commit is contained in:
parent
c097c031bd
commit
9a7674f78d
3 changed files with 21 additions and 4 deletions
|
@ -347,6 +347,10 @@ def test_elipssis():
|
|||
def test_not_implemented_name():
|
||||
yield check_ast, 'NotImplemented'
|
||||
|
||||
def test_genexpr():
|
||||
yield check_ast, '(x for x in "mom")'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,4 +4,4 @@ from ast import Module, Num, Expr, Str, Bytes, UnaryOp, UAdd, USub, Invert, \
|
|||
BinOp, Add, Sub, Mult, Div, FloorDiv, Mod, Pow, Compare, Lt, Gt, LtE, \
|
||||
GtE, Eq, NotEq, In, NotIn, Is, IsNot, Not, BoolOp, Or, And, Subscript, \
|
||||
Index, Load, Slice, List, Tuple, Set, Dict, AST, NameConstant, Ellipsis, \
|
||||
Name
|
||||
Name, GeneratorExp, Store, comprehension
|
|
@ -1036,6 +1036,9 @@ class Parser(object):
|
|||
p0 = p0.elts[0]
|
||||
elif p2 == ',':
|
||||
pass
|
||||
elif isinstance(p2, ast.comprehension):
|
||||
p0 = ast.GeneratorExp(elt=p0.elts[0], generators=[p2],
|
||||
lineno=self.lineno, col_offset=self.col)
|
||||
else:
|
||||
assert False
|
||||
elif len(p) == 4:
|
||||
|
@ -1098,7 +1101,12 @@ class Parser(object):
|
|||
|
||||
def p_exprlist(self, p):
|
||||
"""exprlist : expr_or_star_expr comma_expr_or_star_expr_list_opt comma_opt"""
|
||||
p[0] = p[1:]
|
||||
p1, p2, p3 = p[1], p[2], p[3]
|
||||
if p2 is None and p3 is None:
|
||||
p0 = p1
|
||||
else:
|
||||
assert False
|
||||
p[0] = p0
|
||||
|
||||
def p_testlist(self, p):
|
||||
"""testlist : test comma_test_list_opt comma_opt
|
||||
|
@ -1195,11 +1203,16 @@ class Parser(object):
|
|||
"""comp_iter : comp_for
|
||||
| comp_if
|
||||
"""
|
||||
p[0] = p[1:]
|
||||
p[0] = p[1]
|
||||
|
||||
def p_comp_for(self, p):
|
||||
"""comp_for : FOR exprlist IN or_test comp_iter_opt"""
|
||||
p[0] = p[1:]
|
||||
targ, it = p[2], p[4]
|
||||
targ.ctx = ast.Store()
|
||||
p0 = ast.comprehension(target=targ, iter=it, ifs=[])
|
||||
if p[5] is not None:
|
||||
assert False
|
||||
p[0] = p0
|
||||
|
||||
def p_comp_if(self, p):
|
||||
"""comp_if : IF test_nocond comp_iter_opt"""
|
||||
|
|
Loading…
Add table
Reference in a new issue