use std::fmt::Display; use std::str::FromStr; pub use option_ext::UncheckedOptionExt; use sexp::{Atom, Sexp}; mod option_ext; /// Convert a value to Sexp #[allow(non_snake_case)] pub fn A(s: impl Display) -> Sexp { let s = s.to_string(); let x: Result = FromStr::from_str(&s); if let Ok(x) = x { return Sexp::Atom(Atom::U(x), Default::default()); } let x: Result = FromStr::from_str(&s); if let Ok(x) = x { return Sexp::Atom(Atom::I(x), Default::default()); } let x: Result = FromStr::from_str(&s); if let Ok(x) = x { return Sexp::Atom(Atom::F(x), Default::default()); } if s.contains(|c: char| " \t\"\\\n\t\r".contains(c)) { Sexp::Atom(Atom::QS(s), Default::default()) } else { Sexp::Atom(Atom::S(s), Default::default()) } } /// Convert a value to Sexp, with a bit mask #[allow(non_snake_case)] pub fn AM(s: impl Display, offs : u32) -> Sexp { if offs == 0 { return A(s); } let s = s.to_string(); let x: Result = FromStr::from_str(&s); if let Ok(x) = x { return Sexp::Atom(Atom::S(format!("{}:{}", x, offs)), Default::default()); } let x: Result = FromStr::from_str(&s); if let Ok(x) = x { return Sexp::Atom(Atom::S(format!("{}:{}", x, offs)), Default::default()); } let x: Result = FromStr::from_str(&s); if let Ok(x) = x { return Sexp::Atom(Atom::S(format!("{}:{}", x, offs)), Default::default()); } if s.contains(|c: char| " \t\"\\\n\t\r".contains(c)) { panic!("Quoted string with a bit mask!"); } else { Sexp::Atom(Atom::S(format!("{}:{}", s, offs)), Default::default()) } }