Exemple #1
0
 def p_argument(self, p):
     """argument : test comp_for"""
     p1 = p[1]
     p[0] = ast.GeneratorExp(elt=p1,
                             generators=p[2]['comps'],
                             lineno=p1.lineno,
                             col_offset=p1.col_offset)
Exemple #2
0
 def p_argument(self, p):
     """argument : test
                 | test comp_for
                 | test EQUALS test
     """
     # Really [keyword '='] test
     # The reason that keywords are test nodes instead of NAME is that using
     # NAME results in an ambiguity.
     p1 = p[1]
     lenp = len(p)
     if lenp == 2:
         p0 = p1
     elif lenp == 3:
         if p1 == '**':
             p0 = ast.keyword(arg=None, value=p[2])
         elif p1 == '*':
             p0 = ast.Starred(value=p[2])
         else:
             p0 = ast.GeneratorExp(elt=p1,
                                   generators=p[2]['comps'],
                                   lineno=p1.lineno,
                                   col_offset=p1.col_offset)
     elif lenp == 4:
         p0 = ast.keyword(arg=p1.id, value=p[3])
     else:
         assert False
     p[0] = p0