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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
use std::collections::HashMap; #[derive(Debug, PartialEq)] pub struct RispError(String); pub type RispResult = Result<RispType, RispError>; #[derive(Debug, PartialEq, Clone)] pub enum RispType { Int(i64), Str(String), List(Vec<RispType>), Vector(Vec<RispType>), Map(HashMap<String, RispType>), Keyword(String), Symbol(String), Function(fn(Vec<RispType>) -> RispResult), } pub fn error<S: Into<String>>(message: S) -> RispError { RispError(message.into()) } pub fn error_result<S: Into<String>>(message: S) -> RispResult { Err(error(message)) } pub fn symbol<S: Into<String>>(s: S) -> RispType { RispType::Symbol(s.into()) } pub fn keyword<S: Into<String>>(s: S) -> RispType { RispType::Keyword(s.into()) } pub fn string<S: Into<String>>(s: S) -> RispType { RispType::Str(s.into()) } #[allow(dead_code)] pub fn map<S: Into<String>>(pairs: Vec<(S, RispType)>) -> RispType { let result: HashMap<String, RispType> = pairs.into_iter() .map(|(s, r)| (s.into(), r)) .collect(); RispType::Map(result) }