-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductions.rs
25 lines (21 loc) · 1001 Bytes
/
productions.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use liblet::production::{production, ProductionPredicate};
use liblet::symbol::symbol;
extern crate liblet;
// simple production usage
fn main() {
// let's create a production
// we can create producions directly from strings
let p = production("A", "B C");
// we can access production sides
println!("Production lhs: {:?}", p.lhs());
println!("Production rhs: {:?}", p.rhs());
// and even get a set of all symbols involved in the production
println!("Production symbols: {:?}", p.symbols());
// we can test if productions have some properties
// by using production predicates
assert!(ProductionPredicate::LhsEquals(vec![symbol("A")]).test(&p));
assert!(!ProductionPredicate::LhsEquals(vec![]).test(&p));
assert!(ProductionPredicate::RhsEquals(vec![symbol("B"), symbol("C")]).test(&p));
assert!(!ProductionPredicate::RhsEquals(vec![symbol("C")]).test(&p));
// you can discover more predicates and usage checking out the documentation
}