def setUp(self): print "setting up mock grammar and parser" testName = self.shortDescription() self.tokenListOne = breakDownStringToTokens("5 + 5 and 5 + 5", module = data) self.tokenListTwo = breakDownStringToTokens("5 + 5", module = data ) start_node = data.BaseExprNode() self.parser = ParseText(data.grammar, "baseexpr") if testName == "parse test": self.tokenListThree = breakDownStringToTokens("5 + 5 someword", module = data) self.tokenListFour = breakDownStringToTokens("word 5 + 5", module = data) #FIX THIS! Or Should i?! #self.tokenListFive = breakDownStringToTokens(" ", module = data) elif testName == "execute code": self.ast = AST(self.tokenListOne, start_node,data.grammar, data.nodes) self.parser.parse(self.tokenListOne) trace = self.parser.where_was_i self.ast.create_tree("baseexpr",trace) # print self.ast.tree_nodes[0].dooperation() elif testName == "build AST test": self.ast = AST(self.tokenListTwo, start_node,data.grammar, data.nodes) self.parser.parse(self.tokenListTwo) trace = self.parser.where_was_i self.ast.create_tree("baseexpr",trace)
def setUp(self): print("setting up mock grammar and parser") testName = self.shortDescription() self.tokenListOne = breakDownStringToTokens("5 + 5 and 5 + 5", module = data) self.tokenListTwo = breakDownStringToTokens("5 + 5", module = data ) start_node = data.BaseExprNode() self.parser = ParseText(data.grammar, "baseexpr") if testName == "parse test": self.tokenListThree = breakDownStringToTokens("5 + 5 someword", module = data) self.tokenListFour = breakDownStringToTokens("word 5 + 5", module = data) #FIX THIS! Or Should i?! #self.tokenListFive = breakDownStringToTokens(" ", module = data) elif testName == "execute code": self.ast = AST(self.tokenListOne, start_node,data.grammar, data.nodes) self.parser.parse(self.tokenListOne) trace = self.parser.where_was_i self.ast.create_tree("baseexpr",trace) # print self.ast.tree_nodes[0].dooperation() elif testName == "build AST test": self.ast = AST(self.tokenListTwo, start_node,data.grammar, data.nodes) self.parser.parse(self.tokenListTwo) trace = self.parser.where_was_i self.ast.create_tree("baseexpr",trace)
def do_it(query): token_list = breakDownStringToTokens(query) parser = ParseText(grammar,"baseexpr") print token_list if parser.parse(token_list): #parser.parse(["number", "minus", "number", "and","number","plus","number"]): b = BaseExprNode() #p = createnode(nodes["baseexpr"]) # print p, "ovo" ast = AST(token_list,b,grammar,nodes) ast.createtree("baseexpr", parser.where_was_i) # print ast.stack2 #print json.dumps(ast.stack2[0].dooperation(), indent=4, sort_keys=True) print ast.stack2[0].dooperation() print ast.stack2 else: print "nope doin"