1
0
forked from VimPlug/jedi

Using expr_stmt now instead of simple_stmt as ExprStmt, because that resembles the official grammar better.

This commit is contained in:
Dave Halter
2014-10-17 12:03:41 +02:00
parent 19acdd32b7
commit d7face17f6
2 changed files with 11 additions and 5 deletions

View File

@@ -25,7 +25,6 @@ _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "grammar3.4.txt")
class Symbols(object): class Symbols(object):
def __init__(self, grammar): def __init__(self, grammar):
"""Initializer. """Initializer.
@@ -95,7 +94,9 @@ def convert(grammar, raw_node):
if type in grammar.number2symbol: if type in grammar.number2symbol:
# If there's exactly one child, return that child instead of # If there's exactly one child, return that child instead of
# creating a new node. # creating a new node.
if len(children) == 1 and type != 'expr_stmt': # We still create expr_stmt though, because a lot of Jedi depends on
# its logic.
if len(children) == 1 and type != python_symbols.expr_stmt:
return children[0] return children[0]
print(raw_node, type_repr(type)) print(raw_node, type_repr(type))
#import pdb; pdb.set_trace() #import pdb; pdb.set_trace()

View File

@@ -42,6 +42,7 @@ import os
import re import re
from inspect import cleandoc from inspect import cleandoc
from collections import defaultdict from collections import defaultdict
from itertools import chain
from jedi._compatibility import (next, Python3Method, encoding, unicode, from jedi._compatibility import (next, Python3Method, encoding, unicode,
is_py3, u, literal_eval, use_metaclass) is_py3, u, literal_eval, use_metaclass)
@@ -400,7 +401,9 @@ class Scope(Simple, DocstringMixin):
@property @property
def statements(self): def statements(self):
return [c for c in self.children if isinstance(c, ExprStmt)] return [s for c in self.children if is_node(c, 'simple_stmt')
for s in c.children if isinstance(s, (ExprStmt, Import,
KeywordStatement))]
def is_scope(self): def is_scope(self):
return True return True
@@ -460,8 +463,10 @@ class Scope(Simple, DocstringMixin):
""" """
names = [] names = []
for c in self.children: for c in self.children:
if isinstance(c, ExprStmt): if is_node(c, 'simple_stmt'):
names += c.get_defined_names() names += chain.from_iterable(
[s.get_defined_names() for s in c.children
if isinstance(s, (ExprStmt, Import, KeywordStatement))])
elif isinstance(c, (Function, Class)): elif isinstance(c, (Function, Class)):
names.append(c.name) names.append(c.name)
return names return names