aa_macro syntax 
 aa_macro source 
 HTML source 
 HTML render 
Key

4.64 - [postparse] Built-In

Mnemonic aid: postparse for POST (after) PARSE pretty-print Python source

See also:  [pythparse] 

This built-in allows you to generate a pretty-printed representation of Python source code. In the example, you'll see I wrapped a  <div>  with a black background around the  [postparse] , as the default pretty-printing colors were selected with a black background in mind:


[postparse content]

<div style="background: #000000; padding: 1em;">
[postparse
def mygen(n):
for i in range(0,n):
print "hello!"
]
</div>

<div style="background: #000000; padding: 1em;"><span style="color: #00ff00"><span style="color: #ff00ff">def</span> mygen<span style="color:#ff8844;">(</span>n<span style="color:#ff8844;">)</span><span style="color:#00ffff;">:</span></span>
<span style="color: #00ff00"> <span style="color: #ff00ff">for</span> i <span style="color: #ff00ff">in</span> range<span style="color:#ff8844;">(</span>0<span style="color:#00ffff;">,</span>n<span style="color:#ff8844;">)</span><span style="color:#00ffff;">:</span></span>
<span style="color: #00ff00"> <span style="color: #ff00ff">print</span> </span><span style="color: #ffffff">"</span><span style="color: #ff0000">hello!</span><span style="color: #ffffff">"</span><span style="color: #00ff00"></span></div>
def mygen(n): for i in range(0,n): print "hello!"

You can use aa_macro code within the scope of Python source code fed to  [postparse]  at any parsing level, not just the top context; this can be very handy, but it comes with a bit of work, too: You have to change all the Python source occurances of [ and ] to  [lb]  and  [rb] , and all of the occurances of { and } to  [ls]  and  [rs] , or aa_macro will try to parse the Python as aa_macro, and the result of that won't be pretty. With that in mind, it is sometimes more practical to use  [pythparse] , store the result in a variable, and then use the variable in deeper aa_macro contexts.

You can control what the pretty printing does in terms of styling by setting the following variables (default values are shown):

CSS style wrap for Python keywords: import, while, etc.
tx_prekey
'<span style="color: #ff00ff">'
tx_poskey
'</span>'

CSS style wrap for single and double quotes
tx_prequo
'<span style="color: #ffffff">'
tx_posquo
'</span>'

CSS style wrap for Python code
tx_precod
'<span style="color: #00FF00">'
tx_poscod
'</span>'

CSS style wrap for text inside quotes
tx_pretxt
'<span style="color: #ff0000">'
tx_postxt
'</span>'

CSS style wrap for comment content
tx_precom
'<span style="color: #ffff00">'
tx_poscom
'</span>'

CSS style wrap for {}, [], and ()
tx_pybrace
'<span style="color: #ff8844">'
tx_epybrace
'</span>'

CSS style wrap for symbols such as ==, +, < and so on
tx_pysym
'<span style="color: #00ffff">'
tx_epysym
'</span>'
Keyboard Navigation
, Previous Page . Next Page t TOC i Index

Valid HTML 4.01 Loose
 

This manual was generated with wtfm
wtfm uses aa_macro and SqLite
aa_macro uses python 2.7