Struct parol::grammar::production::Pr [−][src]
Expand description
Production type
Tuple Fields
0: Symbol
1: Rhs
Implementations
Calculates the length of the terminal symbols at the beginning of the RHS.
use parol::{Pr, Symbol};
let pr = Pr::new("S", vec![]);
assert_eq!(0, pr.first_len());
let pr = Pr::new("S", vec![Symbol::n("N"), Symbol::n("L")]);
assert_eq!(0, pr.first_len());
let pr = Pr::new("S", vec![Symbol::n("I"), Symbol::n("L")]);
assert_eq!(0, pr.first_len());
let pr = Pr::new("S", vec![Symbol::t(","), Symbol::n("N")]);
assert_eq!(1, pr.first_len());
let pr = Pr::new("S", vec![Symbol::t("d")]);
assert_eq!(1, pr.first_len());
let pr = Pr::new("S", vec![Symbol::t("d"), Symbol::t("e")]);
assert_eq!(2, pr.first_len());
Calculates the length of the terminal symbols starting from an offset within the RHS.
use parol::{Pr, Symbol};
let pr = Pr::new("S", vec![]);
assert_eq!(0, pr.first_len_at(0));
assert_eq!(0, pr.first_len_at(1));
let pr = Pr::new("S", vec![Symbol::n("N"), Symbol::n("L")]);
assert_eq!(0, pr.first_len_at(0));
assert_eq!(0, pr.first_len_at(1));
assert_eq!(0, pr.first_len_at(2));
assert_eq!(0, pr.first_len_at(3));
let pr = Pr::new("S", vec![Symbol::t(","), Symbol::n("N")]);
assert_eq!(1, pr.first_len_at(0));
assert_eq!(0, pr.first_len_at(1));
assert_eq!(0, pr.first_len_at(2));
let pr = Pr::new("S", vec![Symbol::n("N"), Symbol::t("d"), Symbol::t("e")]);
assert_eq!(0, pr.first_len_at(0));
assert_eq!(2, pr.first_len_at(1));
assert_eq!(1, pr.first_len_at(2));
assert_eq!(0, pr.first_len_at(3));
let pr = Pr::new("S", vec![Symbol::t("c"), Symbol::t("d"), Symbol::t("e")]);
assert_eq!(3, pr.first_len_at(0));
assert_eq!(2, pr.first_len_at(1));
assert_eq!(1, pr.first_len_at(2));
assert_eq!(0, pr.first_len_at(3));
let pr = Pr::new("S", vec![Symbol::t("c"), Symbol::t("d"), Symbol::t("e"), Symbol::n("N")]);
assert_eq!(3, pr.first_len_at(0));
assert_eq!(2, pr.first_len_at(1));
assert_eq!(1, pr.first_len_at(2));
assert_eq!(0, pr.first_len_at(3));
assert_eq!(0, pr.first_len_at(4));
Calculates whether a next derivation is necessary and possible to get a first length of k. If the first_len is already equal or greater than k there is no derivation necessary. Else if no non-terminal is contained then a derivation is not possible Else it returns true.
use parol::{Pr, Symbol};
let pr = Pr::new("S", vec![]);
assert!(!pr.is_k_derivable(1), "Empty production - not possible");
let pr = Pr::new("S", vec![Symbol::n("N"), Symbol::n("L")]);
assert!(pr.is_k_derivable(1), "k_len == 0 but containing Nt - possible");
let pr = Pr::new("S", vec![Symbol::t(","), Symbol::n("N")]);
assert!(!pr.is_k_derivable(1), "k_len == 1 - not necessary");
assert!(pr.is_k_derivable(2), "k_len == 1 but containing Nt - not necessary");
let pr = Pr::new("S", vec![Symbol::t("d")]);
assert!(!pr.is_k_derivable(1), "k_len == 1 - not necessary");
assert!(!pr.is_k_derivable(2), "k_len == 1, containing no Nt - not possible");
let pr = Pr::new("S", vec![Symbol::t("d"), Symbol::t("e")]);
assert!(!pr.is_k_derivable(1), "k_len == 2 - not necessary");
assert!(!pr.is_k_derivable(2), "k_len == 2 - not necessary");
assert!(!pr.is_k_derivable(3), "k_len == 2, containing no Nt - not possible");
Calculates whether a next derivation is necessary and possible to get a first length of k at a given symbol offset. If the first_len_at is already equal or greater than k there is no derivation necessary. Else if no non-terminal is contained then a derivation is not possible Else it returns true.
use parol::{Pr, Symbol};
let pr = Pr::new("S", vec![]);
assert!(!pr.is_k_derivable_at(1, 0), "Empty production - not possible");
assert!(!pr.is_k_derivable_at(1, 1), "Empty production, invalid index - not possible");
let pr = Pr::new("S", vec![Symbol::n("N"), Symbol::n("L")]);
assert!(pr.is_k_derivable_at(1, 0), "k_len == 0 but containing Nt - possible");
assert!(pr.is_k_derivable_at(1, 1), "k_len == 0 but containing Nt - possible");
assert!(!pr.is_k_derivable_at(1, 2), "invalid index - not possible");
let pr = Pr::new("S", vec![Symbol::t(","), Symbol::n("N")]);
assert!(!pr.is_k_derivable_at(1, 0), "k_len == 1 - not necessary");
assert!(pr.is_k_derivable_at(2, 0), "k_len == 1 but containing Nt - possible");
assert!(pr.is_k_derivable_at(2, 1), "k_len == 0 but containing Nt - possible");
assert!(!pr.is_k_derivable_at(2, 2), "invalid index - not possible");
let pr = Pr::new("S", vec![Symbol::t("d")]);
assert!(!pr.is_k_derivable_at(1, 0), "k_len == 1 - not necessary");
assert!(!pr.is_k_derivable_at(2, 0), "k_len == 1, containing no Nt - not possible");
assert!(!pr.is_k_derivable_at(1, 1), "invalid index - not possible");
assert!(!pr.is_k_derivable_at(2, 1), "invalid index - not possible");
let pr = Pr::new("S", vec![Symbol::t("d"), Symbol::t("e")]);
assert!(!pr.is_k_derivable_at(1, 0), "k_len == 2 - not necessary");
assert!(!pr.is_k_derivable_at(2, 0), "k_len == 2 - not necessary");
assert!(!pr.is_k_derivable_at(3, 0), "k_len == 2, containing no Nt - not possible");
assert!(!pr.is_k_derivable_at(1, 1), "k_len == 1 - not necessary");
assert!(!pr.is_k_derivable_at(2, 1), "k_len == 1 - not possible");
assert!(!pr.is_k_derivable_at(3, 1), "invalid index - not possible");
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
The output format for a production roughly follows the Yacc format.
use parol::{Pr, Symbol};
let pr = Pr::new("S", vec![]);
assert_eq!("S: ;", format!("{}", pr));
let pr = Pr::new("S", vec![Symbol::n("N"), Symbol::n("L")]);
assert_eq!("S: N L;", format!("{}", pr));
let pr = Pr::new("S", vec![Symbol::n("I"), Symbol::n("L")]);
assert_eq!("S: I L;", format!("{}", pr));
let pr = Pr::new("S", vec![Symbol::t(","), Symbol::n("N")]);
assert_eq!(r#"S: "," N;"#, format!("{}", pr));
let pr = Pr::new("S", vec![Symbol::t("d")]);
assert_eq!(r#"S: "d";"#, format!("{}", pr));
let pr = Pr::new("S", vec![Symbol::t(r#"\d"#), Symbol::t("e")]);
assert_eq!(r#"S: "\d" "e";"#, format!("{}", pr));
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.