[Subversion] / PEAK-Rules / Code-Generation.txt  

Diff of /PEAK-Rules/Code-Generation.txt

Parent Directory | Revision Log

version 2471, Sun Jan 6 15:05:56 2008 UTC version 2490, Sat Jan 19 15:56:52 2008 UTC
Line 45 
Line 45 
 expression's AST using this builder instance::  expression's AST using this builder instance::
   
     >>> def pe(expr):      >>> def pe(expr):
     ...     print parse_expr(expr, builder)      ...     return parse_expr(expr, builder)
   
   
 Names and Constants  Names and Constants
Line 79 
Line 79 
     NameError: fubar      NameError: fubar
   
   
   Namespaces and Binding
   ======================
   
   An ``ExprBuilder`` object's ``bindings`` attribute is a list of dictionaries,
   mapping names to the desired outputs::
   
       >>> builder.bindings
       [{}, {'a': Local('a'), 'c': Local('c'), 'b': Local('b'), 'e': Local('e'),
             'd': Local('d'), 'g': Local('g'), 'f': Local('f')},
             {...}, {...}, {...}]
   
   You can add more bindings temporarily with the ``.push()`` method, then
   remove them with ``.pop()``::
   
       >>> builder.push({'q': pe('42')})
   
       >>> builder.Name('q')
       Const(42)
   
       >>> builder.pop()
       {'q': Const(42)}
   
       >>> builder.Name('q')
       Traceback (most recent call last):
         ...
       NameError: q
   
   If you omit the argument to ``.push()``, it just adds an empty namespace to
   the bindings::
   
       >>> builder.push()
       >>> builder.bindings
       [{}, {}, {'a': Local('a'), 'c': Local('c'), 'b': Local('b'),
                 'e': Local('e'), 'd': Local('d'), 'g': Local('g'),
                 'f': Local('f')}, {...}, {...}, {...}]
   
   Which you can then modify using ``.bind()``::
   
       >>> builder.bind({'x': pe('99')})
       >>> builder.bindings
       [{'x': Const(99)}, {}, {'a': Local('a'), 'c': Local('c'), 'b': Local('b'),
                               'e': Local('e'), 'd': Local('d'), 'g': Local('g'),
                               'f': Local('f')}, {...}, {...}, {...}]
   
   And finally remove with ``.pop()``::
   
       >>> builder.pop()
       {'x': Const(99)}
   
       >>> builder.bindings
       [{}, {'a': Local('a'), 'c': Local('c'), 'b': Local('b'), 'e': Local('e'),
             'd': Local('d'), 'g': Local('g'), 'f': Local('f')},
             {...}, {...}, {...}]
   
   
 Operators  Operators
 =========  =========
   


Generate output suitable for use with a patch program
Legend:
Removed from v.2471  
changed lines
  Added in v.2490

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help