Ejemplo n.º 1
0
 def __init__(self, grammar_file):
     self.grammar = driver.load_grammar(grammar_file)
     self.driver = driver.Driver(self.grammar, convert=self.pconvert)
Ejemplo n.º 2
0
from . import pretty

class SyntaxError(Exception):
    def __init__(self, message='', **kwarg):
        self.message = message
        self.context = kwarg

class Symbol(object):
    def __init__(self, grammar):
        for (k, v) in grammar.symbol2number.items():
            setattr(self, k, v)

import os.path
gfile = os.path.join(os.path.dirname(__file__), 'Grammar.txt')
grammar = driver.load_grammar(gfile)
symbol = Symbol(grammar)

class Node(object):
    __slots__ = ('lineno', 'col')
    def __init__(self, context):
        if context:
            self.lineno, self.col = context[1]
    def __iter__(self):
        return iter(self.children)
    def __getitem__(self, index):
        return self.children[index]
    def __len__(self):
        return len(self.children)
    def __pretty__(self, p, cycle):
        if cycle: