python with braces pre-processor

P

Paul Brauner

Hi, I'm working on a project that outputs several languages including
(hopefully) python. My problem is that the generic backend architecture
has not been designed to output correctly indented code, and that would
be helpful if there were somewhere a python pre-processor that would take
python with braces as an input and output regular python code. I thought
that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'
thing on the subject. I mean that I wonder if there is a special mode of
the offcial parser that does such a thing. If not, do you know the most
reliable project that would do this ?

Thanks a lot.

Paul
 
A

Ant

Hi, I'm working on a project that outputs several languages including
(hopefully) python. My problem is that the generic backend architecture
has not been designed to output correctly indented code, and that would
be helpful if there were somewhere a python pre-processor that would take
python with braces as an input and output regular python code. I thought
that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'

There's a tool in the standard Python distribution that processes code
with commented end statements. eg:

def my_funct():
pass
# end


or similar, and indents it correctly. This may be a possibility for
your purposes.
 
M

Marc 'BlackJack' Rintsch

Hi, I'm working on a project that outputs several languages including
(hopefully) python. My problem is that the generic backend architecture
has not been designed to output correctly indented code, and that would
be helpful if there were somewhere a python pre-processor that would take
python with braces as an input and output regular python code. I thought
that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'
thing on the subject.

Maybe (almost) nobody feels the need to generate Python source code. The
language is so dynamic that there are almost always ways to avoid
source code generation.

Maybe you can generate a token stream and use `tokenize.untokenize()` to
generate the source code!?

Ciao,
Marc 'BlackJack' Rintsch
 
A

Ant

I'll look at that. Thanks a lot !

I've just had a look, it's the pindent.py script in Tools/Scripts (at
least it is on Windows). It takes code of the following form:

def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b > a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar

The help in the script looks pretty good.
 
P

Paul Brauner

Le Mon, 22 Oct 2007 05:00:02 -0700, Ant a écrit :
I've just had a look, it's the pindent.py script in Tools/Scripts (at
least it is on Windows). It takes code of the following form:

def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b > a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar

The help in the script looks pretty good.

Thanks,

actually i'm using it right now as a backend and it's helpful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top