3 stable releases
1.0.2 | Aug 29, 2023 |
---|---|
1.0.1 | Aug 28, 2023 |
1.0.0 | Aug 25, 2023 |
0.1.0 |
|
#1527 in Rust patterns
460KB
112 lines
Context free language parser
This crate provides functionality for parsing context-free languages and was written for use with fck. The documentation will also link you to some benchmarks. These were performed on a MacBook Pro with an M1 Pro CPU. The times are mainly intended for comparisons and not to be used as absolute values.
Usage
This crate provides a derive macro for the Parser
trait. It also provides another trait and two structs used along-side the Parser
trait.
For how to use the derive macro, you will need to read the documentation
Examples
The examples directory contains some example files with generated expansions. These are generated using cargo-expand
and have been neatened up to make them more readable.
The structure of the examples is the same for all of them:
- Two enums for
TokenType
andToken
along with required trait impls mod nodes
which contains the nodes with#[derive(Parser)]
mod equivalent
which is the expanded code for theParser
impl
Current issues
- Errors are a bit rudimentary at the moment:
- If you consider the rule
(Token::T1)?, Token::T2
, the first token could be eitherToken::T1
orToken::T2
. If neither of these are found then the returned error will say it expectedToken::T2
. A future version wil have better errors where theexpected
is aVec<E>
that will be calculated for each possible error position for more useful errors - When parsing an enum, if no variants can be matched, then the error from the error returned is from mathing the first variant. This is a lossy error and may be change in the future
- If you consider the rule
- Non-positional token data is not saved (with positional data only being saved in a
NodeWrapper
). This is intended for v1.1.0 with an additional method in theNodeData
trait to return additional data wrapped in anOption
. This will then be wrapped in a new struct to contain additional data