BraceConverter

BraceConverter.py

Contributed 2000-09-04 by Dave Wallace (dwallace@delanet.com)

Converts Brace-blocked Python into normal indented Python. Brace-blocked Python is non-indentation aware and blocks are delimited by ‘:{’ and ‘}’ pairs.

Thus:

for x in range(10) :{
    if x % 2 :{ print(x) } else :{ print(z) }
}

Becomes (roughly, barring some spurious whitespace):

for x in range(10):
    if x % 2:
        print(x)
    else:
        print(z)

This implementation is fed a line at a time via parseLine(), outputs to a PSPServletWriter, and tracks the current quotation and block levels internally.

class PSP.BraceConverter.BraceConverter

Bases: object

__init__()
closeBrace(writer)

Close brace encountered.

handleQuote(quote, writer)

Check and handle if current pos is a single or triple quote.

openBlock(writer)

Open a new block.

openBrace(writer)

Open brace encountered.

parseLine(line, writer)

Parse a line.

The only public method of this class, call with subsequent lines and an instance of PSPServletWriter.

skipQuote(writer)

Skip to end of quote.

Skip over all chars until the line is exhausted or the current non-escaped quote sequence is encountered.