forked from VimPlug/jedi
Remove Whitespace class and replace it with Newline and Endmarker.
This commit is contained in:
@@ -53,8 +53,8 @@ def _get_code_for_stack(code_lines, module, position):
|
|||||||
leaf = leaf.get_previous_leaf()
|
leaf = leaf.get_previous_leaf()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return u('') # At the beginning of the file.
|
return u('') # At the beginning of the file.
|
||||||
is_after_newline = leaf.type == 'whitespace'
|
is_after_newline = leaf.type == 'newline'
|
||||||
while leaf.type == 'whitespace':
|
while leaf.type == 'newline':
|
||||||
try:
|
try:
|
||||||
leaf = leaf.get_previous_leaf()
|
leaf = leaf.get_previous_leaf()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ def get_faked(module, obj, name=None):
|
|||||||
doc = '"""%s"""' % obj.__doc__ # TODO need escapes.
|
doc = '"""%s"""' % obj.__doc__ # TODO need escapes.
|
||||||
suite = result.children[-1]
|
suite = result.children[-1]
|
||||||
string = pt.String(pt.zero_position_modifier, doc, (0, 0), '')
|
string = pt.String(pt.zero_position_modifier, doc, (0, 0), '')
|
||||||
new_line = pt.Whitespace('\n', (0, 0), '')
|
new_line = pt.Newline('\n', (0, 0), '')
|
||||||
docstr_node = pt.Node('simple_stmt', [string, new_line])
|
docstr_node = pt.Node('simple_stmt', [string, new_line])
|
||||||
suite.children.insert(2, docstr_node)
|
suite.children.insert(2, docstr_node)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ def deep_ast_copy(obj, parent=None, new_elements=None):
|
|||||||
new_children = []
|
new_children = []
|
||||||
for child in obj.children:
|
for child in obj.children:
|
||||||
typ = child.type
|
typ = child.type
|
||||||
if typ in ('whitespace', 'operator', 'keyword', 'number', 'string',
|
if typ in ('newline', 'operator', 'keyword', 'number', 'string',
|
||||||
'indent', 'dedent', 'error_leaf'):
|
'indent', 'dedent', 'endmarker', 'error_leaf'):
|
||||||
# At the moment we're not actually copying those primitive
|
# At the moment we're not actually copying those primitive
|
||||||
# elements, because there's really no need to. The parents are
|
# elements, because there's really no need to. The parents are
|
||||||
# obviously wrong, but that's not an issue.
|
# obviously wrong, but that's not an issue.
|
||||||
|
|||||||
@@ -214,12 +214,14 @@ class Parser(object):
|
|||||||
return pt.String(self.position_modifier, value, start_pos, prefix)
|
return pt.String(self.position_modifier, value, start_pos, prefix)
|
||||||
elif type == NUMBER:
|
elif type == NUMBER:
|
||||||
return pt.Number(self.position_modifier, value, start_pos, prefix)
|
return pt.Number(self.position_modifier, value, start_pos, prefix)
|
||||||
elif type in (NEWLINE, ENDMARKER):
|
elif type == NEWLINE:
|
||||||
return pt.Whitespace(self.position_modifier, value, start_pos, prefix)
|
return pt.Newline(self.position_modifier, value, start_pos, prefix)
|
||||||
elif type == INDENT:
|
elif type == INDENT:
|
||||||
return pt.Indent(self.position_modifier, value, start_pos, prefix)
|
return pt.Indent(self.position_modifier, value, start_pos, prefix)
|
||||||
elif type == DEDENT:
|
elif type == DEDENT:
|
||||||
return pt.Dedent(self.position_modifier, value, start_pos, prefix)
|
return pt.Dedent(self.position_modifier, value, start_pos, prefix)
|
||||||
|
elif type == ENDMARKER:
|
||||||
|
return pt.EndMarker(self.position_modifier, value, start_pos, prefix)
|
||||||
else:
|
else:
|
||||||
return pt.Operator(self.position_modifier, value, start_pos, prefix)
|
return pt.Operator(self.position_modifier, value, start_pos, prefix)
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class Base(object):
|
|||||||
return scope
|
return scope
|
||||||
|
|
||||||
def get_definition(self):
|
def get_definition(self):
|
||||||
if self.type in ('whitespace', 'dedent', 'indent'):
|
if self.type in ('newline', 'dedent', 'indent', 'endmarker'):
|
||||||
raise ValueError('Cannot get the indentation of whitespace or indentation.')
|
raise ValueError('Cannot get the indentation of whitespace or indentation.')
|
||||||
scope = self
|
scope = self
|
||||||
while scope.parent is not None:
|
while scope.parent is not None:
|
||||||
@@ -354,10 +354,15 @@ class LeafWithNewLines(Leaf):
|
|||||||
return "<%s: %r>" % (type(self).__name__, self.value)
|
return "<%s: %r>" % (type(self).__name__, self.value)
|
||||||
|
|
||||||
|
|
||||||
class Whitespace(LeafWithNewLines):
|
class EndMarker(Leaf):
|
||||||
|
__slots__ = ()
|
||||||
|
type = 'endmarker'
|
||||||
|
|
||||||
|
|
||||||
|
class Newline(LeafWithNewLines):
|
||||||
"""Contains NEWLINE and ENDMARKER tokens."""
|
"""Contains NEWLINE and ENDMARKER tokens."""
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
type = 'whitespace'
|
type = 'newline'
|
||||||
|
|
||||||
@utf8_repr
|
@utf8_repr
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user