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 Reason type, which signals what did
a parser expect.
A ParsingError can also have no reason, which will mean that the error is recoverable.
Some built-in parsers can have std::convert::Infallible as their error reason,
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
constructing a FullParsingError with methods such as
Parser::with_full_error, ParsingError::with_src_loc
Modules§
- This module contains utilities for working with generic tuples, such as:
- This module provides utility functions for locating pointers into text.
Macros§
- Generates a closure that calls a function with a tuple’s contents as it arguments. The input can be anything as long as the last token contains all the arguments parenthesized.
- Generates a closure that constructs a struct from a tuple. The struct fields must be exactly in the order in which they’re expected to be in the tuple.
- Create a non-zero integer from a literal.
Structs§
- A final error with information about where in the source did the error occur.
- Error returned by a parser.
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§
- Parses any 1 character from the input. See also
parse_char - Parses exactly 1 character
chfrom the input. See alsoparse_any_char - Parses exactly 1 string
prefixfrom the input. - Parse a balanced group of
open&closecharacters. - Strips characters from the input until
predreturnstrue, i.e. while it returnsfalse, returns the string spanning the stripped characters. - Like
parse_until, but also removes the character on whichpredreturnedtruefrom the rest of the input. - Strips characters from the input until
delimiteris met, returns the string before it. Thedelimiteris omitted from both the output and the rest of the input. - Strips characters from the input until
predreturnedfalse, i.e. while it returnstrue, returns the string spanning the stripped characters. - Like
parse_while, but also removes the character on whichpredreturnedfalsefrom the rest of the input.
Type Aliases§
- The result of a parser.