forked from VimPlug/jedi
Change pr.Simple.
This commit is contained in:
@@ -210,8 +210,7 @@ def convert(grammar, raw_node):
|
|||||||
return children[0]
|
return children[0]
|
||||||
print(raw_node, type_repr(type))
|
print(raw_node, type_repr(type))
|
||||||
try:
|
try:
|
||||||
return Node(type, children)
|
return ast_mapping[type](children)
|
||||||
return ast_mapping[children](children)
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return Node(type, children)
|
return Node(type, children)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -173,47 +173,31 @@ class Simple(Base):
|
|||||||
The super class for Scope, Import, Name and Statement. Every object in
|
The super class for Scope, Import, Name and Statement. Every object in
|
||||||
the parser tree inherits from this class.
|
the parser tree inherits from this class.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('parent', '_sub_module', '_start_pos', 'use_as_parent',
|
__slots__ = ('children',)
|
||||||
'_end_pos')
|
|
||||||
|
|
||||||
def __init__(self, module, start_pos, end_pos=(None, None), parent=None):
|
def __init__(self, children):
|
||||||
"""
|
"""
|
||||||
Initialize :class:`Simple`.
|
Initialize :class:`Simple`.
|
||||||
|
|
||||||
:type module: :class:`SubModule`
|
:type children: :class:`SubModule`
|
||||||
:param module: The module in which this Python object locates.
|
:param children: The module in which this Python object locates.
|
||||||
:type start_pos: 2-tuple of int
|
|
||||||
:param start_pos: Position (line, column) of the Statement.
|
|
||||||
:type end_pos: 2-tuple of int
|
|
||||||
:param end_pos: Same as `start_pos`.
|
|
||||||
"""
|
"""
|
||||||
self._sub_module = module
|
self.children = children
|
||||||
self._start_pos = start_pos
|
|
||||||
self._end_pos = end_pos
|
|
||||||
|
|
||||||
self.parent = parent
|
|
||||||
# use this attribute if parent should be something else than self.
|
|
||||||
self.use_as_parent = self
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def start_pos(self):
|
def start_pos(self):
|
||||||
return self._sub_module.line_offset + self._start_pos[0], \
|
return self.children[0].start_pos
|
||||||
self._start_pos[1]
|
|
||||||
|
|
||||||
@start_pos.setter
|
@property
|
||||||
def start_pos(self, value):
|
def _sub_module(self):
|
||||||
self._start_pos = value
|
return self.get_parent_until()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def end_pos(self):
|
def end_pos(self):
|
||||||
if None in self._end_pos:
|
return self.children[-1].end_pos
|
||||||
return self._end_pos
|
|
||||||
return self._sub_module.line_offset + self._end_pos[0], \
|
|
||||||
self._end_pos[1]
|
|
||||||
|
|
||||||
@end_pos.setter
|
def get_code(self):
|
||||||
def end_pos(self, value):
|
return "".join(str(c) for c in self.children)
|
||||||
self._end_pos = value
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
code = self.get_code().replace('\n', ' ')
|
code = self.get_code().replace('\n', ' ')
|
||||||
|
|||||||
Reference in New Issue
Block a user