Skip to content
Snippets Groups Projects
Commit fef5bee0 authored by Jorge Canizales's avatar Jorge Canizales
Browse files

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).
parent a6da17ee
No related branches found
No related tags found
No related merge requests found
#!/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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment