aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-04-20 01:05:03 -0400
committerbnewbold <bnewbold@robocracy.org>2016-04-20 01:05:03 -0400
commitaabe6b810f04f75546024cd5ac5ec1c1cc7b2f8b (patch)
treecf5bd2b0d3ffb6284d9dd6dfbd68a64547c4581e
parent35137a03a8a011bc6b7681916e3de05639b32423 (diff)
downloadspectrum-aabe6b810f04f75546024cd5ac5ec1c1cc7b2f8b.tar.gz
spectrum-aabe6b810f04f75546024cd5ac5ec1c1cc7b2f8b.zip
rust: add symbol and quote types
-rw-r--r--minimal.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/minimal.rs b/minimal.rs
index c2f3b02..369b9db 100644
--- a/minimal.rs
+++ b/minimal.rs
@@ -21,8 +21,10 @@ enum SchemeExpr<'a> {
SchemeFalse,
SchemeNum(f64),
SchemeBuiltin(&'a str),
+ SchemeSymbol(&'a str),
SchemeStr(&'a str),
SchemeList(Vec<SchemeExpr<'a>>),
+ SchemeQuote(Vec<SchemeExpr<'a>>),
}
///////////////////////////////////
@@ -106,6 +108,11 @@ fn scheme_parse_token(token: &str) -> Result<SchemeExpr, &'static str> {
return Ok(SchemeExpr::SchemeStr(token));
}
+ // If it's all alphas, must be a symbol
+ if token.is_alpha() {
+ return Ok(SchemeExpr::SchemeSymbol(token));
+ }
+
return Err("unparsable token");
}
@@ -154,6 +161,7 @@ fn scheme_repr<'a>(ast: &SchemeExpr) -> Result<String, &'static str> {
&SchemeExpr::SchemeNull => Ok("'()".to_string()),
&SchemeExpr::SchemeBuiltin(b)=> Ok(b.to_string()),
&SchemeExpr::SchemeStr(s)=> Ok(s.to_string()),
+ &SchemeExpr::SchemeSymbol(s)=> Ok(s.to_string()),
&SchemeExpr::SchemeNum(num) => Ok(format!("{}", num).to_string()),
&SchemeExpr::SchemeList(ref list) => {
let mut ret: String =
@@ -162,6 +170,13 @@ fn scheme_repr<'a>(ast: &SchemeExpr) -> Result<String, &'static str> {
ret.push_str(" )");
Ok(ret)
},
+ &SchemeExpr::SchemeQuote(ref list) => {
+ let mut ret: String =
+ list.iter().fold("(quote ".to_string(),
+ |acc, ref el| acc + " " + &scheme_repr(&el).unwrap());
+ ret.push_str(" )");
+ Ok(ret)
+ },
}
}