hydra.parsers module
General-purpose parser combinators, operating on a Parser type. A helper library, not a set of parse<T> convention functions (see docs/specification/index.md, Conventions).
- hydra.parsers.alt(p1: Parser[T0], p2: Parser[T0]) Parser[T0]
Try the first parser; if it fails without consuming input, try the second.
- hydra.parsers.apply(pf: Parser[Callable[[T0], T1]], pa: Parser[T0]) Parser[T1]
Apply a parser containing a function to a parser containing a value.
- hydra.parsers.between(open: Parser[T0], close: Parser[T1], p: Parser[T2]) Parser[T2]
Parse something between an opening and closing parser.
- hydra.parsers.bind(pa: Parser[T0], f: Callable[[T0], Parser[T1]]) Parser[T1]
Sequence two parsers, passing the result of the first to a function that produces the second.
- hydra.parsers.choice(ps: Sequence[Parser[T0]]) Parser[T0]
Try each parser in the list until one succeeds.
- hydra.parsers.lazy(f: Callable[[None], Parser[T0]]) Parser[T0]
Create a parser that defers construction of another parser until parsing time. This is essential for breaking recursive parser definitions.
- hydra.parsers.many(p: Parser[T0]) Parser[Sequence[T0]]
Parse zero or more occurrences of the given parser.
- hydra.parsers.many_loop(p: Parser[T0], input: Sequence[int], acc: Sequence[T0]) object
Repeatedly apply a parser, accumulating results, until it fails.
- hydra.parsers.map(f: Callable[[T0], T1], pa: Parser[T0]) Parser[T1]
Apply a function to the result of a parser.
- hydra.parsers.optional(p: Parser[T0]) Parser[object]
Optionally parse something, returning Nothing if it fails.
- hydra.parsers.pure(a: T0) Parser[T0]
A parser that always succeeds with the given value without consuming input.
- hydra.parsers.run_parser(p: Parser[T0], input: str) object
Run a parser on the given input string. The string is converted to a codepoint list once, up front, so that the parser itself can consume characters in constant time.
- hydra.parsers.satisfy(pred: Callable[[int], bool]) Parser[int]
Parse a character (codepoint) that satisfies the given predicate.
- hydra.parsers.sep_by(p: Parser[T0], sep: Parser[T1]) Parser[Sequence[T0]]
Parse zero or more occurrences separated by a separator.
- hydra.parsers.sep_by1(p: Parser[T0], sep: Parser[T1]) Parser[Sequence[T0]]
Parse one or more occurrences separated by a separator.