mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Make the prefix parsing a bit simpler by combining tabs and spaces.
This commit is contained in:
@@ -41,10 +41,10 @@ class WhitespaceInfo(object):
|
|||||||
if part.type == 'comment':
|
if part.type == 'comment':
|
||||||
self.comments.append(Comment(part, indentation))
|
self.comments.append(Comment(part, indentation))
|
||||||
|
|
||||||
if part.type not in ('tabs', 'spaces'):
|
if part.type == 'indentation':
|
||||||
indentation = ''
|
indentation = part.value
|
||||||
else:
|
else:
|
||||||
indentation += part.value
|
indentation = ''
|
||||||
self.indentation = indentation
|
self.indentation = indentation
|
||||||
|
|
||||||
self.newline_count = 2
|
self.newline_count = 2
|
||||||
|
|||||||
@@ -18,23 +18,22 @@ class PrefixPart(object):
|
|||||||
|
|
||||||
_comment = r'#[^\n\r\f]*'
|
_comment = r'#[^\n\r\f]*'
|
||||||
_backslash = r'\\\r?\n'
|
_backslash = r'\\\r?\n'
|
||||||
_whitespace = r' +'
|
_indentation = r'[ \t]+'
|
||||||
_tabs = r'\t+'
|
|
||||||
_newline = r'\r?\n'
|
_newline = r'\r?\n'
|
||||||
_form_feed = r'\f'
|
_form_feed = r'\f'
|
||||||
|
|
||||||
_regex = group(_comment, _backslash, _whitespace, _newline, _form_feed, _tabs)
|
_regex = group(_comment, _backslash, _indentation, _newline, _form_feed)
|
||||||
_regex = re.compile(_regex)
|
_regex = re.compile(_regex)
|
||||||
|
|
||||||
|
|
||||||
_types = {
|
_types = {
|
||||||
' ': 'spaces',
|
' ': 'indentation',
|
||||||
'#': 'comment',
|
'#': 'comment',
|
||||||
'\\': 'backslash',
|
'\\': 'backslash',
|
||||||
'\f': 'formfeed',
|
'\f': 'formfeed',
|
||||||
'\n': 'newline',
|
'\n': 'newline',
|
||||||
'\r': 'newline',
|
'\r': 'newline',
|
||||||
'\t': 'tabs',
|
'\t': 'indentation',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ def test_simple_prefix_splitting(string, tokens):
|
|||||||
('\r\n', ['newline']),
|
('\r\n', ['newline']),
|
||||||
('\f', ['formfeed']),
|
('\f', ['formfeed']),
|
||||||
('\\\n', ['backslash']),
|
('\\\n', ['backslash']),
|
||||||
|
(' \t', ['indentation']),
|
||||||
|
(' \t ', ['indentation']),
|
||||||
])
|
])
|
||||||
def test_prefix_splitting_types(string, types):
|
def test_prefix_splitting_types(string, types):
|
||||||
tree = parso.parse(string)
|
tree = parso.parse(string)
|
||||||
|
|||||||
Reference in New Issue
Block a user