From cc8ebb52801db5a1f94d2d964219f035259267a2 Mon Sep 17 00:00:00 2001 From: David Halter Date: Tue, 6 Mar 2012 17:58:58 +0100 Subject: [PATCH] get rid of the completer of Aaron Griffin --- pycomplete.py | 32 ++++++++++++++++++-------------- pyfuzzyparser.py | 20 +++++++++++++++++--- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/pycomplete.py b/pycomplete.py index b82c3f57..a7dc7d6b 100755 --- a/pycomplete.py +++ b/pycomplete.py @@ -205,22 +205,27 @@ def showdbg(): for d in debugstmts: print "DBG: %s " % d - -pyfuzzyparser.debug_function = pyfuzzyparser.dbg() -text = cStringIO.StringIO(open('test.py').read()) -cmpl = Completer() -cmpl.evalsource(text, 51) #print cmpl.sc.get_code() #all = cmpl.get_completions("cdef.", '') +showdbg() + #print "Completions:", len(all) #for c in all: # print c['word'], # print ',', #print '' -showdbg() -print cmpl.parser.top.get_code() +def show_debug(*args): + print args + +pyfuzzyparser.debug_function = show_debug + +text = open('test.py').read() +parser = pyfuzzyparser.PyFuzzyParser(text) + + +print parser.top.get_code() #print cmpl.parser.top.subscopes[1].subscopes[0].get_code() def handle_names(names): @@ -232,30 +237,29 @@ def handle_names(names): print 'star!', n.from_ns print 'global names:' -names = cmpl.parser.top.get_set_vars() +names = parser.top.get_set_vars() handle_names(names) print print 'func names:' -names = cmpl.parser.top.subscopes[7].get_set_vars() +names = parser.top.subscopes[7].get_set_vars() handle_names(names) print print 'class names:' -names = cmpl.parser.top.subscopes[2].get_set_vars() +names = parser.top.subscopes[2].get_set_vars() handle_names(names) -for s in cmpl.parser.top.subscopes[2].subscopes: +for s in parser.top.subscopes[2].subscopes: print 'method names:' names = s.get_set_vars() handle_names(names) print print 'start/end' -for s in cmpl.parser.top.subscopes: +for s in parser.top.subscopes: print repr(s) -p = cmpl.parser -s = p.top +s = parser.top import code sh = code.InteractiveConsole(locals=locals()) #sh.interact("InteractiveConsole") diff --git a/pyfuzzyparser.py b/pyfuzzyparser.py index f29169ad..64f969f5 100644 --- a/pyfuzzyparser.py +++ b/pyfuzzyparser.py @@ -482,13 +482,23 @@ class PyFuzzyParser(object): """ This class is used to parse a Python file, it then divides them into a class structure of different scopes. + + :param code: The codebase for the parser. + :type code: str + :param user_line: The line, the user is currently on. + :type user_line: int """ - def __init__(self): + def __init__(self, code, user_line=None): + self.user_line = user_line + self.code = code + # initialize global Scope self.top = Scope(0, 0) self.scope = self.top self.current = (None, None, None) + self.parse() + def _parsedotname(self, pre_used_token=None): """ The dot name parser parses a name, variable or function and returns @@ -773,11 +783,15 @@ class PyFuzzyParser(object): """ Generate the next tokenize pattern. """ type, tok, position, dummy, self.parserline = self.gen.next() (self.line_nr, indent) = position + if self.line_nr == self.user_line: + print 'user scope found [%s] =%s' % \ + (self.parserline.replace('\n', ''), self.scope.get_name()) + self.user_scope = self.scope self.last_token = self.current self.current = (type, tok, indent) return self.current - def parse(self, text): + def parse(self): """ The main part of the program. It analyzes the given code-text and returns a tree-like scope. For a more detailed description, see the @@ -788,7 +802,7 @@ class PyFuzzyParser(object): :raises: IndentationError """ - buf = cStringIO.StringIO(''.join(text) + '\n') + buf = cStringIO.StringIO(self.code) self.gen = tokenize.generate_tokens(buf.readline) self.currentscope = self.scope