Module Expr Str Import alias Import alias Import alias ImportFrom alias Assign NameStore Str Assign NameStore Str FunctionDef arguments args NameParam defaults body Assign NameStore Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad SubscriptLoad NameLoad Slice BinOpAdd NameLoad Num attr Return TupleLoad NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Str If CompareEq NameLoad Num body Return NameLoad Assign NameStore Call AttributeLoad SubscriptLoad NameLoad Slice NameLoad attr Return NameLoad decorator_list Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Num ClassDef bases body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr ListLoad decorator_list FunctionDef arguments args NameParam defaults body If CompareIn Str AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Slice BinOpAdd NameLoad Num NameLoad orelse Assign NameStore AttributeLoad NameLoad attr Return ListComp Call NameLoad Call AttributeLoad NameLoad attr comprehension NameStore Call AttributeLoad NameLoad attr Str NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Dict Assign NameStore NameLoad For NameStore Call NameLoad Call NameLoad AttributeLoad NameLoad attr body Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad If Call AttributeLoad NameLoad attr Str body Assign NameStore SubscriptStore AttributeLoad NameLoad attr Index NameLoad SubscriptLoad NameLoad Slice Num Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad orelse If Call AttributeLoad NameLoad attr Str body Assign NameStore SubscriptStore AttributeLoad NameLoad attr Index NameLoad SubscriptLoad NameLoad Slice Num Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad orelse If Call AttributeLoad NameLoad attr Str body Assign NameStore SubscriptStore AttributeLoad NameLoad attr Index NameLoad SubscriptLoad NameLoad Slice Num Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad orelse Assign SubscriptStore NameLoad Index NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad If CompareGt NameLoad NameLoad body Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Str Str Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Str Str Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Str Str Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Assign NameStore Call NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Print NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Print NameLoad Assign NameStore Call NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Num Num Expr Call AttributeLoad NameLoad attr Num Num Return TupleLoad Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Print NameLoad Str Print NameLoad BinOpMod Str AttributeLoad NameLoad attr If AttributeLoad NameLoad attr body Print NameLoad BinOpMod Str AttributeLoad NameLoad attr orelse Print NameLoad Str Print NameLoad BinOpMod Str AttributeLoad NameLoad attr If AttributeLoad NameLoad attr body For NameStore AttributeLoad NameLoad attr body Print NameLoad BinOpMod Str TupleLoad NameLoad NameLoad Print NameLoad Str For NameStore AttributeLoad NameLoad attr body Print NameLoad Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Print NameLoad Str If CompareEq Call NameLoad AttributeLoad NameLoad attr Num body Print NameLoad Str orelse If CompareLt AttributeLoad NameLoad attr NameLoad body For NameStore AttributeLoad NameLoad attr body Print NameLoad BinOpMod Str NameLoad Print NameLoad BinOpMod Str NameLoad orelse For NameStore AttributeLoad NameLoad attr body If CompareEq SubscriptLoad AttributeLoad NameLoad attr Index NameLoad NameLoad body Print NameLoad BinOpMod Str Dict Str NameLoad Print NameLoad BinOpMod Str Dict Str NameLoad Print NameLoad BinOpMod Str Dict Str NameLoad orelse Print NameLoad BinOpMod Str NameLoad Print NameLoad BinOpMod Str NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Print NameLoad BinOpMod Str AttributeLoad NameLoad attr If AttributeLoad NameLoad attr body Assign NameStore ListLoad For NameStore AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore ListComp BinOpMod Str NameLoad comprehension NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad Print NameLoad BinOpMod Str TupleLoad AttributeLoad NameLoad attr NameLoad NameLoad orelse Print NameLoad BinOpMod Str AttributeLoad NameLoad attr Print NameLoad Str decorator_list decorator_list Assign NameStore Call AttributeLoad NameLoad attr Str FunctionDef arguments args NameParam defaults body Assign NameStore Dict Assign NameStore NameLoad For NameStore Call AttributeLoad NameLoad attr NameLoad body If Call AttributeLoad Call AttributeLoad NameLoad attr attr Str body Continue Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareIs NameLoad NameLoad body If CompareIs NameLoad NameLoad body TryExcept body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Str handlers ExceptHandler type NameLoad body Continue Assign SubscriptStore NameLoad Index NameLoad Call NameLoad NameLoad NameLoad Assign NameStore NameLoad orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad orelse Assign NameStore Call AttributeLoad NameLoad attr Num Assign NameStore SubscriptLoad NameLoad Index NameLoad Return Call NameLoad Call AttributeLoad NameLoad attr keyword Lambda arguments args NameParam defaults AttributeLoad NameLoad attr decorator_list FunctionDef arguments args defaults body Assign TupleStore NameStore NameStore Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Str Assign NameStore Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Num Str Print NameLoad NameLoad Print NameLoad Print NameLoad Str Assign NameStore Call NameLoad NameLoad For NameStore NameLoad body Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Print NameLoad NameLoad Print NameLoad NameLoad Print NameLoad NameLoad Print NameLoad Str Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr decorator_list If CompareEq NameLoad Str body Expr Call NameLoad Expr Call AttributeLoad NameLoad attr Num Expr Str
N/A N/A Generate ast module from specification

