예제 #1
0
파일: parser.py 프로젝트: y372465774/luna
    def __init__(self):
        dir = os.path.dirname(os.path.abspath(__file__))
        fp = os.path.join(dir, 'grammar.txt')
        content = util.read(fp)

        self.grammar = Grammar(content)
        self.builder = AstBuilder()
예제 #2
0
파일: parser.py 프로젝트: y372465774/luna
class Parser(object):
    def __init__(self):
        dir = os.path.dirname(os.path.abspath(__file__))
        fp = os.path.join(dir, 'grammar.txt')
        content = util.read(fp)

        self.grammar = Grammar(content)
        self.builder = AstBuilder()

    def parse_with_rule(self, rule, content):
        # linecomment removal: broken as it will also match inside strings
        content = re.sub('--(?!\[\[).*', '', content)

        grammar = self.grammar
        if rule is not None:
            grammar = grammar[rule]

        tree = grammar.parse(content)
        tree = self.builder.visit(tree)

        return tree

    def parse(self, content):
        return self.parse_with_rule(None, content)