Struct SetOfRules

Source
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

Source

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

Source

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())
}
Source

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§

Source§

impl Debug for SetOfRules

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.