Пример #1
0
def make_parser(debug=False):
    import sys
    import blex
    import byacc
    import lexer
    from plyhacks import lexfrom, yaccfrom
    from functools import partial

    module = sys.modules[__name__]
    lexer = lexfrom(lexer, blex)
    parser = yaccfrom(module, byacc, lexer)

    return partial(parser.parse, lexer=lexer)
Пример #2
0
def make_parser(debug=False):
    import sys
    import blex
    import byacc
    import lexer
    from plyhacks import lexfrom, yaccfrom
    from functools import partial

    module = sys.modules[__name__]
    lexer = lexfrom(lexer, blex)
    parser = yaccfrom(module, byacc, lexer)

    return partial(parser.parse, lexer=lexer)
Пример #3
0
def load_parser(debug=False):
    if debug:
        from ply import lex, yacc
        path = os.path.relpath(__file__)
        dir_path = os.path.dirname(path)
        lexer = lex.lex(lextab="mlex", outputdir=dir_path, optimize=0)
        parser = yacc.yacc(tabmodule='myacc',outputdir=dir_path,
                write_tables=0, debug=0, optimize=0)
        return partial(debug_parse, lexer=lexer, parser=parser)
    else:
        module = sys.modules[__name__]
        lexer = lexfrom(module, mlex)
        parser = yaccfrom(module, myacc, lexer)

        # curry the lexer into the parser
        return partial(parser.parse, lexer=lexer)
Пример #4
0
def load_parser(debug=False):
    if debug:
        from ply import lex, yacc
        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        lexer = lex.lex(lextab="_alex", outputdir=dir_path, optimize=1)
        parser = yacc.yacc(tabmodule='_ayacc',
                           outputdir=dir_path,
                           write_tables=1,
                           debug=0,
                           optimize=1)
        return partial(parser.parse, lexer=lexer)
    else:
        module = sys.modules[__name__]
        lexer = lexfrom(module, _alex)
        parser = yaccfrom(module, _ayacc, lexer)

        # curry the lexer into the parser
        return partial(parser.parse, lexer=lexer)