示例#1
0
    def testPythonRuntime(self):
        
        symbols = self._parser.compile_file(TEST_GRAMMAR_FILE)
        
        self.assertIsNotNone(symbols)
        
        self._generated_file = "godl_parser.py"
        
        codegen = PythonCodeGenerator()
        output = FileOut(self._generated_file)
        
        output.open_file()
        CodeWriter(symbols, codegen).write(output)
        output.close_file()
        
        from godl_parser import GodlParser
        
        parser = GodlParser()
        
        self.assertIsNotNone(parser)
        
        code = """
/* GODL example code */

include "some_external_defs.goc";

package demo {

    gobject Person { // <-- a class
    
        Person { }
        
        method do_something {
            result { type: string; }
            parameter error { type: ref(ref(GError)); }
        }
    
    }

}
        """
        
        try:
            ast = parser.parseString(code)
        except Exception as error:
            self.fail(str(error))
            
        self.assertIsNotNone(ast)
        
        print(ast.toXml())
示例#2
0
    def testPythonRT_2(self):
        
        symbols = self._parser.compile_file("text_block_test.bovg")
        
        self.assertIsNotNone(symbols)
        
        self._generated_file = "demo_parser.py"
        
        codegen = PythonCodeGenerator()
        
        output = FileOut(self._generated_file)
        
        output.open_file()
        CodeWriter(symbols, codegen).write(output)
        output.close_file()
        
        from demo_parser import TextblockParser
        
        parser = TextblockParser()
        
        self.assertIsNotNone(parser)
        
        code = '''
# Test
var hello;
var world = 'World';
var text = """
This is a long
text block. It
stretches over 
several lines...""";
'''
        
        try:
            ast = parser.parseString(code)
        except Exception as error:
            self.fail(str(error))
            
        self.assertIsNotNone(ast)
        
        print(ast.toXml())