Crate parser_compose

source ·
Expand description

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

The crate is logically organized into three 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.

Errors

Error handling is an important part of parsing. What good is a good parser if you cannot understand what happened when it failed?

parser-compose take a simple but comprehensive approach to error handling: All parsers and combinators report errors by building up an ErrorTree. If the top level parser fails, the result will contain an instance of this tree.

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
  • Input to parsers should either be a &str or a slice (i.e. &[T])
  • A parser that reports an error if it fails, but pipes its value through a function if it succeeds. See map().
  • 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

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