Crate fn_bnf

Crate fn_bnf 

Source
Expand description

Repository Latest version Documentation MSRV unsafe forbidden License

§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 elements Rule is implemented for on tuples of Rules from 16 to 256 - however, enabling this will raise compilation times dramatically
  • error_in_core, enabling use of this library before Rust 1.81.0 on nightly compilers - 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§

errors
Contains some common error types.

Macros§

define
Allows defining multiple custom rules using a PEG-like syntax.
err
Convenience macro for quickly defining errors with static messages for use in your grammars.

Structs§

Action
Runs a function when parsed. Parses nothing, and returns the function’s output.
Any
Matches one of any character or slice member. Fails on empty input.
Attempt
Attempts to parse a rule, returning its result. See Rule::attempt.
Consume
Matches a rule forever, failing if it does. See Rule::consume_all.
Fail
Always fails with a given error.
Many
Matches a rule an arbitrary amount of times. See Rule::take.
Map
Maps a function over the output of a rule. See Rule::map_parsed.
Not
Errors if a rule matches. See Rule::prevent.
ParseError
Holds data about something that went wrong while parsing a rule.
Repeat
Matches a rule a set amount of times. See Rule::repeat
RepeatFor
Repeatedly matches a rule a known amount of times. See Rule::repeat_for.
Separated
Parses similar to Many, but with an separator rule between each parse. See [Rule::separated].
Span
Struct returned by Rule::spanned to store the span and source of a given parsed rule.
Spanned
Records the span of a given rule. See Rule::spanned.
TryMap
Attempts to map a function over the output of a rule. See Rule::try_map_parsed.
While
Takes input until a given function fails.

Traits§

NamedRule
Defines a rule’s name separate from the Rule trait.
Rule
Trait dictating that something can be used as a rule within a parsing grammar.

Type Aliases§

AnyRule
Alias for a refernce to a dyn Rule object of a given type and output.
Never
The ! type.

Derive Macros§

NamedRule
Derive macro generating an impl of the trait NamedRule.