def check_js(self, code, expected_js): char_stream = antlr3.ANTLRStringStream(code) lexer = gleamLexer(char_stream) tokens = antlr3.CommonTokenStream(lexer) parser = gleamParser(tokens) response = parser.prog() js = gleam.to_js(response.tree, "view", debug=True) js = self.deindent(js) expected_js = self.deindent(expected_js) if expected_js != js: print 'Expected:' print expected_js print '\nActual:' print js self.assertEquals(expected_js, js)
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()