Example #1
0
def parse(s):
    p = (State([], s) >> pyparsec.repeat(pyparsec.ignore(spaces0) >> (parse_val | pyparsec.ignore(parse_comment)))) >> pyparsec.ignore(spaces0)
    if p.state != '':
        raise ParseError(repr(p.state))
    return p.value
Example #2
0
    parse_string,
    pyparsec.lazy(lambda: parse_list),
    pyparsec.lazy(lambda: parse_quoted),
    pyparsec.lazy(lambda: parse_lazylist),
    pyparsec.lazy(lambda: parse_dict),
    pyparsec.lazy(lambda: parse_key),
)

spaces0 = pyparsec.regex(r'[\s\n\t]*')
spaces  = pyparsec.regex(r'[\s\n\t]+')

parse_list = pyparsec.seq(
    pyparsec.string('('),
    spaces0,
    parse_val.to(lambda x: [x]),
    pyparsec.repeat(spaces >> parse_val).map(operator.add),
    pyparsec.ignore(pyparsec.string(')'))
).to(List)

parse_quoted = (pyparsec.string('\'') >> parse_list).to(lambda l: QExpr(l.value)) | (pyparsec.string('\'(') >> spaces0 >> pyparsec.string(')')).to(lambda _: QuotedList([]))

parse_lazylist = pyparsec.seq(
    pyparsec.ignore(pyparsec.string('[') >> spaces0),
    parse_val.to(lambda x: [x]),
    pyparsec.repeat(spaces >> parse_val).map(operator.add),
    pyparsec.ignore(pyparsec.string(']'))
).to(LazyList) | (pyparsec.string('[') >> spaces0 >> pyparsec.string(']')).to(lambda _: LazyList([]))

parse_key = (pyparsec.string(':') >> parse_atom).to(lambda a: Getter(a.value))

def check_property_length(p):