pybraces
I work with a guy who hates Python's significant whitespace and wishes that he could just use curly braces. This little script was made as an encoding filter that can rewrite Python source files before they get to the interpreter, and will even allow you to transform docstrings written with c-like bits into more Python-like bits in case they are being automatically extracted for sane people to read.
Seriously, it's a joke. Making your own encodings is also a good way to go insane (or spend an evening when you're +8 hours away from home).
Downloads
There is no stable version, this is a joke. You can try it out anyway,
download braces.py and put it in your Python
encodings directory (making sure that you python -O braces.py
to create the pyc), then set the encoding of a source file
to braces.
I got the idea after pondering whether the rot13 encoding could be used on source files... one thing led to another at PyCon and a number of us played with encodings but didn't get anything finished. Rumor has it that coderanger has gotten gzip to work.
The examples from Europython and associated bits are up a bzr branch if you want to play with them.
Simple Example
# -*- encoding: braces -*-
if(True) {
print("Hello World");
}
#
Example Usage
# -*- encoding: braces -*-
i = 5;
if(i>4) {
print "Hello World";
}
my_name = "Bob";
print """
digraph G {
a -> b;
c -> c;
}
"""
while(True) {
print "Hi!";
print "This is a test", i;
i++;
if(i>10) {
break;
}
}
Notes
If you attempt to use your own encoding, a BOM error means that your encoding had a parse error itself, not the source file. If you get errors about types, make sure that decode/encode are returning tuples of str/unicode (respectively) and length of characters consumed. If your fake language is line based, you'll need to leave the last piece of a line as unparsed, which caused my "eats the last line" bug.
Contributing
I welcome patches, suggestions, and bugreports. Send me an email to code@timhatch.com