1
0
forked from VimPlug/jedi

Actually replace tree with representation (in all the imports).

This commit is contained in:
Dave Halter
2014-11-23 19:46:52 +01:00
parent 1fbc4c9196
commit c152a1c58b
23 changed files with 65 additions and 62 deletions

View File

@@ -17,7 +17,7 @@ from itertools import chain
from jedi._compatibility import next, unicode, builtins
from jedi.parser import Parser
from jedi.parser.tokenize import source_tokens
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.parser.user_context import UserContext, UserContextParser
from jedi import debug
from jedi import settings

View File

@@ -9,7 +9,7 @@ from itertools import chain
from jedi._compatibility import next, unicode, use_metaclass
from jedi import settings
from jedi import common
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.evaluate.helpers import statement_elements_in_statement
from jedi.evaluate.cache import memoize_default, CachedMetaClass
from jedi.evaluate import representation as er

View File

@@ -7,7 +7,7 @@ from jedi.common import source_to_unicode
from jedi.cache import underscore_memoization
from jedi.evaluate import compiled
from jedi.evaluate.compiled.fake import get_module
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.parser.fast import FastParser
from jedi.evaluate import helpers

View File

@@ -1,7 +1,7 @@
from jedi._compatibility import u, unicode
from jedi import common
from jedi.api import classes
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.evaluate import imports
from jedi.evaluate import helpers

View File

@@ -72,7 +72,7 @@ import copy
from itertools import tee, chain
from jedi._compatibility import next, hasattr, unicode
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.parser.pytree import python_symbols
from jedi.parser.tokenize import Token
from jedi.parser import fast

View File

@@ -3,7 +3,7 @@ Module for statical analysis.
"""
from jedi import debug
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.evaluate.compiled import CompiledObject

View File

@@ -11,7 +11,7 @@ from jedi._compatibility import builtins as _builtins, unicode
from jedi import debug
from jedi.cache import underscore_memoization, memoize
from jedi.evaluate.sys_path import get_sys_path
from jedi.parser.representation import Param, SubModule, Base, Operator
from jedi.parser.tree import Param, SubModule, Base, Operator
from jedi.evaluate.helpers import FakeName
from . import fake

View File

@@ -10,7 +10,7 @@ import inspect
from jedi._compatibility import is_py3, builtins, unicode
from jedi.parser import Parser
from jedi.parser import tokenize
from jedi.parser.representation import Class
from jedi.parser.tree import Class
from jedi.evaluate.helpers import FakeName
modules = {}

View File

@@ -18,7 +18,7 @@ It works as follows:
"""
from jedi._compatibility import unicode
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi import settings
from jedi import debug
from jedi.evaluate import helpers

View File

@@ -14,7 +14,7 @@ check for -> a is a string). There's big potential in these checks.
from itertools import chain
from jedi._compatibility import hasattr, unicode, u
from jedi.parser import representation as pr, tokenize
from jedi.parser import tree as pr, tokenize
from jedi.parser import fast
from jedi import debug
from jedi import common

View File

@@ -1,4 +1,4 @@
from jedi.parser import representation as pr
from jedi.parser import tree as pr
class Status(object):

View File

@@ -2,7 +2,7 @@ import copy
from itertools import chain
from jedi._compatibility import unicode
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi import debug

View File

@@ -21,7 +21,7 @@ from jedi import common
from jedi import debug
from jedi import cache
from jedi.parser import fast
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.evaluate.sys_path import get_sys_path, sys_path_with_modifications
from jedi.evaluate import helpers
from jedi import settings

View File

@@ -26,7 +26,7 @@ from jedi import common
from jedi import debug
from jedi import settings
from jedi._compatibility import use_metaclass, is_py3, unicode
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.evaluate import compiled
from jedi.evaluate import helpers
from jedi.evaluate import precedence

View File

@@ -5,7 +5,7 @@ from itertools import chain
from jedi._compatibility import unicode, zip_longest
from jedi import debug
from jedi import common
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.evaluate import iterable
from jedi.evaluate import helpers
from jedi.evaluate import analysis

View File

