예제 #1
0
    def _test(self, data, expected):
        s = StringIO()

        p = parse(data)
        ast_pprint(p, string=s)

        try:
            assert_equal(s.getvalue(), expected)
        except AssertionError:
            msg = s.getvalue()
            msg += "\n%s" % str(expected)
            raise AssertionError("assertion error:\n%s" % msg)
예제 #2
0
def parse_and_analyse(data):
    p = parse(data)
    dispatcher = Dispatcher()
    res = ast_walk(p, dispatcher)

    return res
예제 #3
0
파일: setup.py 프로젝트: dagss/Bento
def create_ply_tabfile():
    from bento.core.parser.parser import parse
    parse('')
예제 #4
0
파일: generate.py 프로젝트: abadger/Bento
import sys

from pprint \
    import \
        pprint

from bento.core.parser.nodes import ast_walk
from bento.core.parser.visitor import Dispatcher
from bento.core.parser.parser import parse

if __name__ == "__main__":
    if len(sys.argv) > 1:
        arg = sys.argv[1]
        data = open(arg).read()
    else:
        raise ValueError("Usage: generate foo.info")

    base, ext = arg.split(".")
    py_module  = base + ".py"
    p = parse(data)
    dispatcher = Dispatcher()
    res = ast_walk(p, dispatcher)
    with open(py_module, "w") as fid:
        fid.write("ref = ")
        pprint(res, fid)