def singleArg(self): self.returnAST = None currentAST = antlr.ASTPair() singleArg_AST = None try: ## for error handling pass self.match(LPAREN) self.nonAlternatingTemplateExpr() self.addASTChild(currentAST, self.returnAST) self.match(RPAREN) if not self.inputState.guessing: singleArg_AST = currentAST.root singleArg_AST = antlr.make(self.astFactory.create(SINGLEVALUEARG,"SINGLEVALUEARG"), singleArg_AST) currentAST.root = singleArg_AST if (singleArg_AST != None) and (singleArg_AST.getFirstChild() != None): currentAST.child = singleArg_AST.getFirstChild() else: currentAST.child = singleArg_AST currentAST.advanceChildToEnd() singleArg_AST = currentAST.root except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_14) else: raise ex
def templateInclude(self): self.returnAST = None currentAST = antlr.ASTPair() templateInclude_AST = None id = None id_AST = None qid = None qid_AST = None try: ## for error handling pass la1 = self.LA(1) if False: pass elif la1 and la1 in [ID]: pass id = self.LT(1) id_AST = self.astFactory.create(id) self.addASTChild(currentAST, id_AST) self.match(ID) self.argList() self.addASTChild(currentAST, self.returnAST) elif la1 and la1 in [LITERAL_super]: pass self.match(LITERAL_super) self.match(DOT) qid = self.LT(1) qid_AST = self.astFactory.create(qid) self.addASTChild(currentAST, qid_AST) self.match(ID) if not self.inputState.guessing: qid_AST.setText("super."+qid_AST.getText()) self.argList() self.addASTChild(currentAST, self.returnAST) elif la1 and la1 in [LPAREN]: pass self.indirectTemplate() self.addASTChild(currentAST, self.returnAST) else: raise antlr.NoViableAltException(self.LT(1), self.getFilename()) if not self.inputState.guessing: templateInclude_AST = currentAST.root templateInclude_AST = antlr.make(self.astFactory.create(INCLUDE,"include"), templateInclude_AST) currentAST.root = templateInclude_AST if (templateInclude_AST != None) and (templateInclude_AST.getFirstChild() != None): currentAST.child = templateInclude_AST.getFirstChild() else: currentAST.child = templateInclude_AST currentAST.advanceChildToEnd() templateInclude_AST = currentAST.root except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_14) else: raise ex
def argList(self): self.returnAST = None currentAST = antlr.ASTPair() argList_AST = None try: ## for error handling if (self.LA(1)==LPAREN) and (self.LA(2)==RPAREN): pass self.match(LPAREN) self.match(RPAREN) if not self.inputState.guessing: argList_AST = currentAST.root argList_AST = self.astFactory.create(ARGS,"ARGS") currentAST.root = argList_AST if (argList_AST != None) and (argList_AST.getFirstChild() != None): currentAST.child = argList_AST.getFirstChild() else: currentAST.child = argList_AST currentAST.advanceChildToEnd() elif (self.LA(1)==LPAREN) and (self.LA(2)==ID): pass self.match(LPAREN) self.argumentAssignment() self.addASTChild(currentAST, self.returnAST) while True: if (self.LA(1)==COMMA): pass self.match(COMMA) self.argumentAssignment() self.addASTChild(currentAST, self.returnAST) else: break self.match(RPAREN) if not self.inputState.guessing: argList_AST = currentAST.root argList_AST = antlr.make(self.astFactory.create(ARGS,"ARGS"), argList_AST) currentAST.root = argList_AST if (argList_AST != None) and (argList_AST.getFirstChild() != None): currentAST.child = argList_AST.getFirstChild() else: currentAST.child = argList_AST currentAST.advanceChildToEnd() argList_AST = currentAST.root else: raise antlr.NoViableAltException(self.LT(1), self.getFilename()) except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_7) else: raise ex
def testHeteroTreeDup() : x = factory.create(1,"[type 1]",MyAST) ## will be root y = factory.create(2,"[type 2]",MyAST) z = factory.create(3,"[type 3]",MyAST) sub = factory.create(49,"[type 49]",ASTType49) sub.addChild(factory.create(3,"[type 3 #2]",MyAST)) t = antlr.make(x,y,sub,z) dup_t = antlr.dupList(t,factory) ## check structure a = dup_t.equalsList(t) ## check types b = equalsNodeTypesList(t,dup_t) return a and b
def function(self): self.returnAST = None currentAST = antlr.ASTPair() function_AST = None try: ## for error handling pass la1 = self.LA(1) if False: pass elif la1 and la1 in [LITERAL_first]: pass tmp21_AST = None tmp21_AST = self.astFactory.create(self.LT(1)) self.addASTChild(currentAST, tmp21_AST) self.match(LITERAL_first) elif la1 and la1 in [LITERAL_rest]: pass tmp22_AST = None tmp22_AST = self.astFactory.create(self.LT(1)) self.addASTChild(currentAST, tmp22_AST) self.match(LITERAL_rest) elif la1 and la1 in [LITERAL_last]: pass tmp23_AST = None tmp23_AST = self.astFactory.create(self.LT(1)) self.addASTChild(currentAST, tmp23_AST) self.match(LITERAL_last) else: raise antlr.NoViableAltException(self.LT(1), self.getFilename()) self.singleArg() self.addASTChild(currentAST, self.returnAST) if not self.inputState.guessing: function_AST = currentAST.root function_AST = antlr.make(self.astFactory.create(FUNCTION), function_AST) currentAST.root = function_AST if (function_AST != None) and (function_AST.getFirstChild() != None): currentAST.child = function_AST.getFirstChild() else: currentAST.child = function_AST currentAST.advanceChildToEnd() function_AST = currentAST.root except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_11) else: raise ex
def parallelArrayTemplateApplication(self): self.returnAST = None currentAST = antlr.ASTPair() parallelArrayTemplateApplication_AST = None c = None c_AST = None try: ## for error handling pass self.expr() self.addASTChild(currentAST, self.returnAST) _cnt17= 0 while True: if (self.LA(1)==COMMA): pass self.match(COMMA) self.expr() self.addASTChild(currentAST, self.returnAST) else: break _cnt17 += 1 if _cnt17 < 1: raise antlr.NoViableAltException(self.LT(1), self.getFilename()) c = self.LT(1) c_AST = self.astFactory.create(c) self.addASTChild(currentAST, c_AST) self.match(COLON) self.anonymousTemplate() self.addASTChild(currentAST, self.returnAST) if not self.inputState.guessing: parallelArrayTemplateApplication_AST = currentAST.root parallelArrayTemplateApplication_AST = \ antlr.make(self.astFactory.create(MULTI_APPLY,"MULTI_APPLY"), parallelArrayTemplateApplication_AST) currentAST.root = parallelArrayTemplateApplication_AST if (parallelArrayTemplateApplication_AST != None) and (parallelArrayTemplateApplication_AST.getFirstChild() != None): currentAST.child = parallelArrayTemplateApplication_AST.getFirstChild() else: currentAST.child = parallelArrayTemplateApplication_AST currentAST.advanceChildToEnd() parallelArrayTemplateApplication_AST = currentAST.root except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_5) else: raise ex
def template(self): self.returnAST = None currentAST = antlr.ASTPair() template_AST = None try: ## for error handling pass la1 = self.LA(1) if False: pass elif la1 and la1 in [LPAREN,ID,LITERAL_super]: pass self.namedTemplate() self.addASTChild(currentAST, self.returnAST) elif la1 and la1 in [ANONYMOUS_TEMPLATE]: pass self.anonymousTemplate() self.addASTChild(currentAST, self.returnAST) else: raise antlr.NoViableAltException(self.LT(1), self.getFilename()) if not self.inputState.guessing: template_AST = currentAST.root template_AST = antlr.make(self.astFactory.create(TEMPLATE), template_AST) currentAST.root = template_AST if (template_AST != None) and (template_AST.getFirstChild() != None): currentAST.child = template_AST.getFirstChild() else: currentAST.child = template_AST currentAST.advanceChildToEnd() template_AST = currentAST.root except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_3) else: raise ex
def indirectTemplate(self): self.returnAST = None currentAST = antlr.ASTPair() indirectTemplate_AST = None e_AST = None args_AST = None try: ## for error handling pass tmp27_AST = None tmp27_AST = self.astFactory.create(self.LT(1)) self.match(LPAREN) self.expr() e_AST = self.returnAST tmp28_AST = None tmp28_AST = self.astFactory.create(self.LT(1)) self.match(RPAREN) self.argList() args_AST = self.returnAST if not self.inputState.guessing: indirectTemplate_AST = currentAST.root indirectTemplate_AST = antlr.make(self.astFactory.create(VALUE,"value"), e_AST, args_AST) currentAST.root = indirectTemplate_AST if (indirectTemplate_AST != None) and (indirectTemplate_AST.getFirstChild() != None): currentAST.child = indirectTemplate_AST.getFirstChild() else: currentAST.child = indirectTemplate_AST currentAST.advanceChildToEnd() except antlr.RecognitionException, ex: if not self.inputState.guessing: self.reportError(ex) self.consume() self.consumeUntil(_tokenSet_7) else: raise ex