@@ -4,7 +4,7 @@ Handles operator precedence.
import operator
from jedi._compatibility import unicode
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi import debug
from jedi.common import PushBackIterator
from jedi.evaluate.compiled import (CompiledObject, create, builtin,

View File

@@ -7,7 +7,7 @@ Next to :mod:`jedi.evaluate.cache` this module also makes |jedi| not
thread-safe. Why? ``execution_recursion_decorator`` uses class variables to
count the function calls.
"""
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi import debug
from jedi import settings
from jedi.evaluate import compiled

View File

@@ -1,5 +1,5 @@
"""
Like described in the :mod:`jedi.parser.representation` module,
Like described in the :mod:`jedi.parser.tree` module,
there's a need for an ast like module to represent the states of parsed
modules.
@@ -34,7 +34,7 @@ import pkgutil
from itertools import chain
from jedi._compatibility import use_metaclass, unicode, Python3Method
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.parser.tokenize import Token
from jedi.parser.pytree import python_symbols
from jedi import debug

View File

@@ -13,9 +13,8 @@ from jedi._compatibility import unicode
from jedi.evaluate import compiled
from jedi.evaluate import representation as er
from jedi.evaluate import iterable
from jedi.evaluate.helpers import FakeArray, FakeStatement
from jedi.parser import Parser
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi import debug
from jedi.evaluate import precedence
from jedi.evaluate import param

View File

@@ -2,7 +2,7 @@ import os
import sys
from jedi._compatibility import exec_function, unicode
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.parser import Parser
from jedi.evaluate.cache import memoize_default
from jedi import debug

View File

@@ -1,7 +1,7 @@
"""
The ``Parser`` tries to convert the available Python code in an easy to read
format, something like an abstract syntax tree. The classes who represent this
tree, are sitting in the :mod:`jedi.parser.representation` module.
tree, are sitting in the :mod:`jedi.parser.tree` module.
The Python module ``tokenize`` is a very important part in the ``Parser``,
because it splits the code into different words (tokens). Sometimes it looks a
@@ -21,7 +21,7 @@ import logging
from jedi._compatibility import next, unicode
from jedi import debug
from jedi import common
from jedi.parser import representation as pr
from jedi.parser import tree as pt
from jedi.parser import tokenize
from jedi.parser import pytree
from jedi.parser.pgen2 import Driver
@@ -52,29 +52,29 @@ class Parser(object):
source += '\n'
_ast_mapping = {
'expr_stmt': pr.ExprStmt,
'classdef': pr.Class,
'funcdef': pr.Function,
'file_input': pr.SubModule,
'import_name': pr.ImportName,
'import_from': pr.ImportFrom,
'break_stmt': pr.KeywordStatement,
'continue_stmt': pr.KeywordStatement,
'return_stmt': pr.ReturnStmt,
'raise_stmt': pr.KeywordStatement,
'yield_expr': pr.YieldExpr,
'del_stmt': pr.KeywordStatement,
'pass_stmt': pr.KeywordStatement,
'global_stmt': pr.GlobalStmt,
'nonlocal_stmt': pr.KeywordStatement,
'assert_stmt': pr.KeywordStatement,
'if_stmt': pr.IfStmt,
'with_stmt': pr.WithStmt,
'for_stmt': pr.ForStmt,
'while_stmt': pr.WhileStmt,
'try_stmt': pr.TryStmt,
'comp_for': pr.CompFor,
'decorator': pr.Decorator,
'expr_stmt': pt.ExprStmt,
'classdef': pt.Class,
'funcdef': pt.Function,
'file_input': pt.SubModule,
'import_name': pt.ImportName,
'import_from': pt.ImportFrom,
'break_stmt': pt.KeywordStatement,
'continue_stmt': pt.KeywordStatement,
'return_stmt': pt.ReturnStmt,
'raise_stmt': pt.KeywordStatement,
'yield_expr': pt.YieldExpr,
'del_stmt': pt.KeywordStatement,
'pass_stmt': pt.KeywordStatement,
'global_stmt': pt.GlobalStmt,
'nonlocal_stmt': pt.KeywordStatement,
'assert_stmt': pt.KeywordStatement,
'if_stmt': pt.IfStmt,
'with_stmt': pt.WithStmt,
'for_stmt': pt.ForStmt,
'while_stmt': pt.WhileStmt,
'try_stmt': pt.TryStmt,
'comp_for': pt.CompFor,
'decorator': pt.Decorator,
}
self._ast_mapping = dict((getattr(pytree.python_symbols, k), v)
@@ -110,26 +110,26 @@ class Parser(object):
try:
new_node = self._ast_mapping[type](children)
except KeyError:
new_node = pr.Node(type, children)
new_node = pt.Node(type, children)
# We need to check raw_node always, because the same node can be
# returned by convert multiple times.
if type == pytree.python_symbols.global_stmt:
self.global_names += new_node.get_defined_names()
elif isinstance(new_node, (pr.ClassOrFunc, pr.Module)) \
elif isinstance(new_node, (pt.ClassOrFunc, pt.Module)) \
and type in (pytree.python_symbols.funcdef,
pytree.python_symbols.classdef,
pytree.python_symbols.file_input):
# scope_name_stack handling
scope_names = self.scope_names_stack.pop()
if isinstance(new_node, pr.ClassOrFunc):
if isinstance(new_node, pt.ClassOrFunc):
n = new_node.name
scope_names[n.value].remove(n)
# Set the func name of the current node
arr = self.scope_names_stack[-1].setdefault(n.value, [])
arr.append(n)
new_node.names_dict = scope_names
elif isinstance(new_node, pr.CompFor):
elif isinstance(new_node, pt.CompFor):
# The name definitions of comprehenions shouldn't be part of the
# current scope. They are part of the comprehension scope.
for n in new_node.get_defined_names():
@@ -143,9 +143,9 @@ class Parser(object):
if value in ('def', 'class'):
self.scope_names_stack.append({})
return pr.Keyword(value, start_pos, prefix)
return pt.Keyword(value, start_pos, prefix)
else:
name = pr.Name(value, start_pos, prefix)
name = pt.Name(value, start_pos, prefix)
# Keep a listing of all used names
arr = self.used_names.setdefault(name.value, [])
arr.append(name)
@@ -153,13 +153,13 @@ class Parser(object):
arr.append(name)
return name
elif type == tokenize.STRING:
return pr.String(value, start_pos, prefix)
return pt.String(value, start_pos, prefix)
elif type == tokenize.NUMBER:
return pr.Number(value, start_pos, prefix)
return pt.Number(value, start_pos, prefix)
elif type in (tokenize.NEWLINE, tokenize.ENDMARKER):
return pr.Whitespace(value, start_pos, prefix)
return pt.Whitespace(value, start_pos, prefix)
else:
return pr.Operator(value, start_pos, prefix)
return pt.Operator(value, start_pos, prefix)
def error_recovery(self, grammar, stack, type, value):
"""
@@ -185,7 +185,7 @@ class Parser(object):
try:
clear_names(c.children)
except AttributeError:
if isinstance(c, pr.Name):
if isinstance(c, pt.Name):
try:
self.scope_names_stack[-1][c.value].remove(c)
self.used_names[c.value].remove(c)
@@ -200,6 +200,10 @@ class Parser(object):
def __init__old__(self, source, module_path=None, no_docstr=False,
tokenizer=None, top_module=None):
"""
TODO REMOVE THIS
"""
self.no_docstr = no_docstr
tokenizer = tokenizer or tokenize.source_tokens(source)
@@ -208,7 +212,7 @@ class Parser(object):
# initialize global Scope
start_pos = next(self._gen).start_pos
self._gen.push_last_back()
self.module = pr.SubModule(module_path, start_pos, top_module)
self.module = pt.SubModule(module_path, start_pos, top_module)
self._scope = self.module
self._top_module = top_module or self.module
@@ -257,7 +261,7 @@ class Parser(object):
except KeyError:
self.module.used_names[tok_name] = set([simple])
self.module.temp_used_names = []
if isinstance(simple, pr.Statement):
if isinstance(simple, pt.Statement):
for name, calls in simple.get_names_dict().items():
self._scope.add_name_calls(name, calls)

View File

@@ -9,7 +9,7 @@ from jedi._compatibility import use_metaclass, unicode
from jedi import settings
from jedi import common
from jedi.parser import Parser
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi.parser import tokenize
from jedi import cache
from jedi.parser.tokenize import (source_tokens, Token, FLOWS, NEWLINE,

View File

@@ -7,7 +7,7 @@ from jedi import common
from jedi.parser import tokenize
from jedi._compatibility import u
from jedi.parser.fast import FastParser
from jedi.parser import representation as pr
from jedi.parser import tree as pr
from jedi import debug
from jedi.common import PushBackIterator