Crate shrimple_parser

source ·
Expand description

Zero-dependency library for writing parsers in a concise functional style & with exhaustive error-reporting.

Kinds of errors are distinguished via a user-defined Expectation type, which signals what did a parser expect. A ParsingError can also have no expectation, which will mean that the error is recoverable. Some built-in parsers can have Infallible as their expectation, which means that any error the parser may ever return is recoverable. The distinction between recoverable & fatal errors is important for parsers that need to try multiple options.

Error reporting with precise location in the source is facilitated by methods such as Parser::parse_with_err_loc, ParsingError::with_src_loc

Modules§

  • This module contains utilities for working with generic tuples, such as:

Structs§

Traits§

  • The core of the crate, a trait representing a function that takes some string as input and returns either a tuple of (the rest of the input, the output) or a ParsingError.

Functions§

  • Strips any 1 character from the input. Returns the parsed character or a recoverable error. See also parse_char
  • Strips exactly 1 character ch from the input. Returns ch or a recoverable error. See also parse_any_char
  • Strips exactly 1 string prefix from the input. Returns prefix or a recoverable error.
  • Parse a balanced group of open & close characters. Returns the group without the initial open & the final close, or:
  • Strips characters from the input until pred returns true, i.e. while it returns false. Returns the consumed string slice or a recoverable error. See also parse_while
  • Strips characters from the input until delimiter is met. The delimiter is omitted from both the output and the rest of the input. Returns the string consumed before the delimiter or a recoverable error.
  • The output is a string up to the point where pred returned true any returned error is recoverable

Type Aliases§