Skip to content

Commit

Permalink
Fix endl handling inside groupings.
Browse files Browse the repository at this point in the history
Example:
(b
 [0])
  • Loading branch information
kyleatmakrs committed Oct 23, 2017
1 parent e781669 commit 91e839a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions baron/inner_formatting_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def group_generator(sequence):
in_grouping_mode += 1
elif current[0] in QUIT_GROUPING_MODE:
in_grouping_mode -= 1
assert in_grouping_mode >= 0

if in_grouping_mode:
if current[0] in GROUP_THOSE:
Expand All @@ -168,11 +169,15 @@ def group_generator(sequence):
yield next(iterator)

fail_on_bad_token(iterator.show_next(), debug_file_content, in_grouping_mode)

current = append_to_token_before(next(iterator), to_group)

if current[0] in ENTER_GROUPING_MODE:
in_grouping_mode += 1
# TODO test
if current[0] in QUIT_GROUPING_MODE:
in_grouping_mode -= 1
assert in_grouping_mode >= 0
yield current
continue

Expand Down
26 changes: 25 additions & 1 deletion tests/test_inner_formatting_grouper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
# -*- coding:Utf-8 -*-
# -*- coding:utf-8 -*-

from baron.inner_formatting_grouper import group

Expand Down Expand Up @@ -183,3 +183,27 @@ def test_number_backslash_newline():
('INT', '3'),
('SPACE', '\\\n'),
]


def test_nested_grouping_after_endl():
"""
(b
[0])
"""
assert group([
('LEFT_PARENTHESIS', '('),
('NAME', 'b'),
('ENDL', '\n'),
('SPACE', ' '),
('LEFT_SQUARE_BRACKET', '['),
('INT', '0'),
('RIGHT_SQUARE_BRACKET', ']'),
('RIGHT_PARENTHESIS', ')'),
]) == [
('LEFT_PARENTHESIS', '('),
('NAME', 'b'),
('LEFT_SQUARE_BRACKET', '[', [('ENDL', '\n'), ('SPACE', ' ')], []),
('INT', '0'),
('RIGHT_SQUARE_BRACKET', ']'),
('RIGHT_PARENTHESIS', ')'),
]

0 comments on commit 91e839a

Please sign in to comment.