def __init__(self, grammar=None, lr_type=LR0, whitespaces=False, startsymbol=None): if grammar: logging.debug("Parsing Grammar") parser = Parser(grammar, whitespaces) parser.parse() filename = "".join([ os.path.dirname(__file__), "/../pickle/", str(hash(grammar) ^ hash(whitespaces)), ".pcl" ]) try: logging.debug("Try to unpickle former stategraph") f = open(filename, "r") start = time.time() self.graph = pickle.load(f) end = time.time() logging.debug("unpickling done in %s", end - start) except IOError: logging.debug("could not unpickle old graph") logging.debug("Creating Stategraph") self.graph = StateGraph(parser.start_symbol, parser.rules, lr_type) logging.debug("Building Stategraph") self.graph.build() logging.debug("Pickling") pickle.dump(self.graph, open(filename, "w")) if lr_type == LALR: self.graph.convert_lalr() logging.debug("Creating Syntaxtable") self.syntaxtable = SyntaxTable(lr_type) self.syntaxtable.build(self.graph) self.stack = [] self.ast_stack = [] self.all_changes = [] self.undo = [] self.last_shift_state = 0 self.validating = False self.last_status = False self.error_node = None self.whitespaces = whitespaces self.status_by_version = {} self.errornode_by_version = {} self.indentation_based = False self.pm = PluginManager() self.pm.loadplugins(self) self.pm.do_incparse_init() self.previous_version = None logging.debug("Incremental parser done")
def __init__(self, grammar, lr_type=LR0): parser = Parser(grammar) parser.parse() self.graph = StateGraph(parser.start_symbol, parser.rules, lr_type) self.graph.build() if lr_type == LALR: self.graph.convert_lalr() self.syntaxtable = SyntaxTable(lr_type) self.syntaxtable.build(self.graph) self.stack = [] self.ast_stack = []
def from_dict(self, rules, startsymbol, lr_type, whitespaces, pickle_id, precedences): self.graph = None self.syntaxtable = None if pickle_id: filename = "".join([os.path.dirname(__file__), "/../pickle/", str(pickle_id ^ hash(whitespaces)), ".pcl"]) try: f = open(filename, "r") self.syntaxtable = pickle.load(f) except IOError: pass if self.syntaxtable is None: self.graph = StateGraph(startsymbol, rules, lr_type) self.graph.build() self.syntaxtable = SyntaxTable(lr_type) self.syntaxtable.build(self.graph, precedences) if pickle_id: pickle.dump(self.syntaxtable, open(filename, "w")) self.whitespaces = whitespaces