diff options
author | Nadrieril | 2019-09-11 21:10:38 +0200 |
---|---|---|
committer | Nadrieril | 2019-09-11 21:10:38 +0200 |
commit | 810a3d8066c2efed3f7c74cfb171d17988168080 (patch) | |
tree | 74424ede0dcdc81b9754a1e47239f06f1ecf316f /pest_consume/src/lib.rs | |
parent | f1a4d315de5be701f29beb7d3c32af2e96f967b6 (diff) |
Add an example to pest_consume
Diffstat (limited to 'pest_consume/src/lib.rs')
-rw-r--r-- | pest_consume/src/lib.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/pest_consume/src/lib.rs b/pest_consume/src/lib.rs index 425d8cf..f14f6f5 100644 --- a/pest_consume/src/lib.rs +++ b/pest_consume/src/lib.rs @@ -1,3 +1,7 @@ +/// `pest_consume` extends [pest] to make it easy to consume the resulting pest parse tree. +/// Given a grammar file, pest generates a parser that outputs an untyped parse tree. Then that +/// parse tree needs to be transformed into whatever datastructures your application uses. +/// `pest_consume` provides two powerful macros to make this easy. use pest::error::Error; use pest::Parser as PestParser; use pest::RuleType; @@ -85,6 +89,9 @@ mod node { pub fn as_pair(&self) -> &Pair<'i, R> { &self.pair } + pub fn into_pair(self) -> Pair<'i, R> { + self.pair + } pub fn as_span(&self) -> Span<'i> { self.pair.as_span() } @@ -135,6 +142,13 @@ mod node { { Node::new(new_pair, self.user_data.clone()) } + + pub fn as_pairs(&self) -> &Pairs<'i, R> { + &self.pairs + } + pub fn into_pairs(self) -> Pairs<'i, R> { + self.pairs + } } impl<'i, R, D> Iterator for Nodes<'i, R, D> |