Ejemplo n.º 1
0
 def _parse_rhs(self, ctx, exp):
     result = ctx._call(exp.parse, self.name, self.params, self.kwparams)
     if isinstance(result, AST):
         defines = compress_seq(self.defines())
         result._define(
             [d for d, l in defines if not l],
             [d for d, l in defines if l]
         )
     return result
Ejemplo n.º 2
0
    def render_fields(self, fields):
        self.reset_counter()

        params = kwparams = ""
        if self.node.params:
            params = ", ".join(self.param_repr(self.rend(p)) for p in self.node.params)
        if self.node.kwparams:
            kwparams = ", ".join("%s=%s" % (k, self.param_repr(self.rend(v))) for k, v in self.kwparams.items())

        if params and kwparams:
            params = params + ", " + kwparams
        elif kwparams:
            params = kwparams

        fields.update(params=params)

        defines = compress_seq(self.defines())
        sdefs = [d for d, l in defines if not l]
        ldefs = [d for d, l in defines if l]
        if not (sdefs or ldefs):
            sdefines = ""
        else:
            sdefs = "[%s]" % ", ".join(urepr(d) for d in sdefs)
            ldefs = "[%s]" % ", ".join(urepr(d) for d in ldefs)
            if not ldefs:
                sdefines = "\n\n    self.ast._define(%s, %s)" % (sdefs, ldefs)
            else:
                sdefines = indent(
                    "\n\n"
                    + trim(
                        """\
                                                self.ast._define(
                                                    %s,
                                                    %s
                                                )"""
                        % (sdefs, ldefs)
                    )
                )

        fields.update(defines=sdefines)