Struct Grammar

Source
pub struct Grammar {
    pub start: String,
    pub rules: HashMap<String, Vec<Rc<Rule>>>,
    /* private fields */
}

Fields§

§start: String§rules: HashMap<String, Vec<Rc<Rule>>>

Implementations§

Source§

impl Grammar

Source

pub fn new(rules: Vec<Rule>) -> Result<Self, Err>

Source

pub fn is_nullable(&self, s: &str) -> bool

Source§

impl Grammar

Source

pub fn parse_chart(&self, input: &[&str]) -> Chart

Source

pub fn parse_forest(&self, input: &[&str]) -> Forest

Source

pub fn unify_tree( tree: SynTree<Rc<Rule>, String>, ) -> Result<(SynTree<String, String>, NodeRef), Err>

Source

pub fn parse(&self, input: &[&str]) -> Vec<(SynTree<String, String>, NodeRef)>

Source

pub fn read_from_file<P: AsRef<Path>>(path: P) -> Result<Self, Err>

Trait Implementations§

Source§

impl Debug for Grammar

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Grammar

Source§

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

Formats the value using the given formatter. Read more
Source§

impl FromStr for Grammar

Parses a str into a tuple of (rules, nonterminals) Errors if the grammar doesn’t parse or is malformed

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a grammar from a string. Assumes the first rule’s symbol is the start symbol.

Source§

type Err = Box<dyn Error>

The associated error which can be returned from parsing.

Auto Trait Implementations§

§

impl Freeze for Grammar

§

impl !RefUnwindSafe for Grammar

§

impl !Send for Grammar

§

impl !Sync for Grammar

§

impl Unpin for Grammar

§

impl !UnwindSafe for Grammar

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.