diff options
author | Jorge Canizales <jcanizales@google.com> | 2015-10-19 12:24:28 -0700 |
---|---|---|
committer | Jorge Canizales <jcanizales@google.com> | 2015-10-25 21:48:12 -0700 |
commit | fef5bee020bac0522af2a1ceec20b78098efac7c (patch) | |
tree | 1430399efa1e697e318baf7598cab766f41afe37 /src | |
parent | a6da17eeebcfa7960d322f7ab58be251204089e1 (diff) |
Prototype script to change comment format.
Still needs implementing format_as_block, and switching input and output
to use sys.stdin.readline() and sys.stdout.write(line).
Diffstat (limited to 'src')
-rw-r--r-- | src/objective-c/change-comments.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/objective-c/change-comments.py b/src/objective-c/change-comments.py new file mode 100644 index 0000000000..20351d5bf8 --- /dev/null +++ b/src/objective-c/change-comments.py @@ -0,0 +1,53 @@ +#!/usr/bin/python + +import re +import sys + +print 'Number of arguments:', len(sys.argv), 'arguments.' +print 'Argument List:', str(sys.argv) + +with open(sys.argv[0], "r") as input_file: + lines = input_file.readlines() + +def peek(): + return lines[0] + +def read_line(): + return lines.pop(0) + +def more_input(): + return lines + + +comment_regex = r'^(\s*)//\s(.*)$' + +def is_comment(line): + return re.search(comment_regex, line) + +def isnt_comment(line): + return not is_comment(line) + +def next_line(predicate): + if not more_input(): + return False + return predicate(peek()) + + +output_lines = [] + +def output(line): + output_lines.append(line) + + +while more_input(): + while next_line(isnt_comment): + output(read_line()) + + comment_block = [] + # Get all lines in the same comment block. We could restrict the indentation + # to be the same as the first line of the block, but it's probably ok. + while (next_line(is_comment)): + comment_block.append(read_line()) + + for line in format_as_block(comment_block): + output(line) |