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
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
def recast_Placeholder_Selectors__BlockStatements(frag,paren): if not frag.Selectors: # !!! return jast_make(jast.BlockStatements, jast_make(jast.BlockStatementPlaceholder,frag.Placeholder))
def recast_QualifiedIdentifier__ExpressionInSeq(frag,paren): if len(frag.QualifiedIdentifier) == 1: return jast_make(jast.Primary,Identifier=frag.QualifiedIdentifier[0],ArgumentsOpt=None)
def recast_QualifiedIdentifier__ExpressionInSeq(frag, paren): if len(frag.QualifiedIdentifier) == 1: return jast_make(jast.Primary, Identifier=frag.QualifiedIdentifier[0], ArgumentsOpt=None)
def recast_Placeholder_Selectors__ExpressionInSeq(frag,paren): if not frag.Selectors: # !!! return jast_make(jast.ExpressionInSeqPlaceholder,frag.Placeholder)
def recast_Placeholder_Selectors__FormalParameterInSeq(frag,paren): if not frag.Selectors: # !!! return jast_make(jast.FormalParameterInSeqPlaceholder,frag.Placeholder)
def recast_Placeholder_Selectors__ExpressionInSeq(frag, paren): if not frag.Selectors: # !!! return jast_make(jast.ExpressionInSeqPlaceholder, frag.Placeholder)
def recast_Expression__Primary(frag,paren): return jast_make(jast.Primary,Expression=frag.Expression)
def recast_Expression__Primary(frag, paren): return jast_make(jast.Primary, Expression=frag.Expression)
def recast___ExpressionInSeq(frag, paren): return jast_make(jast.Expressions)
def recast___BlockStatements(frag, paren): return jast_make(jast.BlockStatements)
def recast_Placeholder_Selectors__Identifier(frag, paren): if not frag.Selectors: # !!! return jast_make(jast.IdentifierPlaceholder, frag.Placeholder)
def recast_Placeholder_Selectors__BlockStatements(frag, paren): if not frag.Selectors: # !!! return jast_make( jast.BlockStatements, jast_make(jast.BlockStatementPlaceholder, frag.Placeholder))
def recast_Placeholder_Selectors__Identifier(frag,paren): if not frag.Selectors: # !!! return jast_make(jast.IdentifierPlaceholder,frag.Placeholder)
def recast___ClassBodyDeclarations(frag, paren): return jast_make(jast.ClassBodyDeclarations)
def recast___BlockStatements(frag,paren): return jast_make(jast.BlockStatements)
def recast_Placeholder_Selectors__FormalParameterInSeq(frag, paren): if not frag.Selectors: # !!! return jast_make(jast.FormalParameterInSeqPlaceholder, frag.Placeholder)
def recast___ExpressionInSeq(frag,paren): return jast_make(jast.Expressions)
def recast___SwitchBlockStatementGroupInSeq(frag, paren): return jast_make(jast.SwitchBlockStatementGroups)
def recast___ClassBodyDeclarations(frag,paren): return jast_make(jast.ClassBodyDeclarations)
def recast_Literal__Primary(frag, paren): return jast_make(jast.Primary, Literal=frag)
def recast___SwitchBlockStatementGroupInSeq(frag,paren): return jast_make(jast.SwitchBlockStatementGroups)
def recast_QualifiedIdentifier__TypeOrVOID(frag,paren): return jast_make(jast.Type, QualifiedIdentifier = frag, BracketsOpt = jast_make(jast.Brackets))
def recast_Literal__Primary(frag,paren): return jast_make(jast.Primary,Literal=frag)
def recast_QualifiedIdentifier__TypeOrVOID(frag, paren): return jast_make(jast.Type, QualifiedIdentifier=frag, BracketsOpt=jast_make(jast.Brackets))