Exemple #1
0
    def tvisit(self,
               visitor,
               args=None,
               paren=[],
               bindings=None,
               expect=None,
               ctxt=None):
        if len(args) != 1:
            raise Exception("strfy expects one arg")
        self_eval = 0
        arg = args[0]
        dummy, frag = recast(arg.fragment, [], ('Identifier', ))
        if isinstance(frag, jast.Identifier):
            frag = frag.IDENTIFIER.value
        elif isinstance(frag, jast.IdentifierPlaceholder):
            frag = texpand(frag, arg.bindings)
            if frag and frag[0] == "`":  # !!!
                self_eval = 1
        else:
            raise Exception("can't recast as identifier for strfy: %s" % arg)

        if not self_eval:
            frag = '"%s"' % frag
            frag = make_literal(frag)
        else:
            frag = "`strfy`(%s)" % frag

        return JavaTemplate(frag).tvisit(visitor,
                                         paren=paren,
                                         expect=expect,
                                         ctxt=ctxt)
Exemple #2
0
def switchgroup(vals,suite):
    vals = [ jast_make(jast.Primary,Literal=make_literal(str(v))) for v in vals ]
    groups = []
    for prim in vals[:-1]:
        lbl = jast_make(jast.SwitchLabel,Expression=prim)
        stmts = jast_make(jast.BlockStatements)
        groups.append(jast_make(jast.SwitchBlockStatementGroup,lbl,stmts))
    groups.append(jast_make(jast.SwitchBlockStatementGroup,
                            jast_make(jast.SwitchLabel,Expression=vals[-1])
                            ,suite))
    return JavaTemplate(jast_make(jast.SwitchBlockStatementGroups,groups))
def switchgroup(vals,suite):
    vals = [ jast_make(jast.Primary,Literal=make_literal(str(v))) for v in vals ]
    groups = []
    for prim in vals[:-1]:
        lbl = jast_make(jast.SwitchLabel,Expression=prim)
        stmts = jast_make(jast.BlockStatements)
        groups.append(jast_make(jast.SwitchBlockStatementGroup,lbl,stmts))
    groups.append(jast_make(jast.SwitchBlockStatementGroup,
                            jast_make(jast.SwitchLabel,Expression=vals[-1])
                            ,suite))
    return JavaTemplate(jast_make(jast.SwitchBlockStatementGroups,groups))
Exemple #4
0
    def tvisit(self,visitor,args=None,paren=[],bindings=None,expect=None,ctxt=None):
        if len(args) != 1:
            raise Exception("strfy expects one arg")
        self_eval = 0
        arg = args[0]
        dummy, frag = recast(arg.fragment,[],('Identifier',))
        if isinstance(frag,jast.Identifier):
            frag = frag.IDENTIFIER.value               
        elif isinstance(frag,jast.IdentifierPlaceholder):
            frag = texpand(frag,arg.bindings)
            if frag and frag[0] == "`": # !!!
                self_eval = 1
        else:
            raise Exception("can't recast as identifier for strfy: %s" % arg)

        if not self_eval:
            frag = '"%s"' % frag
            frag = make_literal(frag)
        else:
            frag = "`strfy`(%s)" % frag

        return JavaTemplate(frag).tvisit(visitor,paren=paren,expect=expect,ctxt=ctxt)