1
0
forked from VimPlug/jedi

Implement the new parser in jedi.parser.Parser

This commit is contained in:
Dave Halter
2014-10-10 00:06:28 +02:00
parent 05fd7f992e
commit 66840a742c
3 changed files with 31 additions and 9 deletions

View File

@@ -231,7 +231,7 @@ def save_parser(path, name, parser, pickling=True):
class ParserPickling(object):
version = 18
version = 19
"""
Version number (integer) for file system cache.

View File

@@ -16,12 +16,15 @@ complexity of the ``Parser`` (there's another parser sitting inside
``Statement``, which produces ``Array`` and ``Call``).
"""
import keyword
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 tokenize
from jedi.parser import pytree
from jedi.parser.pgen2 import Driver
OPERATOR_KEYWORDS = 'and', 'for', 'if', 'else', 'in', 'is', 'lambda', 'not', 'or'
# Not used yet. In the future I intend to add something like KeywordStatement
@@ -43,6 +46,21 @@ class Parser(object):
"""
def __init__(self, source, module_path=None, no_docstr=False,
tokenizer=None, top_module=None):
if not source.endswith('\n'):
source += '\n'
#if self.options["print_function"]:
# python_grammar = pygram.python_grammar_no_print_statement
#else:
# When this is True, the refactor*() methods will call write_file() for
# files processed even if they were not changed during refactoring. If
# and only if the refactor method's write parameter was True.
logger = logging.getLogger("RefactoringTool")
d = Driver(pytree.python_grammar, convert=pytree.convert, logger=logger)
self.module = d.parse_string(source)
def __init__old__(self, source, module_path=None, no_docstr=False,
tokenizer=None, top_module=None):
self.no_docstr = no_docstr
tokenizer = tokenizer or tokenize.source_tokens(source)

View File

@@ -558,17 +558,21 @@ class Class(Scope):
:param start_pos: The start position (line, column) of the class.
:type start_pos: tuple(int, int)
"""
__slots__ = ('name', 'supers', 'decorators')
__slots__ = ('decorators')
def __init__(self, module, name, supers, start_pos):
super(Class, self).__init__(module, start_pos)
self.name = name
name.parent = self.use_as_parent
self.supers = supers
for s in self.supers:
s.parent = self.use_as_parent
def __init__(self, children):
super(Class, self).__init__(children)
self.decorators = []
@property
def supers(self):
raise NotImplementedError
@property
def name(self):
return self.children[1] # First token after `def`
@property
def doc(self):
"""