Struct parol::grammar::production::Pr[][src]

pub struct Pr(pub Symbol, pub Rhs);
Expand description

Production type

Tuple Fields

0: Symbol1: 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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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));

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.