1
0
forked from VimPlug/jedi

The interpreter is not using the fast parser anymore.

This commit is contained in:
Dave Halter
2015-02-05 00:27:37 +01:00
parent dce952aec6
commit 3a4235eb33
3 changed files with 18 additions and 6 deletions

View File

@@ -570,6 +570,13 @@ class Interpreter(Script):
super(Interpreter, self).__init__(source, **kwds)
self.namespaces = namespaces
# Don't use the fast parser, because it does crazy stuff that we don't
# need in our very simple and small code here (that is always
# changing).
self._parser = UserContextParser(self._grammar, self.source,
self._orig_path, self._pos,
self._user_context,
use_fast_parser=False)
interpreter.add_namespaces_to_parser(self._evaluator, namespaces,
self._parser.module())

View File

@@ -18,7 +18,7 @@ The easiest way to play with this module is to use :class:`parsing.Parser`.
>>> parser = Parser(load_grammar(), u('import os'), 'example.py')
>>> submodule = parser.module
>>> submodule
<SubModule: example.py@1-2>
<SubModule: example.py@1-1>
Any subclasses of :class:`Scope`, including :class:`SubModule` has an attribute
:attr:`imports <Scope.imports>`:

View File

@@ -4,7 +4,7 @@ import keyword
from jedi import cache
from jedi import common
from jedi.parser import tokenize
from jedi.parser import tokenize, Parser
from jedi._compatibility import u
from jedi.parser.fast import FastParser
from jedi.parser import tree as pr
@@ -235,19 +235,24 @@ class UserContext(object):
class UserContextParser(object):
def __init__(self, grammar, source, path, position, user_context):
def __init__(self, grammar, source, path, position, user_context,
use_fast_parser=True):
self._grammar = grammar
self._source = source
self._path = path and os.path.abspath(path)
self._position = position
self._user_context = user_context
self._use_fast_parser = use_fast_parser
@cache.underscore_memoization
def _parser(self):
cache.invalidate_star_import_cache(self._path)
parser = FastParser(self._grammar, self._source, self._path)
# Don't pickle that module, because the main module is changing quickly
cache.save_parser(self._path, None, parser, pickling=False)
if self._use_fast_parser:
parser = FastParser(self._grammar, self._source, self._path)
# Don't pickle that module, because the main module is changing quickly
cache.save_parser(self._path, None, parser, pickling=False)
else:
parser = Parser(self._grammar, self._source, self._path)
return parser
@cache.underscore_memoization