1
0
forked from VimPlug/jedi

renamed all occurences of parsing

This commit is contained in:
David Halter
2013-02-05 16:29:39 +01:00
parent 42450f48dc
commit bc08ea9630
10 changed files with 148 additions and 149 deletions

View File

@@ -12,7 +12,7 @@ __all__ = ['Script', 'NotFoundError', 'set_debug_function', '_quick_complete']
import re import re
import os import os
import parsing import parsing_representation as pr
import dynamic import dynamic
import imports import imports
import evaluate import evaluate
@@ -129,13 +129,13 @@ class Script(object):
# Do the completion if there is no path before and no import stmt. # Do the completion if there is no path before and no import stmt.
u = self._parser.user_stmt u = self._parser.user_stmt
bs = builtin.Builtin.scope bs = builtin.Builtin.scope
if isinstance(u, parsing.Import): if isinstance(u, pr.Import):
if (u.relative_count > 0 or u.from_ns) and not re.search( if (u.relative_count > 0 or u.from_ns) and not re.search(
r'(,|from)\s*$|import\s+$', completion_line): r'(,|from)\s*$|import\s+$', completion_line):
completions += ((k, bs) for k completions += ((k, bs) for k
in keywords.get_keywords('import')) in keywords.get_keywords('import'))
if not path and not isinstance(u, parsing.Import): if not path and not isinstance(u, pr.Import):
# add keywords # add keywords
completions += ((k, bs) for k in keywords.get_keywords( completions += ((k, bs) for k in keywords.get_keywords(
all=True)) all=True))
@@ -179,7 +179,7 @@ class Script(object):
# matched to much. # matched to much.
return [] return []
if isinstance(user_stmt, parsing.Import): if isinstance(user_stmt, pr.Import):
scopes = [self._get_on_import_stmt(is_like_search)[0]] scopes = [self._get_on_import_stmt(is_like_search)[0]]
else: else:
# just parse one statement, take it and evaluate it # just parse one statement, take it and evaluate it
@@ -188,7 +188,7 @@ class Script(object):
return scopes return scopes
def _get_under_cursor_stmt(self, cursor_txt): def _get_under_cursor_stmt(self, cursor_txt):
r = parsing.Parser(cursor_txt, no_docstr=True) r = pr.Parser(cursor_txt, no_docstr=True)
try: try:
stmt = r.module.statements[0] stmt = r.module.statements[0]
except IndexError: except IndexError:
@@ -260,7 +260,7 @@ class Script(object):
""" """
definitions = set(defs) definitions = set(defs)
for d in defs: for d in defs:
if isinstance(d.parent, parsing.Import) \ if isinstance(d.parent, pr.Import) \
and d.start_pos == (0, 0): and d.start_pos == (0, 0):
i = imports.ImportPath(d.parent).follow(is_goto=True) i = imports.ImportPath(d.parent).follow(is_goto=True)
definitions.remove(d) definitions.remove(d)
@@ -274,7 +274,7 @@ class Script(object):
user_scope = self._parser.user_scope user_scope = self._parser.user_scope
definitions = set([user_scope.name]) definitions = set([user_scope.name])
search_name = unicode(user_scope.name) search_name = unicode(user_scope.name)
elif isinstance(user_stmt, parsing.Import): elif isinstance(user_stmt, pr.Import):
s, name_part = self._get_on_import_stmt() s, name_part = self._get_on_import_stmt()
try: try:
definitions = [s.follow(is_goto=True)[0]] definitions = [s.follow(is_goto=True)[0]]
@@ -291,7 +291,7 @@ class Script(object):
stmt = self._get_under_cursor_stmt(goto_path) stmt = self._get_under_cursor_stmt(goto_path)
defs, search_name = evaluate.goto(stmt) defs, search_name = evaluate.goto(stmt)
definitions = follow_inexistent_imports(defs) definitions = follow_inexistent_imports(defs)
if isinstance(user_stmt, parsing.Statement): if isinstance(user_stmt, pr.Statement):
if user_stmt.get_assignment_calls().start_pos > self.pos: if user_stmt.get_assignment_calls().start_pos > self.pos:
# The cursor must be after the start, otherwise the # The cursor must be after the start, otherwise the
# statement is just an assignee. # statement is just an assignee.
@@ -311,12 +311,12 @@ class Script(object):
""" """
user_stmt = self._parser.user_stmt user_stmt = self._parser.user_stmt
definitions, search_name = self._goto(add_import_name=True) definitions, search_name = self._goto(add_import_name=True)
if isinstance(user_stmt, parsing.Statement) \ if isinstance(user_stmt, pr.Statement) \
and self.pos < user_stmt.get_assignment_calls().start_pos: and self.pos < user_stmt.get_assignment_calls().start_pos:
# the search_name might be before `=` # the search_name might be before `=`
definitions = [v for v in user_stmt.set_vars definitions = [v for v in user_stmt.set_vars
if unicode(v.names[-1]) == search_name] if unicode(v.names[-1]) == search_name]
if not isinstance(user_stmt, parsing.Import): if not isinstance(user_stmt, pr.Import):
# import case is looked at with add_import_name option # import case is looked at with add_import_name option
definitions = dynamic.related_name_add_import_modules(definitions, definitions = dynamic.related_name_add_import_modules(definitions,
search_name) search_name)
@@ -326,7 +326,7 @@ class Script(object):
names = dynamic.related_names(definitions, search_name, module) names = dynamic.related_names(definitions, search_name, module)
for d in set(definitions): for d in set(definitions):
if isinstance(d, parsing.Module): if isinstance(d, pr.Module):
names.append(api_classes.RelatedName(d, d)) names.append(api_classes.RelatedName(d, d))
else: else:
names.append(api_classes.RelatedName(d.names[-1], d)) names.append(api_classes.RelatedName(d.names[-1], d))
@@ -351,7 +351,7 @@ class Script(object):
""" """
def check_user_stmt(user_stmt): def check_user_stmt(user_stmt):
if user_stmt is None \ if user_stmt is None \
or not isinstance(user_stmt, parsing.Statement): or not isinstance(user_stmt, pr.Statement):
return None, 0 return None, 0
ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls()) ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls())

View File

