diff --git a/pycomplete.py b/pycomplete.py index 74ae9f2a..475ae99e 100755 --- a/pycomplete.py +++ b/pycomplete.py @@ -222,7 +222,13 @@ showdbg() print cmpl.parser.top.get_code() #print cmpl.parser.top.subscopes[1].subscopes[0].get_code() -#print cmpl.parser.top.get_locals() +names = cmpl.parser.top.get_names() +for n in names: + try: + print n.names + except: + print n.name + p = cmpl.parser s = p.top diff --git a/pyfuzzyparser.py b/pyfuzzyparser.py index 9dde9d45..4bcbee35 100644 --- a/pyfuzzyparser.py +++ b/pyfuzzyparser.py @@ -15,7 +15,7 @@ of the python module 'tokenize'. This original codebase of this parser, which has been refactored and heavily changed, was programmed by Aaron Griffin . -*The structure of the following script:* +**The structure of the following script:** A Scope has - imports (Import) - subscopes (Scope, Class, Function, Flow) @@ -97,6 +97,8 @@ class Scope(object): def add_docstr(self, str): """ Clean up a docstring """ + # TODO the docstring clean isn't good, because things like + # r""" test """ are not being handled d = str.replace('\n', ' ') d = d.replace('\t', ' ') while d.find(' ') > -1: @@ -139,6 +141,20 @@ class Scope(object): string = indent_block(string, indention=indention) return string + def get_names(self): + """ + Get all the names, that are active and accessible in the current + scope. + + :return: list of Name + :rtype: list + """ + n = [] + for stmt in self.statements: + n += stmt.get_names() + n += self.subscopes + return n + def is_empty(self): """ :return: True if there are no subscopes, imports and statements. @@ -207,7 +223,10 @@ class Flow(Scope): super(Flow, self).__init__(name, indent, line_nr, '') self.command = command self.statement = statement - self.set_args = set_args + if set_args == None: + self.set_args = [] + else: + self.set_args = set_args self.next = None def get_code(self, first_indent=False, indention=" "): @@ -227,6 +246,17 @@ class Flow(Scope): str += self.next.get_code() return str + def get_names(self): + """ + Get the names for the flow. This includes also a call to the super + class. + """ + n = self.set_args + if self.next: + n += self.next.get_names() + n += super(Flow, self).get_names() + return n + def set_next(self, next): """ Set the next element in the flow, those are else, except, etc. """ if self.next: @@ -342,6 +372,10 @@ class Statement(object): else: return self.code + def get_names(self): + """ Get the names for the statement. """ + return self.set_vars + class Name(object): """ diff --git a/test.py b/test.py index eed98ed4..73442fe0 100644 --- a/test.py +++ b/test.py @@ -15,7 +15,7 @@ class Intro(object): return string+"," class Supi(A, datetime.datetime): - """ test123 """ + r""" test123 """ class 2 static_var = 0 @@ -30,11 +30,15 @@ class A(): #class B(): def test(self): return A() +class init: + def __init__(self, a): + self.a = a a = A() b = a.test() c = a or b +c = a or c class Empty(): pass