示例#1
0
文件: pico.py 项目: djangosms/core
def tags():
    """Parse one or more tags, each separated by whitespace and/or a
    comma.

    >>> run_parser(tags, 'abc, def')[0]
    ['abc', 'def']
    >>> run_parser(tags, '#abc #def')[0]
    ['abc', 'def']
    """

    return map(partial("".join), sep(tag, partial(many1, partial(one_of, ' ,'))))
示例#2
0
文件: pico.py 项目: djangosms/core
def identifiers(**kwargs):
    """Parse multiple identifiers, separated by whitespace and/or
    comma.

    >>> run_parser(identifiers, 'abc123 def456')[0]
    ['abc123', 'def456']

    """

    term = partial(identifier, **kwargs)
    return map(partial("".join),
               sep(term, partial(many1, partial(one_of, ' ,'))))
示例#3
0
文件: pico.py 项目: malthe/ugandasms
def name():
    """Parses one or more names separated by whitespace, and
    concatenates with a single space.

    >>> parse(name, 'John')
    'John'

    >>> parse(name, 'John Smith')
    'John Smith'

    >>> parse(name, 'John, Smith')
    'John'

    """
    names = map(partial("".join), sep(
        partial(many1, partial(satisfies, lambda l: l.isalpha())), whitespace))

    return " ".join(names)