forked from VimPlug/jedi
Rework the parser so we can use arbitrary start nodes of the syntax.
This also includes a rework for error recovery in the parser. This is now just possible for file_input parsing, which means for full files. Includes also a refactoring of the tokenizer. No more do we have to add an additional newline, because it now works correctly (removes certain confusion.
This commit is contained in:
@@ -19,9 +19,11 @@ x support for type hint comments `# type: (int, str) -> int`. See comment from
|
||||
"""
|
||||
|
||||
from itertools import chain
|
||||
|
||||
from jedi.parser import Parser, load_grammar
|
||||
from jedi.evaluate.cache import memoize_default
|
||||
from jedi.evaluate.compiled import CompiledObject
|
||||
from jedi import debug
|
||||
|
||||
|
||||
def _evaluate_for_annotation(evaluator, annotation):
|
||||
@@ -30,13 +32,13 @@ def _evaluate_for_annotation(evaluator, annotation):
|
||||
for definition in evaluator.eval_element(annotation):
|
||||
if (isinstance(definition, CompiledObject) and
|
||||
isinstance(definition.obj, str)):
|
||||
p = Parser(load_grammar(), definition.obj)
|
||||
try:
|
||||
element = p.module.children[0].children[0]
|
||||
except (AttributeError, IndexError):
|
||||
continue
|
||||
element.parent = annotation.parent
|
||||
definitions |= evaluator.eval_element(element)
|
||||
p = Parser(load_grammar(), definition.obj, start='expr')
|
||||
element = p.get_parsed_node()
|
||||
if element is None:
|
||||
debug.warning('Annotation not parsed: %s' % definition.obj)
|
||||
else:
|
||||
element.parent = annotation.parent
|
||||
definitions |= evaluator.eval_element(element)
|
||||
else:
|
||||
definitions.add(definition)
|
||||
return list(chain.from_iterable(
|
||||
|
||||
Reference in New Issue
Block a user