restructuring

This commit is contained in:
David Halter
2012-04-16 16:51:01 +02:00
parent c03bc8c714
commit dcf83069d9
5 changed files with 49 additions and 34 deletions

View File

@@ -21,11 +21,18 @@ class Parser(object):
""" This module tries to imitate parsing.Scope """ """ This module tries to imitate parsing.Scope """
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
self.parent = None self._content = {}
self.content = {}
exec 'import %s as module' % name in self.content
self.module = self.content['module']
self._parser = None self._parser = None
self._module = None
@property
def module(self):
if not self._module:
print 'import', self.name
exec 'import %s as module' % self.name in self._content
print 'import2', self.name
self._module = self._content['module']
return self._module
@property @property
def parser(self): def parser(self):
@@ -33,7 +40,7 @@ class Parser(object):
if self._parser: if self._parser:
return self._parser return self._parser
else: else:
code = self.generate_code(self.module) code = self._generate_code(self.module)
try: try:
self._parser = parsing.PyFuzzyParser(code) self._parser = parsing.PyFuzzyParser(code)
except: except:
@@ -42,7 +49,7 @@ class Parser(object):
raise raise
return self._parser return self._parser
def generate_code(self, scope, depth=0): def _generate_code(self, scope, depth=0):
""" """
Generate a string, which uses python syntax as an input to the Generate a string, which uses python syntax as an input to the
PyFuzzyParser. PyFuzzyParser.
@@ -88,7 +95,7 @@ class Parser(object):
bases = (c.__name__ for c in cl.__bases__) bases = (c.__name__ for c in cl.__bases__)
code += 'class %s(%s):\n' % (name, ','.join(bases)) code += 'class %s(%s):\n' % (name, ','.join(bases))
if depth == 0: if depth == 0:
cl_code = self.generate_code(cl, depth + 1) cl_code = self._generate_code(cl, depth + 1)
code += parsing.indent_block(cl_code) code += parsing.indent_block(cl_code)
code += '\n' code += '\n'
@@ -126,8 +133,8 @@ class Parser(object):
if depth == 0: if depth == 0:
#with open('writeout.py', 'w') as f: #with open('writeout.py', 'w') as f:
# f.write(code) # f.write(code)
#import sys import sys
#sys.stdout.write(code) sys.stdout.write(code)
#exit() #exit()
pass pass
return code return code

View File

@@ -55,7 +55,7 @@ def memoize(default=None):
class Exec(object): class Exec(object):
def __init__(self, base, params): def __init__(self, base, params=None):
self.base = base self.base = base
self.params = params self.params = params
@@ -250,6 +250,7 @@ def get_scopes_for_name(scope, name, search_global=False):
elif isinstance(par, parsing.Param): elif isinstance(par, parsing.Param):
if isinstance(par.parent.parent, parsing.Class) \ if isinstance(par.parent.parent, parsing.Class) \
and par.position == 0: and par.position == 0:
# this is where self is added
result.append(Instance(par.parent.parent)) result.append(Instance(par.parent.parent))
else: else:
# TODO get function data # TODO get function data

View File

@@ -75,7 +75,8 @@ def find_module(current_module, point_path):
path = [ns[1]] path = [ns[1]]
else: else:
path = None path = None
debug.dbg('search_module', string, path) debug.dbg('search_module', string, path,
current_module.module_path)
try: try:
i = imp.find_module(string, path) i = imp.find_module(string, path)
except ImportError: except ImportError:
@@ -86,7 +87,7 @@ def find_module(current_module, point_path):
raise raise
return i return i
# TODO handle relative paths - they are included int the import object # TODO handle relative paths - they are included in the import object
current_namespace = None current_namespace = None
sys.path.insert(0, os.path.dirname(current_module.module_path)) sys.path.insert(0, os.path.dirname(current_module.module_path))
# now execute those paths # now execute those paths
@@ -105,6 +106,7 @@ def find_module(current_module, point_path):
path = current_namespace[1] path = current_namespace[1]
is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY
f = None
if is_package_directory or current_namespace[0]: if is_package_directory or current_namespace[0]:
# is a directory module # is a directory module
if is_package_directory: if is_package_directory:
@@ -115,7 +117,11 @@ def find_module(current_module, point_path):
source = open(path).read() source = open(path).read()
else: else:
source = current_namespace[0].read() source = current_namespace[0].read()
if path.endswith('.py'):
f = File(path, source) f = File(path, source)
else: if not f:
print 'lala'
f = builtin.Parser(path) f = builtin.Parser(path)
print 'lala2'
return f.parser.top, rest return f.parser.top, rest

View File

@@ -138,13 +138,13 @@ class c1():
return c5+'asdf' return c5+'asdf'
(c1().c2.\ (c1().c2.\
c, 1, c3()) [0].pop() c, 1, c3()) [0].pop()
c = u"asdf".join([1,2]) c = u"asdf".join([1,2])
matrix_test = [[1,2], [1,3]] matrix_test = [[1,2], [1,3]]
c = c1().c3().sleep() c = c1().c3().sleep()
asdf = c1; asdf2 = asdf asdf = c1; asdf2 = asdf
b= asdf2 b= asdf2
#import parsing as test
c = b().c3() 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
pylab.

View File

@@ -10,6 +10,7 @@ import functions
#functions.set_debug_function(functions.debug.print_to_stdout) #functions.set_debug_function(functions.debug.print_to_stdout)
def completion_test(source): def completion_test(source):
""" """
This is the completion test for some cases. The tests are not unit test This is the completion test for some cases. The tests are not unit test