A list comprehension of the form [xp for fp in it if test]. If test is None, the "if test" part is omitted.
(xp, fp, it, test=None)
| 85 | return Leaf(token.STRING, string, prefix=prefix) |
| 86 | |
| 87 | def ListComp(xp, fp, it, test=None): |
| 88 | """A list comprehension of the form [xp for fp in it if test]. |
| 89 | |
| 90 | If test is None, the "if test" part is omitted. |
| 91 | """ |
| 92 | xp.prefix = "" |
| 93 | fp.prefix = " " |
| 94 | it.prefix = " " |
| 95 | for_leaf = Leaf(token.NAME, "for") |
| 96 | for_leaf.prefix = " " |
| 97 | in_leaf = Leaf(token.NAME, "in") |
| 98 | in_leaf.prefix = " " |
| 99 | inner_args = [for_leaf, fp, in_leaf, it] |
| 100 | if test: |
| 101 | test.prefix = " " |
| 102 | if_leaf = Leaf(token.NAME, "if") |
| 103 | if_leaf.prefix = " " |
| 104 | inner_args.append(Node(syms.comp_if, [if_leaf, test])) |
| 105 | inner = Node(syms.listmaker, [xp, Node(syms.comp_for, inner_args)]) |
| 106 | return Node(syms.atom, |
| 107 | [Leaf(token.LBRACE, "["), |
| 108 | inner, |
| 109 | Leaf(token.RBRACE, "]")]) |
| 110 | |
| 111 | def FromImport(package_name, name_leafs): |
| 112 | """ Return an import statement in the form: |