Exemplo n.º 1
0
    def parseMFQL(self, content):
        '''
        parse a MFQL source file an return a list of Statements.
        @param content: the name of the file to be parsed or directly an file
                      object.
        @type content: string || file.
        @return: the list of statements.
        @rtype: list<Statement>
        '''
        
        if isinstance(content, str) or isinstance(content, unicode):
            stream = antlr3.ANTLRStringStream(content)
        else:
            stream = antlr3.ANTLRInputStream(content)

        lexer = MFQLLexer(stream)
        tokens = antlr3.CommonTokenStream(lexer)
        parser = MFQLParser(tokens)
        
        result = parser.stmts()
        parser.eof()
        
        validator = CompositeVisitor()
        validator.addComponent(IsKeyValidator())

        if isinstance(result, list):
            for elem in result:
                elem.walk(validator)
        else:
            result.walk(validator)
        
        return result
Exemplo n.º 2
0
    def parse(self, rule, input):
        char_stream = antlr3.ANTLRStringStream(input)
        lexer = MFQLLexer(char_stream)
        tokens = antlr3.CommonTokenStream(lexer)
        parser = MFQLParser(tokens)

        rule = getattr(parser, rule)
        result = rule()
        parser.eof()
        return result