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
chfrom the input. Returnschor a recoverable error. See alsoparse_any_char - Strips exactly 1 string
prefixfrom the input. Returnsprefixor a recoverable error. - Parse a balanced group of
open&closecharacters. Returns the group without the initialopen& the finalclose, or: - Strips characters from the input until
predreturnstrue, i.e. while it returnsfalse. Returns the consumed string slice or a recoverable error. See alsoparse_while - Strips characters from the input until
delimiteris met. Thedelimiteris omitted from both the output and the rest of the input. Returns the string consumed before thedelimiteror a recoverable error. - The output is a string up to the point where
predreturnedtrueany returned error is recoverable
Type Aliases§
- The result of a parser.