peel
Dynamic parsing within trees 🌲 🌳 🌴
Target of this library is to provide a flexible approach in parsing data. This will mainly be done within
arena based
parser trees which can be modified during runtime. Every parser is using the
nom framework for the actual parsing work. A complete source code example can be found
within the src/example
directory of the crate.
Architecture and usage
Every Peel
instance can be seen as a parsing graph structure which has different states and transitions. In the
example within the crate the structure looks like this:
Independently of what these parser do, the creation of this structure is done within the peel_example
function:
The first created parser will automatically be the root parser and the entry point for the tree traversal. Every
succeeding parser returns a certain result, which will be pushed into a vector as a Box<Any>
which can be downcasted
to a certain other type.
This means that the traversal method of Peel
will try to find the deepest possible valid path within the tree
structure. After the creation of the structure the traversal can begin:
let mut peel = peel_example;
peel.set_log_level;
let result = peel.traverse.unwrap;
assert_eq!;
println!;
With the help of the log crate it will output:
[peel] [DEBUG] Parser 1 parsing succeed, left input length: 3
[peel] [DEBUG] Failed parser: Parser 3
[peel] [DEBUG] Parser 2 parsing succeed, left input length: 2
[peel] [DEBUG] Parser 3 parsing succeed, left input length: 1
[peel] [DEBUG] Parser 4 parsing succeed, left input length: 0
A minimal parser has to implement the Parser
trait which could look like this:
use *;
/// The first example parser
;
/// The result of the first example parser
;
It is possible to access the current parsing result
for a more advanced behavior like dependency checks during the
parsing. Furthermore, additional data data
can be used to share data between parsers.
Contributing
You want to contribute to this project? Wow, thanks! So please just fork it and send me a pull request.