Esempio n. 1
0
 def __init__(self, *static_types):
     self.static_type = static.Or(static_types)
Esempio n. 2
0
"""

from __future__ import print_function
"""
TODO: write something that can convert a number into its textual representation,
so like the opposite of the number parser example, and then write something that
can format a list of items into, say, "first", "first or second", "first, second, or third", etc, meaning
that it converts a list of items into an english language phrase describing that set properly. Also add
things for extracting keys from maps.
"""

from parcon import static
import six

sequence_type = static.Sequence()
sequence_or_dict_type = static.Or(static.Sequence(), static.Type(dict))

class Result(object):
    """
    A formatter result. Instances of this class are returned from
    Formatter.format.
    
    Two fields are present: text and remainder. If this result represents
    failure of a formatter, text will be None and remainder will be unspecified.
    If this result represents success, text will be the text produced by the
    formatter, and remainder will be the portion of the input object that the
    parser did not consume.
    
    Result objects have a boolean truth value corresponding to whether or not
    they succeeded. For example, this could be used to print whether some
    particular result succeeded: