mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
parser working for get_set_vars
This commit is contained in:
@@ -232,21 +232,21 @@ def handle_names(names):
|
|||||||
print 'star!', n.from_ns
|
print 'star!', n.from_ns
|
||||||
|
|
||||||
print 'global names:'
|
print 'global names:'
|
||||||
names = cmpl.parser.top.get_names()
|
names = cmpl.parser.top.get_set_vars()
|
||||||
handle_names(names)
|
handle_names(names)
|
||||||
|
|
||||||
print
|
print
|
||||||
print 'func names:'
|
print 'func names:'
|
||||||
names = cmpl.parser.top.subscopes[0].get_names()
|
names = cmpl.parser.top.subscopes[7].get_set_vars()
|
||||||
handle_names(names)
|
handle_names(names)
|
||||||
|
|
||||||
print
|
print
|
||||||
print 'class names:'
|
print 'class names:'
|
||||||
names = cmpl.parser.top.subscopes[2].get_names()
|
names = cmpl.parser.top.subscopes[2].get_set_vars()
|
||||||
handle_names(names)
|
handle_names(names)
|
||||||
for s in cmpl.parser.top.subscopes[2].subscopes:
|
for s in cmpl.parser.top.subscopes[2].subscopes:
|
||||||
print 'method names:'
|
print 'method names:'
|
||||||
names = s.get_names()
|
names = s.get_set_vars()
|
||||||
handle_names(names)
|
handle_names(names)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ TODO take special care for future imports
|
|||||||
TODO check meta classes
|
TODO check meta classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import tokenize
|
import tokenize
|
||||||
import cStringIO
|
import cStringIO
|
||||||
import token
|
import token
|
||||||
@@ -147,7 +146,7 @@ class Scope(object):
|
|||||||
string = indent_block(string, indention=indention)
|
string = indent_block(string, indention=indention)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def get_names(self):
|
def get_set_vars(self):
|
||||||
"""
|
"""
|
||||||
Get all the names, that are active and accessible in the current
|
Get all the names, that are active and accessible in the current
|
||||||
scope.
|
scope.
|
||||||
@@ -157,7 +156,7 @@ class Scope(object):
|
|||||||
"""
|
"""
|
||||||
n = []
|
n = []
|
||||||
for stmt in self.statements:
|
for stmt in self.statements:
|
||||||
n += stmt.get_names()
|
n += stmt.get_set_vars()
|
||||||
|
|
||||||
# function and class names
|
# function and class names
|
||||||
n += [s.name for s in self.subscopes]
|
n += [s.name for s in self.subscopes]
|
||||||
@@ -210,6 +209,24 @@ class Class(Scope):
|
|||||||
str += "pass\n"
|
str += "pass\n"
|
||||||
return str
|
return str
|
||||||
|
|
||||||
|
def get_set_vars(self):
|
||||||
|
n = []
|
||||||
|
for s in self.subscopes:
|
||||||
|
try:
|
||||||
|
# get the self name, if there's one
|
||||||
|
self_name = s.params[0].used_vars[0].names[0]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for n2 in s.get_set_vars():
|
||||||
|
# Only names with the selfname are being added.
|
||||||
|
# It is also important, that they have a len() of 2,
|
||||||
|
# because otherwise, they are just something else
|
||||||
|
if n2.names[0] == self_name and len(n2.names) == 2:
|
||||||
|
n.append(n2)
|
||||||
|
n += super(Class, self).get_set_vars()
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
class Function(Scope):
|
class Function(Scope):
|
||||||
"""
|
"""
|
||||||
@@ -242,12 +259,11 @@ class Function(Scope):
|
|||||||
str += "pass\n"
|
str += "pass\n"
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def get_names(self):
|
def get_set_vars(self):
|
||||||
#n = self.params
|
|
||||||
n = []
|
n = []
|
||||||
for p in self.params:
|
for i, p in enumerate(self.params):
|
||||||
n += p.set_vars or p.used_vars
|
n += p.set_vars or p.used_vars
|
||||||
n += super(Function, self).get_names()
|
n += super(Function, self).get_set_vars()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
|
||||||
@@ -307,15 +323,15 @@ class Flow(Scope):
|
|||||||
str += self.next.get_code()
|
str += self.next.get_code()
|
||||||
return str
|
return str
|
||||||
|
|
||||||
def get_names(self):
|
def get_set_vars(self):
|
||||||
"""
|
"""
|
||||||
Get the names for the flow. This includes also a call to the super
|
Get the names for the flow. This includes also a call to the super
|
||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
n = self.set_vars
|
n = self.set_vars
|
||||||
if self.next:
|
if self.next:
|
||||||
n += self.next.get_names()
|
n += self.next.get_set_vars()
|
||||||
n += super(Flow, self).get_names()
|
n += super(Flow, self).get_set_vars()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def set_next(self, next):
|
def set_next(self, next):
|
||||||
@@ -410,7 +426,7 @@ class Statement(object):
|
|||||||
else:
|
else:
|
||||||
return self.code
|
return self.code
|
||||||
|
|
||||||
def get_names(self):
|
def get_set_vars(self):
|
||||||
""" Get the names for the statement. """
|
""" Get the names for the statement. """
|
||||||
return self.set_vars
|
return self.set_vars
|
||||||
|
|
||||||
@@ -847,9 +863,9 @@ class PyFuzzyParser(object):
|
|||||||
#print "_not_implemented_", tok, self.parserline
|
#print "_not_implemented_", tok, self.parserline
|
||||||
except StopIteration: # thrown on EOF
|
except StopIteration: # thrown on EOF
|
||||||
pass
|
pass
|
||||||
except StopIteration: # TODO catch the right error
|
#except StopIteration:
|
||||||
dbg("parse error: %s, %s @ %s" %
|
# dbg("parse error: %s, %s @ %s" %
|
||||||
(sys.exc_info()[0], sys.exc_info()[1], self.parserline))
|
# (sys.exc_info()[0], sys.exc_info()[1], self.parserline))
|
||||||
return self.top
|
return self.top
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
test.py
7
test.py
@@ -26,7 +26,7 @@ class Supi(A, datetime.datetime):
|
|||||||
class 2
|
class 2
|
||||||
|
|
||||||
static_var = 0
|
static_var = 0
|
||||||
def __init__():
|
def __init__(self):
|
||||||
self.b = A()
|
self.b = A()
|
||||||
def test(self):
|
def test(self):
|
||||||
import time
|
import time
|
||||||
@@ -36,6 +36,7 @@ class Supi(A, datetime.datetime):
|
|||||||
2,[3,2
|
2,[3,2
|
||||||
])
|
])
|
||||||
self.c = {1:3,
|
self.c = {1:3,
|
||||||
|
a = self.a
|
||||||
4:2,5:9}
|
4:2,5:9}
|
||||||
return A()
|
return A()
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ def ass_test(a):
|
|||||||
"""docstring for assignment test"""
|
"""docstring for assignment test"""
|
||||||
a -= 1
|
a -= 1
|
||||||
# (comment without indent)
|
# (comment without indent)
|
||||||
b, c, d = (1,2,3)
|
(b, c, d) = (1,2,3)
|
||||||
del b
|
del b
|
||||||
# test strange statements
|
# test strange statements
|
||||||
[a,c] ; {1: a}; (1,); `a`
|
[a,c] ; {1: a}; (1,); `a`
|
||||||
@@ -107,7 +108,7 @@ def flow_test(a):
|
|||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
pass
|
pass
|
||||||
return Matrix[0,m]
|
return matrix[0,m]
|
||||||
|
|
||||||
if True or a:
|
if True or a:
|
||||||
print a
|
print a
|
||||||
|
|||||||
Reference in New Issue
Block a user