def check_python(self, code, expected_python): char_stream = antlr3.ANTLRStringStream(code) lexer = gleamLexer(char_stream) tokens = antlr3.CommonTokenStream(lexer) parser = gleamParser(tokens) response = parser.prog() python = gleam.to_python(response.tree, debug=True) python = self.deindent(python) expected_python = self.deindent(expected_python) if expected_python != python: print "Expected:" print expected_python print "\nActual:" print python self.assertEquals(expected_python, python)
def compile_gleam(src, target_js, target_python): '''Compiles the given src file to the target JS and target Python files. ''' char_stream = antlr3.ANTLRFileStream(src) lexer = gleamLexer(char_stream) tokens = antlr3.CommonTokenStream(lexer) parser = gleamParser(tokens) response = parser.prog() js = gleam.to_js(response.tree, src, debug=True) of = file(target_js, 'w') of.write(js) of.close() python = gleam.to_python(response.tree, debug=True) of = file(target_python, 'w') of.write(python) of.close()