This script generates the ast module from a simple specification,
which makes it easy to accomodate changes in the grammar.  This
approach would be quite reasonable if the grammar changed often.
Instead, it is rather complex to generate the appropriate code.  And
the Node interface has changed more often than the grammar.
 N/A fileinput N/A re N/A sys StringIO StringIO N/A SPEC ast.txt N/A COMMA ,  load_boilerplate N/A N/A file N/A N/A N/A f N/A open file N/A buf N/A N/A f read N/A N/A N/A f close N/A i N/A N/A buf find ### PROLOGUE N/A pro N/A N/A N/A buf N/A N/A i 12 strip N/A N/A pro N/A strip_default N/A N/A arg N/A N/A N/A Return the argname from an 'arg = default' string N/A i N/A N/A arg find = N/A N/A i -1 N/A N/A arg N/A t N/A N/A N/A arg N/A i strip N/A t N/A N/A P_NODE 1 N/A P_OTHER 2 N/A P_NESTED 3 N/A P_NONE 4 NodeInfo N/A N/A N/A Each instance describes a specific AST node __init__ N/A N/A self name args N/A N/A N/A N/A self name name N/A N/A self args N/A N/A args strip N/A N/A self argnames N/A N/A self get_argnames N/A N/A self argprops N/A N/A self get_argprops N/A N/A self nargs N/A len N/A self argnames N/A N/A self init N/A N/A get_argnames N/A N/A self N/A N/A N/A N/A ( N/A self args N/A N/A i N/A N/A N/A self args find ( N/A j N/A N/A N/A self args rfind ) N/A args N/A N/A self args N/A N/A i 1 j N/A N/A args N/A self args N/A N/A N/A strip_default N/A N/A arg strip N/A arg N/A N/A args split , arg N/A get_argprops N/A N/A self N/A N/A N/A Each argument can have a property like '*' or '!'

        XXX This method modifies the argnames in place!
         N/A d N/A N/A hardest_arg P_NODE N/A i N/A range N/A len N/A self argnames N/A N/A arg N/A N/A self argnames N/A i N/A N/A N/A arg endswith * N/A N/A arg N/A N/A self argnames N/A i N/A arg N/A -1 N/A N/A d N/A arg P_OTHER N/A hardest_arg N/A max hardest_arg P_OTHER N/A N/A N/A N/A arg endswith ! N/A N/A arg N/A N/A self argnames N/A i N/A arg N/A -1 N/A N/A d N/A arg P_NESTED N/A hardest_arg N/A max hardest_arg P_NESTED N/A N/A N/A N/A arg endswith & N/A N/A arg N/A N/A self argnames N/A i N/A arg N/A -1 N/A N/A d N/A arg P_NONE N/A hardest_arg N/A max hardest_arg P_NONE N/A N/A N/A d N/A arg P_NODE N/A N/A self hardest_arg hardest_arg N/A N/A hardest_arg P_NODE N/A N/A N/A self args N/A N/A N/A self args replace * N/A N/A self args N/A N/A N/A self args replace ! N/A N/A self args N/A N/A N/A self args replace & N/A d N/A gen_source N/A N/A self N/A N/A N/A buf N/A StringIO N/A N/A N/A self _gen_init buf N/A buf N/A N/A N/A self _gen_walkChildren buf N/A buf N/A bufAux N/A StringIO N/A N/A N/A self _gen_repr bufAux N/A N/A N/A buf seek 0 0 N/A N/A N/A bufAux seek 0 0 N/A N/A N/A N/A buf read N/A N/A bufAux read N/A _gen_init N/A N/A self buf N/A N/A N/A buf # -------------------------------------------------------- N/A buf N/A class %s:
 N/A self name N/A N/A self args N/A N/A buf N/A     def __init__ (self, %s, lineno):
 N/A self args N/A N/A buf     def __init__(self, lineno):
 N/A buf N/A         self.nodeName = "%s"; N/A self name N/A N/A self argnames N/A N/A name N/A self argnames N/A N/A buf N/A         self.%s = %s; N/A name name N/A buf         self.lineno = lineno; N/A line N/A self init N/A N/A buf N/A N/A line rstrip N/A _gen_walkChildren N/A N/A self buf N/A N/A N/A buf     def walkChildren(self, handler, args): N/A N/A N/A len N/A self argnames 0 N/A N/A buf         return; N/A N/A N/A N/A self hardest_arg P_NESTED N/A N/A c N/A self argnames N/A N/A buf N/A         ret = handler.visit(self.%s, args); c N/A buf N/A         if ret: self.%s = ret c N/A N/A name N/A self argnames N/A N/A N/A N/A N/A self argprops N/A name P_NESTED N/A N/A buf N/A         for i_%(name)s in range(len(self.%(name)s)):
 N/A name name N/A buf N/A             ret = handler.visit(self.%(name)s[i_%(name)s], args); N/A name name N/A buf N/A             if ret: self.%(name)s[i_%(name)s] = ret
 N/A name name N/A N/A buf N/A         ret = handler.visit(self.%s, args); name N/A buf N/A         if ret: self.%s = ret name N/A _gen_repr N/A N/A self buf N/A N/A N/A buf N/A if (node.nodeName=== '%s'): N/A self name N/A N/A self argnames N/A N/A fmts N/A N/A name N/A self argnames N/A N/A N/A N/A fmts append N/A name =%s N/A fmt N/A N/A COMMA join fmts N/A vals N/A N/A astDump(node.%s) name N/A name N/A self argnames N/A vals N/A N/A COMMA join vals N/A buf N/A     return sprintf("%s(%s)", %s) N/A N/A self name fmt vals N/A N/A buf N/A     return "%s()" N/A self name N/A buf } N/A N/A N/A rx_init N/A N/A re compile init\((.*)\): parse_spec N/A N/A file N/A N/A N/A classes N/A N/A cur None N/A line N/A N/A fileinput input file N/A N/A N/A N/A N/A N/A line strip startswith # N/A N/A N/A mo N/A N/A rx_init search line N/A N/A mo None N/A N/A N/A cur None N/A N/A N/A N/A N/A name args N/A N/A line split : N/A N/A N/A ValueError N/A N/A N/A N/A classes N/A name N/A NodeInfo name args N/A cur None N/A N/A N/A N/A N/A cur init append line N/A N/A name N/A N/A mo group 1 N/A cur N/A classes N/A name N/A N/A sorted N/A N/A classes values key N/A N/A N/A n N/A N/A n name N/A main N/A N/A N/A N/A N/A N/A prologue epilogue N/A load_boilerplate N/A N/A sys argv N/A 0 N/A mainf N/A open N/A N/A sys argv N/A 1 w N/A auxf N/A open N/A N/A sys argv N/A 2 w N/A mainf prologue N/A mainf N/A auxf // This file is automatically generated by pgen/astgen.py

