Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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())