def parse_java_statement(self, statement): parser = ECleverParser(text=statement) tree = parser.java_statement() builder = EPromptoBuilder(parser) walker = ParseTreeWalker() walker.walk(builder, tree) return builder.getNodeValue(tree)
def doParse(self, rule, addLF): self.getTokenStream().tokenSource.addLF = addLF tree = rule() builder = EPromptoBuilder(self) walker = ParseTreeWalker() walker.walk(builder, tree) return builder.getNodeValue(tree)
def parseExpression(self, exp): parser = ECleverParser(text=exp) parser._input.tokenSource.addLF = False tree = parser.expression() builder = EPromptoBuilder(parser) walker = ParseTreeWalker() walker.walk(builder, tree) return builder.getNodeValue(tree)
def testSystemOutPrint(self): parser = ECleverParser(text='print(objects=value,end="")') parser._input.tokenSource.addLF = False tree = parser.python_statement() builder = EPromptoBuilder(parser) walker = ParseTreeWalker() walker.walk(builder, tree) statement = builder.getNodeValue(tree) context = Context.newGlobalContext() arg = CategoryParameter(TextType.instance, "value") arg.register(context) context.setValue("value", TextLiteral('"test"')) # StringLiteral trims enclosing quotes result = statement.interpret(context, None, None) # no module self.assertIsNone(result) self.assertEqual("test", Out.read())