@@ -15,7 +15,7 @@ import helpers
import settings import settings
import evaluate import evaluate
import imports import imports
import parsing import parsing_representation as pr
import keywords import keywords
@@ -195,9 +195,9 @@ class Completion(BaseDefinition):
append = '(' append = '('
if settings.add_dot_after_module: if settings.add_dot_after_module:
if isinstance(self.base, parsing.Module): if isinstance(self.base, pr.Module):
append += '.' append += '.'
if isinstance(self.base, parsing.Param): if isinstance(self.base, pr.Param):
append += '=' append += '='
return dot + self.name.names[-1][self.like_name_length:] + append return dot + self.name.names[-1][self.like_name_length:] + append
@@ -241,9 +241,9 @@ class Completion(BaseDefinition):
numpy), it's just PITA-slow. numpy), it's just PITA-slow.
""" """
if self._followed_definitions is None: if self._followed_definitions is None:
if self.definition.isinstance(parsing.Statement): if self.definition.isinstance(pr.Statement):
defs = evaluate.follow_statement(self.definition) defs = evaluate.follow_statement(self.definition)
elif self.definition.isinstance(parsing.Import): elif self.definition.isinstance(pr.Import):
defs = imports.strip_imports([self.definition]) defs = imports.strip_imports([self.definition])
else: else:
return [self] return [self]
@@ -275,16 +275,16 @@ class Definition(BaseDefinition):
d = self.definition d = self.definition
if isinstance(d, evaluate.InstanceElement): if isinstance(d, evaluate.InstanceElement):
d = d.var d = d.var
if isinstance(d, evaluate.parsing.Name): if isinstance(d, pr.Name):
d = d.parent d = d.parent
if isinstance(d, evaluate.Array): if isinstance(d, evaluate.Array):
d = 'class ' + d.type d = 'class ' + d.type
elif isinstance(d, (parsing.Class, evaluate.Class, evaluate.Instance)): elif isinstance(d, (pr.Class, evaluate.Class, evaluate.Instance)):
d = 'class ' + unicode(d.name) d = 'class ' + unicode(d.name)
elif isinstance(d, (evaluate.Function, evaluate.parsing.Function)): elif isinstance(d, (evaluate.Function, pr.Function)):
d = 'def ' + unicode(d.name) d = 'def ' + unicode(d.name)
elif isinstance(d, evaluate.parsing.Module): elif isinstance(d, evaluate.pr.Module):
# only show module name # only show module name
d = 'module %s' % self.module_name d = 'module %s' % self.module_name
elif self.is_keyword: elif self.is_keyword:
@@ -305,7 +305,7 @@ class Definition(BaseDefinition):
`module.class.function` path. `module.class.function` path.
""" """
if self.module_path.endswith('.py') \ if self.module_path.endswith('.py') \
and not isinstance(self.definition, parsing.Module): and not isinstance(self.definition, pr.Module):
position = '@%s' % (self.line) position = '@%s' % (self.line)
else: else:
# is a builtin or module # is a builtin or module

View File

@@ -36,7 +36,7 @@ def get_sys_path():
class CachedModule(object): class CachedModule(object):
""" """
The base type for all modules, which is not to be confused with The base type for all modules, which is not to be confused with
`parsing.Module`. Caching happens here. `parsing_representation.Module`. Caching happens here.
""" """
def __init__(self, path=None, name=None): def __init__(self, path=None, name=None):

View File

@@ -3,7 +3,7 @@
import re import re
import evaluate import evaluate
import parsing import parsing_representation as pr
DOCSTRING_PARAM_PATTERNS = [ DOCSTRING_PARAM_PATTERNS = [
r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx
@@ -34,7 +34,7 @@ def follow_param(param):
param_str) param_str)
user_position = (2, 0) user_position = (2, 0)
p = parsing.Parser(param_str, None, user_position, p = pr.Parser(param_str, None, user_position,
no_docstr=True) no_docstr=True)
return evaluate.follow_statement(p.user_stmt) return evaluate.follow_statement(p.user_stmt)
return [] return []
@@ -98,7 +98,7 @@ def find_return_types(func):
if not type_str: if not type_str:
return [] return []
p = parsing.Parser(type_str, None, (1, 0), no_docstr=True) p = pr.Parser(type_str, None, (1, 0), no_docstr=True)
p.user_stmt.parent = func p.user_stmt.parent = func
return list(evaluate.follow_statement(p.user_stmt)) return list(evaluate.follow_statement(p.user_stmt))

View File

@@ -10,7 +10,7 @@ from __future__ import with_statement
import os import os
import cache import cache
import parsing import parsing_representation as pr
import modules import modules
import evaluate import evaluate
import helpers import helpers
@@ -124,7 +124,7 @@ def search_params(param):
return [] return []
for stmt in possible_stmts: for stmt in possible_stmts:
if not isinstance(stmt, parsing.Import): if not isinstance(stmt, pr.Import):
calls = _scan_array(stmt.get_assignment_calls(), func_name) calls = _scan_array(stmt.get_assignment_calls(), func_name)
for c in calls: for c in calls:
# no execution means that params cannot be set # no execution means that params cannot be set
@@ -141,10 +141,10 @@ def search_params(param):
result += evaluate.follow_statement(p.parent) result += evaluate.follow_statement(p.parent)
return result return result
func = param.get_parent_until(parsing.Function) func = param.get_parent_until(pr.Function)
current_module = param.get_parent_until() current_module = param.get_parent_until()
func_name = str(func.name) func_name = str(func.name)
if func_name == '__init__' and isinstance(func.parent, parsing.Class): if func_name == '__init__' and isinstance(func.parent, pr.Class):
func_name = str(func.parent.name) func_name = str(func.parent.name)
# get the param name # get the param name
@@ -189,13 +189,13 @@ def _scan_array(arr, search_name):
result = [] result = []
for sub in arr: for sub in arr:
for s in sub: for s in sub:
if isinstance(s, parsing.Array): if isinstance(s, pr.Array):
result += _scan_array(s, search_name) result += _scan_array(s, search_name)
elif isinstance(s, parsing.Call): elif isinstance(s, pr.Call):
s_new = s s_new = s
while s_new is not None: while s_new is not None:
n = s_new.name n = s_new.name
if isinstance(n, parsing.Name) and search_name in n.names: if isinstance(n, pr.Name) and search_name in n.names:
result.append(s) result.append(s)
if s_new.execution is not None: if s_new.execution is not None:
@@ -207,7 +207,7 @@ def _scan_array(arr, search_name):
@cache.memoize_default([]) @cache.memoize_default([])
def _check_array_additions(compare_array, module, is_list): def _check_array_additions(compare_array, module, is_list):
""" """
Checks if a `parsing.Array` has "add" statements: Checks if a `pr.Array` has "add" statements:
>>> a = [""] >>> a = [""]
>>> a.append(1) >>> a.append(1)
""" """
@@ -310,7 +310,7 @@ def check_array_instances(instance):
return helpers.generate_param_array([ai], instance.var_args.parent_stmt) return helpers.generate_param_array([ai], instance.var_args.parent_stmt)
class ArrayInstance(parsing.Base): class ArrayInstance(pr.Base):
""" """
Used for the usage of set() and list(). Used for the usage of set() and list().
This is definitely a hack, but a good one :-) This is definitely a hack, but a good one :-)
@@ -364,7 +364,7 @@ def related_names(definitions, search_name, mods):
follow = [] # There might be multiple search_name's in one call_path follow = [] # There might be multiple search_name's in one call_path
call_path = list(call.generate_call_path()) call_path = list(call.generate_call_path())
for i, name in enumerate(call_path): for i, name in enumerate(call_path):
# name is `parsing.NamePart`. # name is `pr.NamePart`.
if name == search_name: if name == search_name:
follow.append(call_path[:i + 1]) follow.append(call_path[:i + 1])
@@ -392,7 +392,7 @@ def related_names(definitions, search_name, mods):
except KeyError: except KeyError:
continue continue
for stmt in stmts: for stmt in stmts:
if isinstance(stmt, parsing.Import): if isinstance(stmt, pr.Import):
count = 0 count = 0
imps = [] imps = []
for i in stmt.get_all_import_names(): for i in stmt.get_all_import_names():
@@ -420,7 +420,7 @@ def related_name_add_import_modules(definitions, search_name):
""" Adds the modules of the imports """ """ Adds the modules of the imports """
new = set() new = set()
for d in definitions: for d in definitions:
if isinstance(d.parent, parsing.Import): if isinstance(d.parent, pr.Import):
s = imports.ImportPath(d.parent, direct_resolve=True) s = imports.ImportPath(d.parent, direct_resolve=True)
try: try:
new.add(s.follow(is_goto=True)[0]) new.add(s.follow(is_goto=True)[0])
@@ -438,7 +438,7 @@ def check_flow_information(flow, search_name, pos):
ensures that `k` is a string. ensures that `k` is a string.
""" """
result = [] result = []
if isinstance(flow, (parsing.Scope, fast_parser.Module)) and not result: if isinstance(flow, (pr.Scope, fast_parser.Module)) and not result:
for ass in reversed(flow.asserts): for ass in reversed(flow.asserts):
if pos is None or ass.start_pos > pos: if pos is None or ass.start_pos > pos:
continue continue
@@ -446,7 +446,7 @@ def check_flow_information(flow, search_name, pos):
if result: if result:
break break
if isinstance(flow, parsing.Flow) and not result: if isinstance(flow, pr.Flow) and not result:
if flow.command in ['if', 'while'] and len(flow.inits) == 1: if flow.command in ['if', 'while'] and len(flow.inits) == 1:
result = check_statement_information(flow.inits[0], search_name) result = check_statement_information(flow.inits[0], search_name)
return result return result
@@ -459,7 +459,7 @@ def check_statement_information(stmt, search_name):
call = ass.get_only_subelement() call = ass.get_only_subelement()
except AttributeError: except AttributeError:
assert False assert False
assert type(call) == parsing.Call and str(call.name) == 'isinstance' assert type(call) == pr.Call and str(call.name) == 'isinstance'
assert bool(call.execution) assert bool(call.execution)
# isinstance check # isinstance check
@@ -467,11 +467,11 @@ def check_statement_information(stmt, search_name):
assert len(isinst) == 2 # has two params assert len(isinst) == 2 # has two params
assert len(isinst[0]) == 1 assert len(isinst[0]) == 1
assert len(isinst[1]) == 1 assert len(isinst[1]) == 1
assert isinstance(isinst[0][0], parsing.Call) assert isinstance(isinst[0][0], pr.Call)
# names fit? # names fit?
assert str(isinst[0][0].name) == search_name assert str(isinst[0][0].name) == search_name
classes_call = isinst[1][0] # class_or_type_or_tuple classes_call = isinst[1][0] # class_or_type_or_tuple
assert isinstance(classes_call, parsing.Call) assert isinstance(classes_call, pr.Call)
result = [] result = []
for c in evaluate.follow_call(classes_call): for c in evaluate.follow_call(classes_call):
if isinstance(c, evaluate.Array): if isinstance(c, evaluate.Array):

