star imports work now also in the start module

This commit is contained in:
David Halter
2012-04-19 00:04:24 +02:00
parent 900ee27192
commit 4365c80a53
6 changed files with 41 additions and 21 deletions

View File

@@ -244,5 +244,8 @@ class _Builtin(object):
def scope(self): def scope(self):
return self._builtins.parser.top return self._builtins.parser.top
def get_defined_names(self):
return self.scope.get_defined_names()
Builtin = _Builtin() Builtin = _Builtin()

View File

@@ -187,8 +187,12 @@ class Execution(Exec):
(self.__class__.__name__, self.base) (self.__class__.__name__, self.base)
def get_names_for_scope(scope): def get_names_for_scope(scope, star_search=True):
""" Get all completions possible for the current scope. """ """
Get all completions possible for the current scope.
The star search option is only here to provide an optimization. Otherwise
the whole thing would make a little recursive maddness
"""
compl = [] compl = []
start_scope = scope start_scope = scope
while scope: while scope:
@@ -199,6 +203,11 @@ def get_names_for_scope(scope):
# add builtins to the global scope # add builtins to the global scope
compl += builtin.Builtin.scope.get_defined_names() compl += builtin.Builtin.scope.get_defined_names()
# add star imports
if star_search:
for s in remove_star_imports(start_scope.get_parent_until()):
compl += get_names_for_scope(s, star_search=False)
#print 'gnfs', scope, compl #print 'gnfs', scope, compl
return compl return compl
@@ -229,15 +238,6 @@ def get_scopes_for_name(scope, name, search_global=False):
# the name is already given in the parent function # the name is already given in the parent function
result = [] result = []
for scope in scopes: for scope in scopes:
#if isinstance(scope, parsing.Import):
# try:
# debug.dbg('star import', scope)
# i = follow_import(scope).get_defined_names()
# except modules.ModuleNotFound:
# debug.dbg('StarImport not found: ' + str(scope))
# else:
# result += filter_name(i)
#else:
if [name] == list(scope.names): if [name] == list(scope.names):
if isinstance(scope, ArrayElement): if isinstance(scope, ArrayElement):
result.append(scope) result.append(scope)
@@ -410,10 +410,21 @@ def follow_import(_import):
else: else:
scopes = [scope] scopes = [scope]
for s in scopes: new = []
scopes += strip_imports(i for i in s.get_imports() if i.star) for scope in scopes:
new += remove_star_imports(scope)
scopes += new
debug.dbg('after import', scopes, rest) debug.dbg('after import', scopes, rest)
return scopes
def remove_star_imports(scope):
modules = strip_imports(i for i in scope.get_imports() if i.star)
new = []
for m in modules:
new += remove_star_imports(m)
modules += new
# filter duplicate modules # filter duplicate modules
return list(set(scopes)) return list(set(modules))

View File

@@ -2,7 +2,7 @@
import functions import functions
functions.debug.debug_function = functions.debug.print_to_stdout #functions.debug.debug_function = functions.debug.print_to_stdout
functions.debug.ignored_modules = ['parsing', 'builtin'] functions.debug.ignored_modules = ['parsing', 'builtin']
functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules'] functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules']
functions.modules.module_find_path.insert(0, '.') functions.modules.module_find_path.insert(0, '.')

View File

@@ -147,4 +147,4 @@ c = b().c3()
1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request; 1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request;
abc = [1,2+3]; abc[0]. abc = [1,2+3]; abc[0].
import pylab import pylab
abc = datetime; return [abc][0]. abc = datetime; return [abc][0]. ;pylab.

View File

@@ -244,7 +244,7 @@ class GlobalScope(Scope):
def get_set_vars(self): def get_set_vars(self):
n = super(GlobalScope, self).get_set_vars() n = super(GlobalScope, self).get_set_vars()
n += self.global_vars n += self.global_vars
return n return n
class Class(Scope): class Class(Scope):
@@ -1035,7 +1035,7 @@ class PyFuzzyParser(object):
:return: Statement + last parsed token. :return: Statement + last parsed token.
:rtype: (Statement, str) :rtype: (Statement, str)
TODO improve abort criterion of not closing parentheses TODO improve abort criterion of not closing parentheses
""" """
string = '' string = ''
@@ -1245,7 +1245,7 @@ class PyFuzzyParser(object):
while 1: while 1:
token_type, tok, indent = self.next() token_type, tok, indent = self.next()
if tok != '.': if tok != '.':
break; break
relative_count += 1 relative_count += 1
# the from import # the from import
mod, token_type, tok, start_indent, start_line2 = \ mod, token_type, tok, start_indent, start_line2 = \

View File

@@ -1,9 +1,15 @@
import os
def array(): def array():
return list() return list()
#? ['append'] #? ['append']
array().app array().append
#? ['array'] #? ['array']
arr arr
def inputs(param):
return param
#? ['append']
inputs(list).append