Crate parser_compose

source ·
Expand description

See the README.md for a crash course in parser combinators.

The crate is logically organized into two parts

Parsers

Any rust items that implement the Parser trait can parse input by calling try_parse()

Additionally, any function with the right signature automatically becomes a parser.

Parser combinators

The associated methods on the Parser trait are used to combine with other parsers.

The sequence combinator is so common that it has a special form. Tuples of parsers implement Parser such that the tuple parser succeeds if all its parsers succeed.

Examples

Checkout the integration test directory for concrete parsing examples.

Structs

  • A parser that reports an error if it fails, otherwise calls a function with the wrapped value and returns the result. See and_then()
  • A parser that recognizes an ascii str in the given range. See ascii_str
  • A parser that recognizes an byte in the given range. See byte
  • A parser that reports an error if it fails, but pipes its value through a function if it succeeds. See map().
  • A parser that returns its value if it succeeds, but pipes its error through a function if it fails. See map_err()
  • A parser that always succeeds but will wrap its value in an Option. See optional()
  • A parser that succeeds if at least one inner parser succeeds. See or()
  • A parser that does not consume any input regardless of its outcome. See peeked()
  • A parser that only succeeds if it does not report an error and the predicate returns true. See when()
  • A parser that succeeds if it matches the specified number of times. See repeated()

Enums

  • The error type for parsers and their combinators

Traits

Functions

  • A parser that recognizes the first byte in a byte slice.
  • A parser that recognizes the first unicode scalar value at the start of a string slice.
  • Returns a parser that recognizes the first byte in a string slice if its value is in the specified range
  • Returns a parser that recognizes the first byte in a byte slice if its value is in the specified range

Type Aliases

  • The return value of this crate’s parsers