You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
856 B
34 lines
856 B
use std::fmt::Display;
|
|
use std::str::FromStr;
|
|
|
|
pub use option_ext::UncheckedOptionExt;
|
|
use sexp::{Atom, Sexp};
|
|
|
|
mod option_ext;
|
|
|
|
/// Convert a string token to Sexp
|
|
#[allow(non_snake_case)]
|
|
pub fn A(s: impl Display) -> Sexp {
|
|
let s = s.to_string();
|
|
|
|
let x: Result<u64, _> = FromStr::from_str(&s);
|
|
if let Ok(x) = x {
|
|
return Sexp::Atom(Atom::U(x), Default::default());
|
|
}
|
|
|
|
let x: Result<i64, _> = FromStr::from_str(&s);
|
|
if let Ok(x) = x {
|
|
return Sexp::Atom(Atom::I(x), Default::default());
|
|
}
|
|
|
|
let y: Result<f64, _> = FromStr::from_str(&s);
|
|
if let Ok(y) = y {
|
|
return Sexp::Atom(Atom::F(y), 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())
|
|
}
|
|
}
|
|
|