Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 28 lines (27 sloc) 0.889 kb
#!/usr/bin/python
"Remove comments and most extra whitespace from a tbf1 program."
# Wow this program has gotten ugly.
import sys
deindent = ('-i' in sys.argv)
wsp = comment = newline = False
firstline = startline = True
while True:
byte = sys.stdin.read(1)
if not byte: break
elif byte == '(': comment = True
elif byte == ')': comment = False
elif not comment:
if byte == '\n':
startline = True
newline = True
elif (deindent or not startline) and byte == ' ':
wsp = True
else:
startline = (byte == ' ')
if newline:
if not firstline: sys.stdout.write('\n')
elif wsp: sys.stdout.write(' ')
sys.stdout.write(byte)
if byte == "'": sys.stdout.write(sys.stdin.read(1))
wsp = newline = firstline = False
sys.stdout.write('\n')
Jump to Line
Something went wrong with that request. Please try again.