diff options
-rw-r--r-- | minimal.rs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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) + }, } } |