Expand description
§fn-bnf
This crate contains a no_std compatible, low-allocation parsing library
that uses a BNF-like syntax with the define! macro to allow for
using arbitrary Rust items as grammar rules,
and for parsing both strs and any [T] (for example, [u8] or [Token]).
If you just want to skip to writing grammars, look at the documentation for define!.
§Feature flags
This crate has two feature flags:
more_tuple_impls, raising the amount of elementsRuleis implemented for on tuples ofRules from 16 to 256 - however, enabling this will raise compilation times dramaticallyerror_in_core, enabling use of this library before Rust 1.81.0 onnightlycompilers - however, continued support for versions below 1.81.0 is not guaranteed
§A note about the stack
This library’s very lifeblood is deep - and likely recursive - function calls. You may run into stack overflow issues if you have an overly complex grammar, or are blindly parsing malicious input.
§Licensing
This crate is dual-licensed under the Apache 2.0 or MIT licenses.
Modules§
- Contains some common error types.
Macros§
- Allows defining multiple custom rules using a PEG-like syntax.
- Convenience macro for quickly defining errors with static messages for use in your grammars.
Structs§
- Matches one of any character or slice member. Fails on empty input.
- Attempts to parse a rule, returning its result. See
Rule::attempt. - Matches a rule forever, failing if it does. See
Rule::consume_all. - Always fails with a given error.
- Matches a rule an arbitrary amount of times. See
Rule::take. - Maps a function over the output of a rule. See
Rule::map_parsed. - Errors if a rule matches. See
Rule::prevent. - Holds data about something that went wrong while parsing a rule.
- Matches a rule a set amount of times. See
Rule::repeat - Repeatedly matches a rule a known amount of times. See
Rule::repeat_for. - Struct returned by
Rule::spannedto store the span and source of a given parsed rule. - Records the span of a given rule. See
Rule::spanned. - Attempts to map a function over the output of a rule. See
Rule::try_map_parsed. - Takes input until a given function fails.
Traits§
- Defines a rule’s name separate from the
Ruletrait. - Trait dictating that something can be used as a rule within a parsing grammar.
Type Aliases§
- Alias for a refernce to a
dynRule object of a given type and output. - The
!type.
Derive Macros§
- Derive macro generating an impl of the trait
NamedRule.