示例#1
0
    def test_invalid_keyword(self):
        data = """\
Library:
    Name: foo
"""

        try:
            parse(data)
            self.fail("parser did not raise expected ParseError")
        except ParseError:
            e = extract_exception()
            self.assertMultiLineEqual(e.msg, """\
yacc: Syntax error at line 2, Token(NAME_ID, 'Name')
    Name: foo
    ^""")
示例#2
0
    def test_invalid_keyword(self):
        data = """\
Library:
    Name: foo
"""

        try:
            parse(data)
            self.fail("parser did not raise expected ParseError")
        except ParseError:
            e = extract_exception()
            self.assertMultiLineEqual(
                e.msg, """\
yacc: Syntax error at line 2, Token(NAME_ID, 'Name')
    Name: foo
    ^""")
示例#3
0
    def test_invalid_keyword_comment(self):
        """Check comments don't screw up line counting."""
        data = """\
# Some useless
# comments
Library:
    Name: foo
"""

        try:
            parse(data)
            self.fail("parser did not raise expected ParseError")
        except ParseError:
            e = extract_exception()
            self.assertMultiLineEqual(e.msg, """\
yacc: Syntax error at line 4, Token(NAME_ID, 'Name')
    Name: foo
    ^""")
示例#4
0
    def test_invalid_keyword_comment(self):
        """Check comments don't screw up line counting."""
        data = """\
# Some useless
# comments
Library:
    Name: foo
"""

        try:
            parse(data)
            self.fail("parser did not raise expected ParseError")
        except ParseError:
            e = extract_exception()
            self.assertMultiLineEqual(
                e.msg, """\
yacc: Syntax error at line 4, Token(NAME_ID, 'Name')
    Name: foo
    ^""")
示例#5
0
    def _test(self, data, expected):
        s = cStringIO()

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

        try:
            self.assertEqual(s.getvalue(), expected)
        except AssertionError:
            msg = s.getvalue()
            msg += "\n%s" % str(expected)
            raise AssertionError("assertion error:\n%s" % msg)
示例#6
0
    def _test(self, data, expected):
        s = cStringIO()

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

        try:
            self.assertEqual(s.getvalue(), expected)
        except AssertionError:
            msg = s.getvalue()
            msg += "\n%s" % str(expected)
            raise AssertionError("assertion error:\n%s" % msg)
示例#7
0
def parse_and_analyse(data):
    p = parse(data)
    dispatcher = Dispatcher()
    res = ast_walk(p, dispatcher)

    return res
示例#8
0
def parse_and_analyse(data):
    p = parse(data)
    dispatcher = Dispatcher()
    res = ast_walk(p, dispatcher)

    return res
示例#9
0
import sys

from pprint \
    import \
        pprint

from bento.parser.nodes import ast_walk
from bento.parser.visitor import Dispatcher
from bento.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)