Skip to content

Commit 5349c9f

Browse files
author
Issac Trotts
committed
Bump version to 0.3.
1 parent 6ae7332 commit 5349c9f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmakelists_parsing/parsing.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def parse(s, path='<string>'):
5555
def strip_blanks(tree):
5656
return File([x for x in tree if not isinstance(x, BlankLine)])
5757

58-
def compose_lines(tree):
58+
def compose_lines(tree, max_width=79):
5959
"""
6060
Yields pretty-printed lines of a CMakeLists file.
6161
"""
@@ -72,14 +72,23 @@ def compose_lines(tree):
7272
level -= 1
7373
for i, line in enumerate(command_to_lines(item)):
7474
offset = 1 if i > 0 else 0
75-
yield (level + offset) * tab + line
75+
line2 = (level + offset) * tab + line
76+
if len(line2) <= max_width:
77+
yield line2
78+
else:
79+
command_to_lines
80+
# Line is too long. Try again.
81+
for _, (ty, contents) in tokenize(line):
82+
yield (level + offset) * tab + contents
83+
7684
if name in ('function', 'macro', 'if', 'else'):
7785
level += 1
7886

79-
def command_to_lines(cmd):
87+
# FIXME: Make this split into more lines if the result would be too wide.
88+
def command_to_lines(cmd, sep):
8089
final_paren = ')' if cmd.body and cmd.body[-1].comments else ')'
8190
comment_part = ' ' + cmd.comment if cmd.comment else ''
82-
result = cmd.name + '(' + ' '.join(map(arg_to_str, cmd.body)) + final_paren + comment_part
91+
result = cmd.name + '(' + sep.join(map(arg_to_str, cmd.body)) + final_paren + comment_part
8392
return [l.strip() for l in result.splitlines()]
8493

8594
def arg_to_str(arg):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='cmakelists_parsing',
13-
version='0.2',
13+
version='0.3',
1414
author='Issac Trotts',
1515
author_email='[email protected]',
1616
url='http://github.com/ijt/cmakelists_parsing',

0 commit comments

Comments
 (0)