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))
Beispiel #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))
class JavaTemplate:

    def __init__(self,frag,parms='',bindings=None,start='Fragment'):
        if isinstance(frag,java_parser.Node):
            fragment = frag
        else:
            #print "parsing... <<"
            #print frag
            try:
                fragment = java_parser.parse(frag,start=start)
            except java_parser.JavaSyntaxError,e:
                print frag
                raise
            #print ">>"            
        if (not isinstance(fragment,jast.Fragment) and
            not isinstance(fragment,jast.PlaceholderFragment)):
            child_name = fragment.__class__.__name__
            if child_name == 'FormalParameterList': # !!!
                child_name = 'FormalParameterListOpt'
            try:
                fragment = jast_make(jast.Fragment,**{child_name: fragment})
            except UnknownScheme:
                fragment = jast.Fragment((child_name,),[fragment])

        self.fragment = fragment
            
        if not parms:
            self.parms = []
        else:
            if isinstance(parms,str):
	        self.parms = parms.split(':')
            else:
                self.parms = parms
        
        if bindings is None:
            self.bindings = {}
        else:
            self.bindings = bindings
Beispiel #4
0
    def __init__(self,frag,parms='',bindings=None,start='Fragment'):
        if isinstance(frag,java_parser.Node):
            fragment = frag
        else:
            #print("parsing... <<")
            #print(frag)
            try:
                fragment = java_parser.parse(frag,start=start)
            except java_parser.JavaSyntaxError as e:
                print(frag)
                raise e
            #print(">>")
        if (not isinstance(fragment,jast.Fragment) and
            not isinstance(fragment,jast.PlaceholderFragment)):
            child_name = fragment.__class__.__name__
            if child_name == 'FormalParameterList': # !!!
                child_name = 'FormalParameterListOpt'
            try:
                fragment = jast_make(jast.Fragment,**{child_name: fragment})
            except UnknownScheme:
                fragment = jast.Fragment((child_name,),[fragment])

        self.fragment = fragment
            
        if not parms:
            self.parms = []
        else:
            if isinstance(parms,str):
                self.parms = parms.split(':')
            else:
                self.parms = parms
        
        if bindings is None:
            self.bindings = {}
        else:
            self.bindings = bindings
Beispiel #5
0
def recast_Placeholder_Selectors__BlockStatements(frag,paren):
    if not frag.Selectors: # !!!
        return jast_make(jast.BlockStatements,
                         jast_make(jast.BlockStatementPlaceholder,frag.Placeholder))
Beispiel #6
0
def recast_QualifiedIdentifier__ExpressionInSeq(frag,paren):
    if len(frag.QualifiedIdentifier) == 1:
        return jast_make(jast.Primary,Identifier=frag.QualifiedIdentifier[0],ArgumentsOpt=None)
Beispiel #7
0
def recast_QualifiedIdentifier__ExpressionInSeq(frag, paren):
    if len(frag.QualifiedIdentifier) == 1:
        return jast_make(jast.Primary,
                         Identifier=frag.QualifiedIdentifier[0],
                         ArgumentsOpt=None)
Beispiel #8
0
def recast_Placeholder_Selectors__ExpressionInSeq(frag,paren):
    if not frag.Selectors: # !!!
        return jast_make(jast.ExpressionInSeqPlaceholder,frag.Placeholder)
Beispiel #9
0
def recast_Placeholder_Selectors__FormalParameterInSeq(frag,paren):
    if not frag.Selectors: # !!!
        return jast_make(jast.FormalParameterInSeqPlaceholder,frag.Placeholder)
Beispiel #10
0
def recast_Placeholder_Selectors__ExpressionInSeq(frag, paren):
    if not frag.Selectors:  # !!!
        return jast_make(jast.ExpressionInSeqPlaceholder, frag.Placeholder)
Beispiel #11
0
def recast_Expression__Primary(frag,paren):
    return jast_make(jast.Primary,Expression=frag.Expression)
Beispiel #12
0
def recast_Expression__Primary(frag, paren):
    return jast_make(jast.Primary, Expression=frag.Expression)
Beispiel #13
0
def recast___ExpressionInSeq(frag, paren):
    return jast_make(jast.Expressions)
Beispiel #14
0
def recast___BlockStatements(frag, paren):
    return jast_make(jast.BlockStatements)
Beispiel #15
0
def recast_Placeholder_Selectors__Identifier(frag, paren):
    if not frag.Selectors:  # !!!
        return jast_make(jast.IdentifierPlaceholder, frag.Placeholder)
Beispiel #16
0
def recast_Placeholder_Selectors__BlockStatements(frag, paren):
    if not frag.Selectors:  # !!!
        return jast_make(
            jast.BlockStatements,
            jast_make(jast.BlockStatementPlaceholder, frag.Placeholder))
Beispiel #17
0
def recast_Placeholder_Selectors__Identifier(frag,paren):
    if not frag.Selectors: # !!!
        return jast_make(jast.IdentifierPlaceholder,frag.Placeholder)
Beispiel #18
0
def recast___ClassBodyDeclarations(frag, paren):
    return jast_make(jast.ClassBodyDeclarations)
Beispiel #19
0
def recast___BlockStatements(frag,paren):
    return jast_make(jast.BlockStatements)
Beispiel #20
0
def recast_Placeholder_Selectors__FormalParameterInSeq(frag, paren):
    if not frag.Selectors:  # !!!
        return jast_make(jast.FormalParameterInSeqPlaceholder,
                         frag.Placeholder)
Beispiel #21
0
def recast___ExpressionInSeq(frag,paren):
    return jast_make(jast.Expressions)
Beispiel #22
0
def recast___SwitchBlockStatementGroupInSeq(frag, paren):
    return jast_make(jast.SwitchBlockStatementGroups)
Beispiel #23
0
def recast___ClassBodyDeclarations(frag,paren):
    return jast_make(jast.ClassBodyDeclarations)
Beispiel #24
0
def recast_Literal__Primary(frag, paren):
    return jast_make(jast.Primary, Literal=frag)
Beispiel #25
0
def recast___SwitchBlockStatementGroupInSeq(frag,paren):
    return jast_make(jast.SwitchBlockStatementGroups)
Beispiel #26
0
def recast_QualifiedIdentifier__TypeOrVOID(frag,paren):
    return jast_make(jast.Type,
                     QualifiedIdentifier = frag,
                     BracketsOpt = jast_make(jast.Brackets))
Beispiel #27
0
def recast_Literal__Primary(frag,paren):
    return jast_make(jast.Primary,Literal=frag)
Beispiel #28
0
def recast_QualifiedIdentifier__TypeOrVOID(frag, paren):
    return jast_make(jast.Type,
                     QualifiedIdentifier=frag,
                     BracketsOpt=jast_make(jast.Brackets))