function astDump(node)
{
    if node is None: return "None";
    if isinstance(node, str): return Node
    if isinstance(node, bool): return Node
    if isinstance(node, int): return Node
    if (Object.prototype.toString.apply(node) === '[object Array]')
        ret = ''
        for i in range(len(node)):
            ret += astDump(node[i]);
            if i != len(node) - 1):
                ret += ",";
        return ret

 N/A classes N/A parse_spec SPEC N/A info classes N/A N/A N/A a b N/A N/A info gen_source N/A mainf a N/A auxf b N/A mainf epilogue N/A auxf }
 N/A N/A N/A mainf close N/A N/A N/A auxf close N/A N/A N/A __name__ __main__ N/A N/A N/A main N/A N/A N/A sys exit 0 N/A 
### PROLOGUE
# abstract syntax node definitions
# 
# This file is automatically generated by pgen/astgen.py

OP_ASSIGN = 'OP_ASSIGN';
OP_DELETE = 'OP_DELETE';
OP_APPLY = 'OP_APPLY';

SC_LOCAL = 1;
SC_GLOBAL = 2;
SC_FREE = 3;
SC_CELL = 4;
SC_UNKNOWN = 5;

CO_OPTIMIZED = 0x0001;
CO_NEWLOCALS = 0x0002;
CO_VARARGS = 0x0004;
CO_VARKEYWORDS = 0x0008;
CO_NESTED = 0x0010;
CO_GENERATOR = 0x0020;
CO_GENERATOR_ALLOWED = 0;
CO_FUTURE_DIVISION = 0x2000;
CO_FUTURE_ABSIMPORT = 0x4000;
CO_FUTURE_WITH_STATEMENT = 0x8000;
CO_FUTURE_PRINT_FUNCTION = 0x10000;

def flatten(seq):
    l = []
    for i in range(len(seq)):
        if len(seq[i]) > 0:
            subf = flatten(seq[i])
            l += subf
        else:
            l.append(seq[i])
    return l

#