1
0
forked from VimPlug/jedi

Grammar versioning has now a smoother interface.

This commit is contained in:
Dave Halter
2015-12-25 19:30:25 +01:00
parent a373e34229
commit eb2e41f771
4 changed files with 11 additions and 9 deletions

View File

@@ -122,7 +122,7 @@ class Script(object):
cache.clear_time_caches() cache.clear_time_caches()
debug.reset_time() debug.reset_time()
self._grammar = load_grammar('grammar%s.%s' % sys.version_info[:2]) self._grammar = load_grammar(version='%s.%s' % sys.version_info[:2])
self._user_context = UserContext(self.source, self._pos) self._user_context = UserContext(self.source, self._pos)
self._parser = UserContextParser(self._grammar, self.source, path, self._parser = UserContextParser(self._grammar, self.source, path,
self._pos, self._user_context, self._pos, self._user_context,

View File

@@ -30,7 +30,7 @@ def _load_faked_module(module):
except IOError: except IOError:
modules[module_name] = None modules[module_name] = None
return return
grammar = load_grammar('grammar3.4') grammar = load_grammar(version='3.4')
module = ParserWithRecovery(grammar, unicode(source), module_name).module module = ParserWithRecovery(grammar, unicode(source), module_name).module
modules[module_name] = module modules[module_name] = module

View File

@@ -41,16 +41,18 @@ class ParseError(Exception):
""" """
def load_grammar(file='grammar3.4'): def load_grammar(version='3.4'):
# For now we only support two different Python syntax versions: The latest # For now we only support two different Python syntax versions: The latest
# Python 3 and Python 2. This may change. # Python 3 and Python 2. This may change.
if file.startswith('grammar3'): if version in ('3.2', '3.3'):
file = 'grammar3.4' version = '3.4'
else: elif version == '2.6':
file = 'grammar2.7' version == '2.7'
file = 'grammar' + version + '.txt'
global _loaded_grammars global _loaded_grammars
path = os.path.join(os.path.dirname(__file__), file) + '.txt' path = os.path.join(os.path.dirname(__file__), file)
try: try:
return _loaded_grammars[path] return _loaded_grammars[path]
except KeyError: except KeyError:

View File

@@ -190,7 +190,7 @@ def test_param_splitting():
""" """
def check(src, result): def check(src, result):
# Python 2 tuple params should be ignored for now. # Python 2 tuple params should be ignored for now.
grammar = load_grammar('grammar%s.%s' % sys.version_info[:2]) grammar = load_grammar('%s.%s' % sys.version_info[:2])
m = ParserWithRecovery(grammar, u(src)).module m = ParserWithRecovery(grammar, u(src)).module
if is_py3: if is_py3:
assert not m.subscopes assert not m.subscopes