pub struct SetOfRules(/* private fields */);
Expand description
The set of rules to be parsed Any rule has a name A rule can be registered just once The starting rule is main
Implementations§
Source§impl SetOfRules
impl SetOfRules
Sourcepub fn new(mrules: HashMap<String, Expression>) -> Self
pub fn new(mrules: HashMap<String, Expression>) -> Self
Initialize a set of rules with a hashmap of <String, Expression>
In general, is better to use the rules!
macro
Sourcepub fn add(self, name: &str, expr: Expression) -> Self
pub fn add(self, name: &str, expr: Expression) -> Self
As this is a dynamic parser, it is necessary to add rules on runtime.
This method, will take the owner ship, and will return itself
In this way, you don’t need to declare mutable vars. You could need recursion in some cases
To add several rules at once, look for merge
#[macro_use] extern crate dynparser;
use dynparser::parse;
fn main() {
let rules = rules!{
"main" => and!{
rep!(lit!("a"), 1, 5),
ref_rule!("rule2")
}
};
let rules = rules.add("rule2", lit!("bcd"));
assert!(parse("aabcd", &rules).is_ok())
}
Sourcepub fn merge(self, rules2merge: Self) -> Self
pub fn merge(self, rules2merge: Self) -> Self
As this is a dynamic parser, it is necessary to add rules on runtime.
This method, will take the owner ship, and will return itself
In this way, you don’t need to declare mutable vars. You could need recursion in some cases
It will add the rules from the parameter
#[macro_use] extern crate dynparser;
use dynparser::parse;
fn main() {
let rules = rules!{
"main" => and!{
rep!(lit!("a"), 1, 5),
ref_rule!("rule2")
}
};
let rules = rules.merge(rules!{"rule2" => lit!("bcd")});
assert!(parse("aabcd", &rules).is_ok())
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SetOfRules
impl RefUnwindSafe for SetOfRules
impl Send for SetOfRules
impl Sync for SetOfRules
impl Unpin for SetOfRules
impl UnwindSafe for SetOfRules
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more