parcon.pargen
index
/home/boydam/workspace/Parcon-python/parcon/parcon/pargen/__init__.py

Pargen is a formatter combinator library. It's much the opposite of parcon:
while parcon parses text into objects, pargen formats objects into text.
I'll get more documentation up on here soon, but for now, here's a JSON
formatter (essentially a simplified reimplementation of Python's json.dumps):
 
from parcon.pargen import *
from decimal import Decimal
json = Forward()
number = Type(float, int, long, Decimal) & String()
boolean = Type(bool) & ((Is(True) & "true") | (Is(False) & "false"))
null = Is(None) & "null"
string = Type(basestring) & '"' + String() + '"'
json_list = Type(list, tuple) & ("[" + ForEach(json, ", ") + "]")
json_map =Type(dict) &  ("{" + ForEach(Head(json) + ": " + Tail(json), ", ") + "}")
json << (boolean | number | null | string | json_list | json_map)
 
You can then do things like:
 
>>> print json.format([True,1,{"2":3,"4":None},5,None,False,"hello"]).text
[true, 1, {"2": 3, "4": null}, 5, null, false, "hello"]

 
Package Contents
       

 
Classes
       
__builtin__.object
Formatter
And
First
ForEach
Forward
Head
Is
IsExactly
Literal
Repr
String
Tail
Then
Type
Result

 
class And(Formatter)
    
Method resolution order:
And
Formatter
__builtin__.object

Methods defined here:
__init__(self, first, second)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class First(Formatter)
    
Method resolution order:
First
Formatter
__builtin__.object

Methods defined here:
__init__(self, *formatters)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class ForEach(Formatter)
    
Method resolution order:
ForEach
Formatter
__builtin__.object

Methods defined here:
__init__(self, formatter, delimiter='')
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Formatter(__builtin__.object)
    The main class of this module, analogous to parcon.Parser, but for
formatters.
 
  Methods defined here:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)
format(self, input)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Forward(Formatter)
    
Method resolution order:
Forward
Formatter
__builtin__.object

Methods defined here:
__init__(self, formatter=None)
__lshift__ = set(self, formatter)
format(self, input)
set(self, formatter)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Head(Formatter)
    
Method resolution order:
Head
Formatter
__builtin__.object

Methods defined here:
__init__(self, formatter)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Is(Formatter)
    
Method resolution order:
Is
Formatter
__builtin__.object

Methods defined here:
__init__(self, value)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class IsExactly(Formatter)
    
Method resolution order:
IsExactly
Formatter
__builtin__.object

Methods defined here:
__init__(self, value)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Literal(Formatter)
    
Method resolution order:
Literal
Formatter
__builtin__.object

Methods defined here:
__init__(self, text)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Repr(Formatter)
    
Method resolution order:
Repr
Formatter
__builtin__.object

Methods defined here:
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Result(__builtin__.object)
     Methods defined here:
__init__(self, text, remainder)
__nonzero__(self)
__repr__ = __str__(self)
__str__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class String(Formatter)
    
Method resolution order:
String
Formatter
__builtin__.object

Methods defined here:
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Tail(Formatter)
    
Method resolution order:
Tail
Formatter
__builtin__.object

Methods defined here:
__init__(self, formatter)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Then(Formatter)
    
Method resolution order:
Then
Formatter
__builtin__.object

Methods defined here:
__init__(self, first, second)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Type(Formatter)
    
Method resolution order:
Type
Formatter
__builtin__.object

Methods defined here:
__init__(self, *static_types)
format(self, input)

Methods inherited from Formatter:
__add__ = op_add(first, second)
__and__ = op_and(first, second)
__or__ = op_or(first, second)
__radd__ = new_function(x, y)
__rand__ = new_function(x, y)
__ror__ = new_function(x, y)

Data descriptors inherited from Formatter:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
failure()
match(text, remainder)
op_add(first, second)
op_and(first, second)
op_or(first, second)
promote(value)
reversed(function)

 
Data
        sequence_or_dict_type = Or(Sequence(), Type(<type 'dict'>))
sequence_type = Sequence()