View File

@@ -19,8 +19,7 @@ Evaluation of Python code in |jedi| is based on three assumptions:
That said, there's mainly one entry point in this script: ``follow_statement``. That said, there's mainly one entry point in this script: ``follow_statement``.
This is where autocompletion starts. Everything you want to complete is either This is where autocompletion starts. Everything you want to complete is either
a ``parsing.Statement`` or some special name like ``class``, which is easy to a ``Statement`` or some special name like ``class``, which is easy to complete.
complete.
Therefore you need to understand what follows after ``follow_statement``. Let's Therefore you need to understand what follows after ``follow_statement``. Let's
make an example: make an example:
@@ -84,7 +83,7 @@ import copy
import common import common
import cache import cache
import parsing import parsing_representation as pr
import debug import debug
import builtin import builtin
import imports import imports
@@ -100,13 +99,13 @@ class DecoratorNotFound(LookupError):
pass pass
class Executable(parsing.Base): class Executable(pr.Base):
""" An instance is also an executable - because __init__ is called """ """ An instance is also an executable - because __init__ is called """
def __init__(self, base, var_args=None): def __init__(self, base, var_args=None):
self.base = base self.base = base
# The param input array. # The param input array.
if var_args is None: if var_args is None:
var_args = parsing.Array(None, None) var_args = pr.Array(None, None)
self.var_args = var_args self.var_args = var_args
def get_parent_until(self, *args, **kwargs): def get_parent_until(self, *args, **kwargs):
@@ -161,7 +160,7 @@ class Instance(use_metaclass(cache.CachedMetaClass, Executable)):
# This loop adds the names of the self object, copies them and removes # This loop adds the names of the self object, copies them and removes
# the self. # the self.
for sub in self.base.subscopes: for sub in self.base.subscopes:
if isinstance(sub, parsing.Class): if isinstance(sub, pr.Class):
continue continue
# Get the self name, if there's one. # Get the self name, if there's one.
self_name = self.get_func_self_name(sub) self_name = self.get_func_self_name(sub)
@@ -256,9 +255,9 @@ class InstanceElement(use_metaclass(cache.CachedMetaClass)):
variable (e.g. self.variable or class methods). variable (e.g. self.variable or class methods).
""" """
def __init__(self, instance, var, is_class_var=False): def __init__(self, instance, var, is_class_var=False):
if isinstance(var, parsing.Function): if isinstance(var, pr.Function):
var = Function(var) var = Function(var)
elif isinstance(var, parsing.Class): elif isinstance(var, pr.Class):
var = Class(var) var = Class(var)
self.instance = instance self.instance = instance
self.var = var self.var = var
@@ -269,15 +268,15 @@ class InstanceElement(use_metaclass(cache.CachedMetaClass)):
def parent(self): def parent(self):
par = self.var.parent par = self.var.parent
if isinstance(par, Class) and par == self.instance.base \ if isinstance(par, Class) and par == self.instance.base \
or isinstance(par, parsing.Class) \ or isinstance(par, pr.Class) \
and par == self.instance.base.base: and par == self.instance.base.base:
par = self.instance par = self.instance
elif not isinstance(par, parsing.Module): elif not isinstance(par, pr.Module):
par = InstanceElement(self.instance, par, self.is_class_var) par = InstanceElement(self.instance, par, self.is_class_var)
return par return par
def get_parent_until(self, *args, **kwargs): def get_parent_until(self, *args, **kwargs):
return parsing.Simple.get_parent_until(self, *args, **kwargs) return pr.Simple.get_parent_until(self, *args, **kwargs)
def get_decorated_func(self): def get_decorated_func(self):
""" Needed because the InstanceElement should not be stripped """ """ Needed because the InstanceElement should not be stripped """
@@ -306,9 +305,9 @@ class InstanceElement(use_metaclass(cache.CachedMetaClass)):
return "<%s of %s>" % (type(self).__name__, self.var) return "<%s of %s>" % (type(self).__name__, self.var)
class Class(use_metaclass(cache.CachedMetaClass, parsing.Base)): class Class(use_metaclass(cache.CachedMetaClass, pr.Base)):
""" """
This class is not only important to extend `parsing.Class`, it is also a This class is not only important to extend `pr.Class`, it is also a
important for descriptors (if the descriptor methods are evaluated or not). important for descriptors (if the descriptor methods are evaluated or not).
""" """
def __init__(self, base): def __init__(self, base):
@@ -372,7 +371,7 @@ class Class(use_metaclass(cache.CachedMetaClass, parsing.Base)):
return "<e%s of %s>" % (type(self).__name__, self.base) return "<e%s of %s>" % (type(self).__name__, self.base)
class Function(use_metaclass(cache.CachedMetaClass, parsing.Base)): class Function(use_metaclass(cache.CachedMetaClass, pr.Base)):
""" """
Needed because of decorators. Decorators are evaluated here. Needed because of decorators. Decorators are evaluated here.
""" """
@@ -419,7 +418,7 @@ class Function(use_metaclass(cache.CachedMetaClass, parsing.Base)):
f = wrappers[0] f = wrappers[0]
debug.dbg('decorator end', f) debug.dbg('decorator end', f)
if f != self.base_func and isinstance(f, parsing.Function): if f != self.base_func and isinstance(f, pr.Function):
f = Function(f) f = Function(f)
return f return f
@@ -489,12 +488,12 @@ class Execution(Executable):
objects = follow_call_list([self.var_args[0]]) objects = follow_call_list([self.var_args[0]])
return [o.base for o in objects if isinstance(o, Instance)] return [o.base for o in objects if isinstance(o, Instance)]
elif func_name == 'super': elif func_name == 'super':
accept = (parsing.Function,) accept = (pr.Function,)
func = self.var_args.parent_stmt.get_parent_until(accept) func = self.var_args.parent_stmt.get_parent_until(accept)
if func.isinstance(*accept): if func.isinstance(*accept):
cls = func.get_parent_until(accept + (parsing.Class,), cls = func.get_parent_until(accept + (pr.Class,),
include_current=False) include_current=False)
if isinstance(cls, parsing.Class): if isinstance(cls, pr.Class):
cls = Class(cls) cls = Class(cls)
su = cls.get_super_classes() su = cls.get_super_classes()
if su: if su:
@@ -546,7 +545,7 @@ class Execution(Executable):
def get_params(self): def get_params(self):
""" """
This returns the params for an Execution/Instance and is injected as a This returns the params for an Execution/Instance and is injected as a
'hack' into the parsing.Function class. 'hack' into the pr.Function class.
This needs to be here, because Instance can have __init__ functions, This needs to be here, because Instance can have __init__ functions,
which act the same way as normal functions. which act the same way as normal functions.
""" """
@@ -556,7 +555,7 @@ class Execution(Executable):
""" """
parent_stmt = self.var_args.parent_stmt parent_stmt = self.var_args.parent_stmt
pos = parent_stmt.start_pos if parent_stmt else None pos = parent_stmt.start_pos if parent_stmt else None
calls = parsing.Array(pos, parsing.Array.NOARRAY, parent_stmt) calls = pr.Array(pos, pr.Array.NOARRAY, parent_stmt)
calls.values = values calls.values = values
calls.keys = keys calls.keys = keys
calls.type = array_type calls.type = array_type
@@ -615,7 +614,7 @@ class Execution(Executable):
array_type = None array_type = None
if assignment[0] == '*': if assignment[0] == '*':
# *args param # *args param
array_type = parsing.Array.TUPLE array_type = pr.Array.TUPLE
if value: if value:
values.append(value) values.append(value)
for key, value in var_arg_iterator: for key, value in var_arg_iterator:
@@ -626,7 +625,7 @@ class Execution(Executable):
values.append(value) values.append(value)
elif assignment[0] == '**': elif assignment[0] == '**':
# **kwargs param # **kwargs param
array_type = parsing.Array.DICT array_type = pr.Array.DICT
if non_matching_keys: if non_matching_keys:
keys, values = zip(*non_matching_keys) keys, values = zip(*non_matching_keys)
else: else:
@@ -681,10 +680,10 @@ class Execution(Executable):
if hasattr(array, 'get_contents'): if hasattr(array, 'get_contents'):
for key, field in array.get_contents(): for key, field in array.get_contents():
# Take the first index. # Take the first index.
if isinstance(key, parsing.Name): if isinstance(key, pr.Name):
name = key name = key
else: else:
# `parsing`.[Call|Function|Class] lookup. # `pr`.[Call|Function|Class] lookup.
name = key[0].name name = key[0].name
yield name, field yield name, field
# Normal arguments (including key arguments). # Normal arguments (including key arguments).
@@ -705,7 +704,7 @@ class Execution(Executable):
Call the default method with the own instance (self implements all Call the default method with the own instance (self implements all
the necessary functions). Add also the params. the necessary functions). Add also the params.
""" """
return self.get_params() + parsing.Scope.get_set_vars(self) return self.get_params() + pr.Scope.get_set_vars(self)
def copy_properties(self, prop): def copy_properties(self, prop):
""" """
@@ -724,7 +723,7 @@ class Execution(Executable):
else: else:
copied = helpers.fast_parent_copy(element) copied = helpers.fast_parent_copy(element)
copied.parent = self._scope_copy(copied.parent) copied.parent = self._scope_copy(copied.parent)
if isinstance(copied, parsing.Function): if isinstance(copied, pr.Function):
copied = Function(copied) copied = Function(copied)
objects.append(copied) objects.append(copied)
return objects return objects
@@ -774,14 +773,14 @@ class Execution(Executable):
return self.copy_properties('subscopes') return self.copy_properties('subscopes')
def get_statement_for_position(self, pos): def get_statement_for_position(self, pos):
return parsing.Scope.get_statement_for_position(self, pos) return pr.Scope.get_statement_for_position(self, pos)
def __repr__(self): def __repr__(self):
return "<%s of %s>" % \ return "<%s of %s>" % \
(type(self).__name__, self.base) (type(self).__name__, self.base)
class Generator(use_metaclass(cache.CachedMetaClass, parsing.Base)): class Generator(use_metaclass(cache.CachedMetaClass, pr.Base)):
""" Cares for `yield` statements. """ """ Cares for `yield` statements. """
def __init__(self, func, var_args): def __init__(self, func, var_args):
super(Generator, self).__init__() super(Generator, self).__init__()
@@ -797,7 +796,7 @@ class Generator(use_metaclass(cache.CachedMetaClass, parsing.Base)):
none_pos = (0, 0) none_pos = (0, 0)
executes_generator = ('__next__', 'send') executes_generator = ('__next__', 'send')
for n in ('close', 'throw') + executes_generator: for n in ('close', 'throw') + executes_generator:
name = parsing.Name(builtin.Builtin.scope, [(n, none_pos)], name = pr.Name(builtin.Builtin.scope, [(n, none_pos)],
none_pos, none_pos) none_pos, none_pos)
if n in executes_generator: if n in executes_generator:
name.parent = self name.parent = self
@@ -821,9 +820,9 @@ class Generator(use_metaclass(cache.CachedMetaClass, parsing.Base)):
return "<%s of %s>" % (type(self).__name__, self.func) return "<%s of %s>" % (type(self).__name__, self.func)
class Array(use_metaclass(cache.CachedMetaClass, parsing.Base)): class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
""" """
Used as a mirror to parsing.Array, if needed. It defines some getter Used as a mirror to pr.Array, if needed. It defines some getter
methods which are important in this module. methods which are important in this module.
""" """
def __init__(self, array): def __init__(self, array):
@@ -858,7 +857,7 @@ class Array(use_metaclass(cache.CachedMetaClass, parsing.Base)):
def get_exact_index_types(self, index): def get_exact_index_types(self, index):
""" Here the index is an int. Raises IndexError/KeyError """ """ Here the index is an int. Raises IndexError/KeyError """
if self._array.type == parsing.Array.DICT: if self._array.type == pr.Array.DICT:
old_index = index old_index = index
index = None index = None
for i, key_elements in enumerate(self._array.keys): for i, key_elements in enumerate(self._array.keys):
@@ -885,7 +884,7 @@ class Array(use_metaclass(cache.CachedMetaClass, parsing.Base)):
def get_defined_names(self): def get_defined_names(self):
""" """
This method generates all ArrayElements for one parsing.Array. This method generates all ArrayElements for one pr.Array.
It returns e.g. for a list: append, pop, ... It returns e.g. for a list: append, pop, ...
""" """
# `array.type` is a string with the type, e.g. 'list'. # `array.type` is a string with the type, e.g. 'list'.
@@ -949,7 +948,7 @@ def get_defined_names_for_position(scope, position=None, start_scope=None):
# because class variables are always valid and the `self.` variables, too. # because class variables are always valid and the `self.` variables, too.
if (not position or isinstance(scope, (Array, Instance)) if (not position or isinstance(scope, (Array, Instance))
or start_scope != scope or start_scope != scope
and isinstance(start_scope, (parsing.Function, Execution))): and isinstance(start_scope, (pr.Function, Execution))):
return names return names
names_new = [] names_new = []
for n in names: for n in names:
@@ -966,13 +965,13 @@ def get_names_for_scope(scope, position=None, star_search=True,
the whole thing would probably start a little recursive madness. the whole thing would probably start a little recursive madness.
""" """
in_func_scope = scope in_func_scope = scope
non_flow = scope.get_parent_until(parsing.Flow, reverse=True) non_flow = scope.get_parent_until(pr.Flow, reverse=True)
while scope: while scope:
# `parsing.Class` is used, because the parent is never `Class`. # `pr.Class` is used, because the parent is never `Class`.
# Ignore the Flows, because the classes and functions care for that. # Ignore the Flows, because the classes and functions care for that.
# InstanceElement of Class is ignored, if it is not the start scope. # InstanceElement of Class is ignored, if it is not the start scope.
if not (scope != non_flow and scope.isinstance(parsing.Class) if not (scope != non_flow and scope.isinstance(pr.Class)
or scope.isinstance(parsing.Flow) or scope.isinstance(pr.Flow)
or scope.isinstance(Instance) or scope.isinstance(Instance)
and non_flow.isinstance(Function) and non_flow.isinstance(Function)
): ):
@@ -985,14 +984,14 @@ def get_names_for_scope(scope, position=None, star_search=True,
position, in_func_scope) position, in_func_scope)
except StopIteration: except StopIteration:
raise common.MultiLevelStopIteration('StopIteration raised') raise common.MultiLevelStopIteration('StopIteration raised')
if scope.isinstance(parsing.ForFlow) and scope.is_list_comp: if scope.isinstance(pr.ForFlow) and scope.is_list_comp:
# is a list comprehension # is a list comprehension
yield scope, scope.get_set_vars(is_internal_call=True) yield scope, scope.get_set_vars(is_internal_call=True)
scope = scope.parent scope = scope.parent
# This is used, because subscopes (Flow scopes) would distort the # This is used, because subscopes (Flow scopes) would distort the
# results. # results.
if scope and scope.isinstance(Function, parsing.Function, Execution): if scope and scope.isinstance(Function, pr.Function, Execution):
in_func_scope = scope in_func_scope = scope
# Add star imports. # Add star imports.
@@ -1028,7 +1027,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
res_new = [] res_new = []
for r in result: for r in result:
add = [] add = []
if r.isinstance(parsing.Statement): if r.isinstance(pr.Statement):
check_instance = None check_instance = None
if isinstance(r, InstanceElement) and r.is_class_var: if isinstance(r, InstanceElement) and r.is_class_var:
check_instance = r.instance check_instance = r.instance
@@ -1037,14 +1036,14 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
# Global variables handling. # Global variables handling.
if r.is_global(): if r.is_global():
for token_name in r.token_list[1:]: for token_name in r.token_list[1:]:
if isinstance(token_name, parsing.Name): if isinstance(token_name, pr.Name):
add = get_scopes_for_name(r.parent, add = get_scopes_for_name(r.parent,
str(token_name)) str(token_name))
else: else:
# generated objects are used within executions, but these # generated objects are used within executions, but these
# objects are in functions, and we have to dynamically # objects are in functions, and we have to dynamically
# execute first. # execute first.
if isinstance(r, parsing.Param): if isinstance(r, pr.Param):
func = r.parent func = r.parent
# Instances are typically faked, if the instance is not # Instances are typically faked, if the instance is not
# called from outside. Here we check it for __init__ # called from outside. Here we check it for __init__
@@ -1075,13 +1074,13 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
if check_instance is not None: if check_instance is not None:
# class renames # class renames
add = [InstanceElement(check_instance, a, True) add = [InstanceElement(check_instance, a, True)
if isinstance(a, (Function, parsing.Function)) if isinstance(a, (Function, pr.Function))
else a for a in add] else a for a in add]
res_new += add res_new += add
else: else:
if isinstance(r, parsing.Class): if isinstance(r, pr.Class):
r = Class(r) r = Class(r)
elif isinstance(r, parsing.Function): elif isinstance(r, pr.Function):
r = Function(r) r = Function(r)
if r.isinstance(Function): if r.isinstance(Function):
try: try:
@@ -1117,14 +1116,14 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
no_break_scope = False no_break_scope = False
par = name.parent par = name.parent
if par.isinstance(parsing.Flow): if par.isinstance(pr.Flow):
if par.command == 'for': if par.command == 'for':
result += handle_for_loops(par) result += handle_for_loops(par)
else: else:
debug.warning('Flow: Why are you here? %s' % par.command) debug.warning('Flow: Why are you here? %s' % par.command)
elif par.isinstance(parsing.Param) \ elif par.isinstance(pr.Param) \
and par.parent is not None \ and par.parent is not None \
and par.parent.parent.isinstance(parsing.Class) \ and par.parent.parent.isinstance(pr.Class) \
and par.position_nr == 0: and par.position_nr == 0:
# This is where self gets added - this happens at another # This is where self gets added - this happens at another
# place, if the var_args are clear. But sometimes the class is # place, if the var_args are clear. But sometimes the class is
@@ -1136,14 +1135,14 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
inst = Instance(Class(par.parent.parent)) inst = Instance(Class(par.parent.parent))
inst.is_generated = True inst.is_generated = True
result.append(inst) result.append(inst)
elif par.isinstance(parsing.Statement): elif par.isinstance(pr.Statement):
def is_execution(arr): def is_execution(arr):
for a in arr: for a in arr:
a = a[0] # rest is always empty with assignees a = a[0] # rest is always empty with assignees
if a.isinstance(parsing.Array): if a.isinstance(pr.Array):
if is_execution(a): if is_execution(a):
return True return True
elif a.isinstance(parsing.Call): elif a.isinstance(pr.Call):
# Compare start_pos, because names may be different # Compare start_pos, because names may be different
# because of executions. # because of executions.
if a.name.start_pos == name.start_pos \ if a.name.start_pos == name.start_pos \
@@ -1185,7 +1184,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
for name in sorted(name_list, key=comparison_func, reverse=True): for name in sorted(name_list, key=comparison_func, reverse=True):
p = name.parent.parent if name.parent else None p = name.parent.parent if name.parent else None
if isinstance(p, InstanceElement) \ if isinstance(p, InstanceElement) \
and isinstance(p.var, parsing.Class): and isinstance(p.var, pr.Class):
p = p.var p = p.var
if name_str == name.get_code() and p not in break_scopes: if name_str == name.get_code() and p not in break_scopes:
r, no_break_scope = process(name) r, no_break_scope = process(name)
@@ -1249,7 +1248,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
if isinstance(scope, Instance): if isinstance(scope, Instance):
scope_generator = scope.scope_generator() scope_generator = scope.scope_generator()
else: else:
if isinstance(scope, (Class, parsing.Module)): if isinstance(scope, (Class, pr.Module)):
# classes are only available directly via chaining? # classes are only available directly via chaining?
# strange stuff... # strange stuff...
names = scope.get_defined_names() names = scope.get_defined_names()
@@ -1265,7 +1264,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False,
def check_getattr(inst, name_str): def check_getattr(inst, name_str):
result = [] result = []
# str is important to lose the NamePart! # str is important to lose the NamePart!
name = parsing.Call(str(name_str), parsing.Call.STRING, (0, 0), inst) name = pr.Call(str(name_str), pr.Call.STRING, (0, 0), inst)
args = helpers.generate_param_array([name]) args = helpers.generate_param_array([name])
try: try:
result = inst.execute_subscope_by_name('__getattr__', args) result = inst.execute_subscope_by_name('__getattr__', args)
@@ -1330,7 +1329,7 @@ def assign_tuples(tup, results, seek_name):
Here, if seek_name is "a", the number type will be returned. Here, if seek_name is "a", the number type will be returned.
The first part (before `=`) is the param tuples, the second one result. The first part (before `=`) is the param tuples, the second one result.
:type tup: parsing.Array :type tup: pr.Array
""" """
def eval_results(index): def eval_results(index):
types = [] types = []
@@ -1347,10 +1346,10 @@ def assign_tuples(tup, results, seek_name):
return types return types
result = [] result = []
if tup.type == parsing.Array.NOARRAY: if tup.type == pr.Array.NOARRAY:
# Here we have unnessecary braces, which we just remove. # Here we have unnessecary braces, which we just remove.
arr = tup.get_only_subelement() arr = tup.get_only_subelement()
if type(arr) == parsing.Call: if type(arr) == pr.Call:
if arr.name.names[-1] == seek_name: if arr.name.names[-1] == seek_name:
result = results result = results
else: else:
@@ -1364,7 +1363,7 @@ def assign_tuples(tup, results, seek_name):
t = t[0] t = t[0]
# Check the left part, if there are still tuples in it or a Call. # Check the left part, if there are still tuples in it or a Call.
if isinstance(t, parsing.Array): if isinstance(t, pr.Array):
# These are "sub"-tuples. # These are "sub"-tuples.
result += assign_tuples(t, eval_results(i), seek_name) result += assign_tuples(t, eval_results(i), seek_name)
else: else:
@@ -1382,7 +1381,7 @@ def follow_statement(stmt, seek_name=None):
In case multiple names are defined in the statement, `seek_name` returns In case multiple names are defined in the statement, `seek_name` returns
the result for this name. the result for this name.
:param stmt: A `parsing.Statement`. :param stmt: A `pr.Statement`.
:param seek_name: A string. :param seek_name: A string.
""" """
debug.dbg('follow_stmt %s (%s)' % (stmt, seek_name)) debug.dbg('follow_stmt %s (%s)' % (stmt, seek_name))
@@ -1409,28 +1408,27 @@ def follow_statement(stmt, seek_name=None):
def follow_call_list(call_list, follow_array=False): def follow_call_list(call_list, follow_array=False):
""" """
The call_list has a special structure. The call_list has a special structure.
This can be either `parsing.Array` or `list of list`. This can be either `pr.Array` or `list of list`.
It is used to evaluate a two dimensional object, that has calls, arrays and It is used to evaluate a two dimensional object, that has calls, arrays and
operators in it. operators in it.
""" """
def evaluate_list_comprehension(lc, parent=None): def evaluate_list_comprehension(lc, parent=None):
input = lc.input input = lc.input
nested_lc = lc.input.token_list[0] nested_lc = lc.input.token_list[0]
if isinstance(nested_lc, parsing.ListComprehension): if isinstance(nested_lc, pr.ListComprehension):
# is nested LC # is nested LC
input = nested_lc.stmt input = nested_lc.stmt
module = input.get_parent_until() module = input.get_parent_until()
loop = parsing.ForFlow(module, [input], lc.stmt.start_pos, loop = pr.ForFlow(module, [input], lc.stmt.start_pos,
lc.middle, True) lc.middle, True)
loop.parent = lc.stmt.parent if parent is None else parent loop.parent = lc.stmt.parent if parent is None else parent
if isinstance(nested_lc, parsing.ListComprehension): if isinstance(nested_lc, pr.ListComprehension):
loop = evaluate_list_comprehension(nested_lc, loop) loop = evaluate_list_comprehension(nested_lc, loop)
return loop return loop
if parsing.Array.is_type(call_list, parsing.Array.TUPLE, if pr.Array.is_type(call_list, pr.Array.TUPLE, pr.Array.DICT):
parsing.Array.DICT):
# Tuples can stand just alone without any braces. These would be # Tuples can stand just alone without any braces. These would be
# recognized as separate calls, but actually are a tuple. # recognized as separate calls, but actually are a tuple.
result = follow_call(call_list) result = follow_call(call_list)
@@ -1439,9 +1437,9 @@ def follow_call_list(call_list, follow_array=False):
for calls in call_list: for calls in call_list:
calls_iterator = iter(calls) calls_iterator = iter(calls)
for call in calls_iterator: for call in calls_iterator:
if parsing.Array.is_type(call, parsing.Array.NOARRAY): if pr.Array.is_type(call, pr.Array.NOARRAY):
result += follow_call_list(call, follow_array=True) result += follow_call_list(call, follow_array=True)
elif isinstance(call, parsing.ListComprehension): elif isinstance(call, pr.ListComprehension):
loop = evaluate_list_comprehension(call) loop = evaluate_list_comprehension(call)
stmt = copy.copy(call.stmt) stmt = copy.copy(call.stmt)
stmt.parent = loop stmt.parent = loop
@@ -1449,7 +1447,7 @@ def follow_call_list(call_list, follow_array=False):
# comprehensions # comprehensions
result += follow_statement(stmt) result += follow_statement(stmt)
else: else:
if isinstance(call, (parsing.Lambda)): if isinstance(call, (pr.Lambda)):
result.append(Function(call)) result.append(Function(call))
# With things like params, these can also be functions... # With things like params, these can also be functions...
elif isinstance(call, (Function, Class, Instance, elif isinstance(call, (Function, Class, Instance,
@@ -1478,7 +1476,7 @@ def follow_call_list(call_list, follow_array=False):
# if it is an iterable, ignore * operations # if it is an iterable, ignore * operations
next(calls_iterator) next(calls_iterator)
if follow_array and isinstance(call_list, parsing.Array): if follow_array and isinstance(call_list, pr.Array):
# call_list can also be a two dimensional array # call_list can also be a two dimensional array
call_path = call_list.generate_call_path() call_path = call_list.generate_call_path()
next(call_path, None) # the first one has been used already next(call_path, None) # the first one has been used already
@@ -1497,18 +1495,18 @@ def follow_call(call):
def follow_call_path(path, scope, position): def follow_call_path(path, scope, position):
""" Follows a path generated by `parsing.Call.generate_call_path()` """ """ Follows a path generated by `pr.Call.generate_call_path()` """
current = next(path) current = next(path)
if isinstance(current, parsing.Array): if isinstance(current, pr.Array):
result = [Array(current)] result = [Array(current)]
else: else:
if isinstance(current, parsing.NamePart): if isinstance(current, pr.NamePart):
# This is the first global lookup. # This is the first global lookup.
scopes = get_scopes_for_name(scope, current, position=position, scopes = get_scopes_for_name(scope, current, position=position,
search_global=True) search_global=True)
else: else:
if current.type in (parsing.Call.STRING, parsing.Call.NUMBER): if current.type in (pr.Call.STRING, pr.Call.NUMBER):
t = type(current.name).__name__ t = type(current.name).__name__
scopes = get_scopes_for_name(builtin.Builtin.scope, t) scopes = get_scopes_for_name(builtin.Builtin.scope, t)
else: else:
@@ -1559,12 +1557,12 @@ def follow_path(path, scope, call_scope, position=None):
debug.dbg('follow %s in scope %s' % (current, scope)) debug.dbg('follow %s in scope %s' % (current, scope))
result = [] result = []
if isinstance(current, parsing.Array): if isinstance(current, pr.Array):
# This must be an execution, either () or []. # This must be an execution, either () or [].
if current.type == parsing.Array.LIST: if current.type == pr.Array.LIST:
if hasattr(scope, 'get_index_types'): if hasattr(scope, 'get_index_types'):
result = scope.get_index_types(current) result = scope.get_index_types(current)
elif current.type not in [parsing.Array.DICT]: elif current.type not in [pr.Array.DICT]:
# Scope must be a class or func - make an instance or execution. # Scope must be a class or func - make an instance or execution.
debug.dbg('exe', scope) debug.dbg('exe', scope)
result = Execution(scope, current).get_return_types() result = Execution(scope, current).get_return_types()
@@ -1587,7 +1585,7 @@ def follow_path(path, scope, call_scope, position=None):
def filter_private_variable(scope, call_scope, var_name): def filter_private_variable(scope, call_scope, var_name):
if isinstance(var_name, (str, unicode)) \ if isinstance(var_name, (str, unicode)) \
and var_name.startswith('__') and isinstance(scope, Instance): and var_name.startswith('__') and isinstance(scope, Instance):
s = call_scope.get_parent_until((parsing.Class, Instance)) s = call_scope.get_parent_until((pr.Class, Instance))
if s != scope and s != scope.base.base: if s != scope and s != scope.base.base:
return True return True
return False return False

View File

@@ -4,10 +4,11 @@ import operator
from _compatibility import use_metaclass, reduce, property from _compatibility import use_metaclass, reduce, property
import settings import settings
import parsing import parsing
import parsing_representation as pr
import cache import cache
class Module(parsing.Simple, parsing.Module): class Module(pr.Simple, pr.Module):
def __init__(self, parsers): def __init__(self, parsers):
self._end_pos = None, None self._end_pos = None, None
super(Module, self).__init__(self, (1,0)) super(Module, self).__init__(self, (1,0))
@@ -141,7 +142,7 @@ class CachedFastParser(type):
return parsing.Parser(source, module_path, user_position) return parsing.Parser(source, module_path, user_position)
pi = cache.parser_cache.get(module_path, None) pi = cache.parser_cache.get(module_path, None)
if pi is None or isinstance(pi.parser, parsing.Parser): if pi is None or isinstance(pi.parser, pr.Parser):
p = super(CachedFastParser, self).__call__(source, module_path, p = super(CachedFastParser, self).__call__(source, module_path,
user_position) user_position)
else: else:
@@ -152,7 +153,7 @@ class CachedFastParser(type):
class FastParser(use_metaclass(CachedFastParser)): class FastParser(use_metaclass(CachedFastParser)):
def __init__(self, code, module_path=None, user_position=None): def __init__(self, code, module_path=None, user_position=None):
# set values like `parsing.Module`. # set values like `pr.Module`.
self.module_path = module_path self.module_path = module_path
self.user_position = user_position self.user_position = user_position
@@ -168,11 +169,11 @@ class FastParser(use_metaclass(CachedFastParser)):
for p in self.parsers: for p in self.parsers:
if p.user_scope: if p.user_scope:
if self._user_scope is not None and not \ if self._user_scope is not None and not \
isinstance(self._user_scope, parsing.SubModule): isinstance(self._user_scope, pr.SubModule):
continue continue
self._user_scope = p.user_scope self._user_scope = p.user_scope
if isinstance(self._user_scope, parsing.SubModule): if isinstance(self._user_scope, pr.SubModule):
self._user_scope = self.module self._user_scope = self.module
return self._user_scope return self._user_scope
@@ -193,10 +194,10 @@ class FastParser(use_metaclass(CachedFastParser)):
def scan_user_scope(self, sub_module): def scan_user_scope(self, sub_module):
""" Scan with self.user_position. """ Scan with self.user_position.
:type sub_module: parsing.SubModule :type sub_module: pr.SubModule
""" """
for scope in sub_module.statements + sub_module.subscopes: for scope in sub_module.statements + sub_module.subscopes:
if isinstance(scope, parsing.Scope): if isinstance(scope, pr.Scope):
if scope.start_pos <= self.user_position <= scope.end_pos: if scope.start_pos <= self.user_position <= scope.end_pos:
return self.scan_user_scope(scope) or scope return self.scan_user_scope(scope) or scope
return None return None

View File

@@ -1,6 +1,6 @@
import copy import copy
import parsing import parsing_representation as pr
import evaluate import evaluate
import debug import debug
import builtin import builtin
@@ -72,7 +72,7 @@ class RecursionNode(object):
# Don't check param instances, they are not causing recursions # Don't check param instances, they are not causing recursions
# The same's true for the builtins, because the builtins are really # The same's true for the builtins, because the builtins are really
# simple. # simple.
self.is_ignored = isinstance(stmt, parsing.Param) \ self.is_ignored = isinstance(stmt, pr.Param) \
or (self.script == builtin.Builtin.scope) or (self.script == builtin.Builtin.scope)
def __eq__(self, other): def __eq__(self, other):
@@ -185,14 +185,14 @@ def fast_parent_copy(obj):
continue continue
elif isinstance(value, list): elif isinstance(value, list):
setattr(new_obj, key, list_rec(value)) setattr(new_obj, key, list_rec(value))
elif isinstance(value, (parsing.Simple, parsing.Call)): elif isinstance(value, (pr.Simple, pr.Call)):
setattr(new_obj, key, recursion(value)) setattr(new_obj, key, recursion(value))
return new_obj return new_obj
def list_rec(list_obj): def list_rec(list_obj):
copied_list = list_obj[:] # lists, tuples, strings, unicode copied_list = list_obj[:] # lists, tuples, strings, unicode
for i, el in enumerate(copied_list): for i, el in enumerate(copied_list):
if isinstance(el, (parsing.Simple, parsing.Call)): if isinstance(el, (pr.Simple, pr.Call)):
copied_list[i] = recursion(el) copied_list[i] = recursion(el)
elif isinstance(el, list): elif isinstance(el, list):
copied_list[i] = list_rec(el) copied_list[i] = list_rec(el)
@@ -209,7 +209,7 @@ def generate_param_array(args_tuple, parent_stmt=None):
else: else:
values.append([arg]) values.append([arg])
pos = None pos = None
arr = parsing.Array(pos, parsing.Array.TUPLE, parent_stmt, values=values) arr = pr.Array(pos, pr.Array.TUPLE, parent_stmt, values=values)
return arr return arr
@@ -229,9 +229,9 @@ def array_for_pos(arr, pos):
result = arr result = arr
for sub in arr: for sub in arr:
for s in sub: for s in sub:
if isinstance(s, parsing.Array): if isinstance(s, pr.Array):
result = array_for_pos(s, pos)[0] or result result = array_for_pos(s, pos)[0] or result
elif isinstance(s, parsing.Call): elif isinstance(s, pr.Call):
if s.execution: if s.execution:
result = array_for_pos(s.execution, pos)[0] or result result = array_for_pos(s.execution, pos)[0] or result
if s.next: if s.next:
@@ -250,13 +250,13 @@ def search_function_call(arr, pos):
for sub in arr.values: for sub in arr.values:
call = None call = None
for s in sub: for s in sub:
if isinstance(s, parsing.Array): if isinstance(s, pr.Array):
new = search_function_call(s, pos) new = search_function_call(s, pos)
if new[0] is not None: if new[0] is not None:
call, index, stop = new call, index, stop = new
if stop: if stop:
return call, index, stop return call, index, stop
elif isinstance(s, parsing.Call): elif isinstance(s, pr.Call):
start_s = s start_s = s
# check parts of calls # check parts of calls
while s is not None: while s is not None:
@@ -275,8 +275,7 @@ def search_function_call(arr, pos):
# next # next
reset = c or s reset = c or s
if reset.execution.type not in \ if reset.execution.type not in \
[parsing.Array.TUPLE, [pr.Array.TUPLE, pr.Array.NOARRAY]:
parsing.Array.NOARRAY]:
return start_s, index, False return start_s, index, False
reset.execution = None reset.execution = None

View File

@@ -8,7 +8,7 @@ import sys
import builtin import builtin
import modules import modules
import debug import debug
import parsing import parsing_representation as pr
import evaluate import evaluate
import itertools import itertools
import cache import cache
@@ -21,9 +21,9 @@ class ModuleNotFound(Exception):
pass pass
class ImportPath(parsing.Base): class ImportPath(pr.Base):
""" """
An ImportPath is the path of a `parsing.Import` object. An ImportPath is the path of a `pr.Import` object.
""" """
class _GlobalNamespace(object): class _GlobalNamespace(object):
def __init__(self): def __init__(self):
@@ -86,8 +86,8 @@ class ImportPath(parsing.Base):
# 0 (0 is not a valid line number). # 0 (0 is not a valid line number).
zero = (0, 0) zero = (0, 0)
names = i.namespace.names[1:] names = i.namespace.names[1:]
n = parsing.Name(i.module, names, zero, zero, self.import_stmt) n = pr.Name(i.module, names, zero, zero, self.import_stmt)
new = parsing.Import(i.module, zero, zero, n) new = pr.Import(i.module, zero, zero, n)
new.parent = parent new.parent = parent
debug.dbg('Generated a nested import: %s' % new) debug.dbg('Generated a nested import: %s' % new)
return new return new
@@ -113,7 +113,7 @@ class ImportPath(parsing.Base):
except IOError: except IOError:
pass pass
else: else:
if on_import_stmt and isinstance(scope, parsing.Module) \ if on_import_stmt and isinstance(scope, pr.Module) \
and scope.path.endswith('__init__.py'): and scope.path.endswith('__init__.py'):
pkg_path = os.path.dirname(scope.path) pkg_path = os.path.dirname(scope.path)
names += self.get_module_names([pkg_path]) names += self.get_module_names([pkg_path])
@@ -141,7 +141,7 @@ class ImportPath(parsing.Base):
names = [] names = []
for module_loader, name, is_pkg in pkgutil.iter_modules(search_path): for module_loader, name, is_pkg in pkgutil.iter_modules(search_path):
inf_pos = (float('inf'), float('inf')) inf_pos = (float('inf'), float('inf'))
names.append(parsing.Name(self.GlobalNamespace, [(name, inf_pos)], names.append(pr.Name(self.GlobalNamespace, [(name, inf_pos)],
inf_pos, inf_pos, self.import_stmt)) inf_pos, inf_pos, self.import_stmt))
return names return names
@@ -295,7 +295,7 @@ def strip_imports(scopes):
""" """
result = [] result = []
for s in scopes: for s in scopes:
if isinstance(s, parsing.Import): if isinstance(s, pr.Import):
result += ImportPath(s).follow() result += ImportPath(s).follow()
else: else:
result.append(s) result.append(s)

View File

@@ -9,6 +9,7 @@ import os
import cache import cache
import parsing import parsing
import parsing_representation as pr
import fast_parser import fast_parser
import builtin import builtin
import debug import debug
@@ -255,7 +256,7 @@ def sys_path_with_modifications(module):
except AttributeError: except AttributeError:
continue continue
n = call.name n = call.name
if not isinstance(n, parsing.Name) or len(n.names) != 3: if not isinstance(n, pr.Name) or len(n.names) != 3:
continue continue
if n.names[:2] != ('sys', 'path'): if n.names[:2] != ('sys', 'path'):
continue continue
@@ -268,7 +269,7 @@ def sys_path_with_modifications(module):
continue continue
if array_cmd == 'insert': if array_cmd == 'insert':
exe_type, exe.type = exe.type, parsing.Array.NOARRAY exe_type, exe.type = exe.type, pr.Array.NOARRAY
exe_pop = exe.values.pop(0) exe_pop = exe.values.pop(0)
res = execute_code(exe.get_code()) res = execute_code(exe.get_code())
if res is not None: if res is not None: