diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 16a9fd7..1df8656 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -41,10 +41,10 @@ class WhitespaceInfo(object): if part.type == 'comment': self.comments.append(Comment(part, indentation)) - if part.type not in ('tabs', 'spaces'): - indentation = '' + if part.type == 'indentation': + indentation = part.value else: - indentation += part.value + indentation = '' self.indentation = indentation self.newline_count = 2 diff --git a/parso/python/prefix.py b/parso/python/prefix.py index ec851b7..9cb4ba3 100644 --- a/parso/python/prefix.py +++ b/parso/python/prefix.py @@ -18,23 +18,22 @@ class PrefixPart(object): _comment = r'#[^\n\r\f]*' _backslash = r'\\\r?\n' -_whitespace = r' +' -_tabs = r'\t+' +_indentation = r'[ \t]+' _newline = r'\r?\n' _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) _types = { - ' ': 'spaces', + ' ': 'indentation', '#': 'comment', '\\': 'backslash', '\f': 'formfeed', '\n': 'newline', '\r': 'newline', - '\t': 'tabs', + '\t': 'indentation', } diff --git a/test/test_prefix.py b/test/test_prefix.py index 2e47ebc..ec9f338 100644 --- a/test/test_prefix.py +++ b/test/test_prefix.py @@ -42,6 +42,8 @@ def test_simple_prefix_splitting(string, tokens): ('\r\n', ['newline']), ('\f', ['formfeed']), ('\\\n', ['backslash']), + (' \t', ['indentation']), + (' \t ', ['indentation']), ]) def test_prefix_splitting_types(string, types): tree = parso.parse(string)