Expand description
Zero-dependency library with no-std support for writing parsers in a concise functional style & with rich error-reporting.
The library’s structure can be represented as the trinity of
The basic form of a parser is
use shrimple_parser::{Input, ParsingResult};
fn foo<In: Input>(input: In) -> ParsingResult<In, Foo, FooParseError> { ... }If the parser is infallible, i.e. never returns an unrecoverable error, it’s customary to make it generic over the reason type, to make combining it easier.
fn foo<In: Input, Reason>(input: In) -> ParsingResult<In, Foo, Reason> { ... }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.
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
Re-exports§
pub use parser::MappingParser;pub use parser::Parser;pub use pattern::Pattern;
Modules§
- parser
- A collection of fundamental parsers to build out your own.
- pattern
- Abstractions for working with patterns.
- tuple
- This module contains utilities for working with generic tuples, such as:
- utils
- This module provides utility functions for locating pointers into text.
Macros§
- any
- Make a parser/pattern that tries any of the provided paths.
- call
- 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.
- from_
tuple - 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.
- match_
out - Make a mapping parser that chooses the path based on the current output of the parser. The usage
- nonzero
- Create a non-zero integer from a literal.
- seq
- Create a sequence of parsers or patterns.
Structs§
- Full
Location - Like
Location, but also stores the path to the file. - Full
Parsing Error - A final error with information about where in the source did the error occur.
- Location
- Location of the error. Useful for error reporting, and used by
crate::FullParsingError - Parsing
Error - Error returned by a parser.
Enums§
- Line
Column ToLocation Error proc-macro2 - The error returned when converting a
proc_macro2::LineColumntoLocation.
Traits§
Type Aliases§
- Parsing
Result - The result of a parser.