示例#1
0
    def check_parse(self, code, tree):
        char_stream = antlr3.ANTLRStringStream(code)
        lexer = gleamLexer(char_stream)
        tokens = antlr3.CommonTokenStream(lexer)
        parser = gleamParser(tokens)
        response = parser.prog()

        self.check_tree(tree, response.tree)
示例#2
0
    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 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)
示例#4
0
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()