1
0
forked from VimPlug/jedi

Add the grammar as an argument to saving the parser.

This makes collisions of different grammars when loading from the cache impossible.
This commit is contained in:
Dave Halter
2017-03-22 18:32:49 +01:00
parent c41bee4253
commit 26cce4d078
10 changed files with 41 additions and 34 deletions
+4 -2
View File
@@ -16,8 +16,9 @@ fallback token code OP, but the parser needs the actual token code.
"""
# Python imports
import pickle
import hashlib
class Grammar(object):
@@ -74,7 +75,7 @@ class Grammar(object):
"""
def __init__(self):
def __init__(self, bnf_text):
self.symbol2number = {}
self.number2symbol = {}
self.states = []
@@ -84,6 +85,7 @@ class Grammar(object):
self.tokens = {}
self.symbol2label = {}
self.start = 256
self.sha256 = hashlib.sha256(bnf_text.encode("utf-8")).hexdigest()
def dump(self, filename):
"""Dump the grammar tables to a pickle file."""
+2 -2
View File
@@ -5,7 +5,6 @@
# Copyright 2014 David Halter. Integration into Jedi.
# Modifications are dual-licensed: MIT and PSF.
# Pgen imports
from . import grammar
from jedi.parser import token
from jedi.parser import tokenize
@@ -13,6 +12,7 @@ from jedi.parser import tokenize
class ParserGenerator(object):
def __init__(self, bnf_text):
self._bnf_text = bnf_text
self.generator = tokenize.source_tokens(bnf_text)
self.gettoken() # Initialize lookahead
self.dfas, self.startsymbol = self.parse()
@@ -20,7 +20,7 @@ class ParserGenerator(object):
self.addfirstsets()
def make_grammar(self):
c = grammar.Grammar()
c = grammar.Grammar(self._bnf_text)
names = list(self.dfas.keys())
names.sort()
names.remove(self.startsymbol)