Esempio n. 1
0
File: macros.py Progetto: MacLeek/mh
def SeqOfOne(name, *args, **kw):
    """a sequence of one element. only the first element is meaningful, the
    rest are discarded
    * name - the name of the sequence
    * args - subconstructs
    * kw - any keyword arguments to Sequence
    """
    return IndexingAdapter(Sequence(name, *args, **kw), index=0)
Esempio n. 2
0
def SeqOfOne(name, *args, **kw):
    r"""A sequence of one element. only the first element is meaningful, the
    rest are discarded

    :param name: the name of the sequence
    :param \*args: subconstructs
    :param \*\*kw: any keyword arguments to Sequence
    """
    return IndexingAdapter(Sequence(name, *args, **kw), index=0)
Esempio n. 3
0
File: common.py Progetto: MacLeek/mh
def StringUpto(name, terminators, consume_terminator = False, allow_eof = True):
    """a string that stretches up to a terminator, or EOF. this is a more
    flexible version of CString.
    * name - the name of the field
    * terminator - the set of terminator characters
    * consume_terminator - whether to consume the terminator character. the
      default is False.
    * allow_eof - whether to allow EOF to terminate the string. the default
      is True. this option is applicable only if consume_terminator is set.
    """
    con = StringAdapter(OptionalGreedyRange(CharNoneOf(name, terminators)))
    if not consume_terminator:
        return con
    if allow_eof:
        term = Optional(CharOf(None, terminators))
    else:
        term = CharOf(None, terminators)
    return IndexingAdapter(Sequence("foo", con, term), index = 0)