pub enum Sexpr {
Atom(String),
List(Vec<Sexpr>),
}Variants§
Implementations§
Source§impl Sexpr
impl Sexpr
Sourcepub fn print(&self) -> String
pub fn print(&self) -> String
Examples found in repository?
examples/ebnftree.rs (line 38)
19fn main() {
20 let grammar = r#"
21 expr := expr ('+'|'-') term | term ;
22 term := term ('*'|'/') factor | factor ;
23 factor := '-' factor | power ;
24 power := ufact '^' factor | ufact ;
25 ufact := ufact '!' | group ;
26 group := num | '(' expr ')' ;
27 "#;
28
29 let input = std::env::args().skip(1).
30 collect::<Vec<String>>().join(" ");
31
32 use std::str::FromStr;
33 let trificator = abackus::ParserBuilder::default()
34 .plug_terminal("num", |n| f64::from_str(n).is_ok())
35 .sexprificator(&grammar, "expr");
36
37 match trificator(&mut tokenizer(input.chars())) {
38 Ok(trees) => for t in trees { println!("{}", t.print()); },
39 Err(e) => println!("{:?}", e)
40 }
41}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sexpr
impl RefUnwindSafe for Sexpr
impl Send for Sexpr
impl Sync for Sexpr
impl Unpin for Sexpr
impl UnwindSafe for Sexpr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more