> Give me a more politically correct term then. I just chose 'fringe' for
> lack of more descriptive terms.
I like using the term "Python" for describing Python. ;)
So here's what I'm proposing. Since you dislike python's use of
whitespace, I will write a python braceificator and we can compare and
contrast.
And here it is. I wouldn't use the term "Beautiful" to describe this
piece of code. I prefer "Pragmatic". If it happens to look beautiful,
that's merely a side effect.
def indentlevel(line):
count = 0
while len(line) and line[0] == " ":
line=line[1:]
count +=1
return count
def bracify(file):
infd = open(file,"r")
outfd = open(file+".by","w")
bracelevel = [0]
originalline = " "
while originalline != '':
originalline=infd.readline()
line = originalline.rstrip()
level = indentlevel(line)
if line.lstrip() == "":
outfd.write(line + "\n")
continue
if level > bracelevel[-1]:
outfd.write(level * " " + "{\n")
bracelevel.append(level)
while bracelevel[-1] > level:
outfd.write(bracelevel.pop() * " " + "}\n")
if line[-1] == ":":
outfd.write(line + "\n")
continue
while line[-1] == '\\':
outfd.write(line)
line = infd.readline().rstrip()
outfd.write(line + ';\n')
while len(bracelevel):
outfd.write(bracelevel.pop() * " " + "}\n")
And here is what the braceified version of the same code looks like:
def indentlevel(line):
{
count = 0;
while len(line) and line[0] == " ":
{
line=line[1:];
count +=1;
}
return count;
}
def bracified(file):
{
infd = open(file,"r");
outfd = open(file+".by","w");
bracelevel = [0];
originalline = " ";
while originalline != '':
{
....
Anyway you get the point.
At this point it seems pretty trivial to write a debraceificator to
convert it back to normal python syntax. Replace the semicolons with
linefeeds and count braces for indentation. And then you would have
something that with a little polish would replace whitespace with
braces.
Oh and the code ports easily to jave:
$jythonc -j braceificator.jar braceificator.py
--R
_______________________________________________
Fwlug mailing list
[email protected]
http://fortwaynelug.org/mailman/listinfo/fwlug_fortwaynelug.org