From cf36381b394678bd528466c563c520517a916810 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 17 Oct 2021 18:47:36 -0700 Subject: sexpr: simplify by removing quote and vector types --- src/sexpr.rs | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'src/sexpr.rs') diff --git a/src/sexpr.rs b/src/sexpr.rs index bc13bd4..6cef563 100644 --- a/src/sexpr.rs +++ b/src/sexpr.rs @@ -34,8 +34,6 @@ pub enum SExpr { SIdentifier(String), SString(String), SList(Vec), - SVector(Vec), - //SQuote(Vec), } //////////// Lexing, Parsing, and Printing @@ -45,7 +43,7 @@ fn is_whitespace(c: char) -> bool{ } fn is_seperator(c: char) -> bool { - "()#".find(c) != None + "()".find(c) != None } fn is_valid_identifier(s: &str) -> bool { @@ -193,7 +191,7 @@ pub fn sexpr_parse(tokens: &Vec<&str>, depth: u32) -> Result<(Vec, usize) while i < tokens.len() { parsed += 1; match tokens[i] { - "(" | "#(" => { + "(" => { // "Read ahead" to check for empty tuple if i+1 < tokens.len() && tokens[i+1] == ")" { ret.push(SExpr::SNull); @@ -203,11 +201,7 @@ pub fn sexpr_parse(tokens: &Vec<&str>, depth: u32) -> Result<(Vec, usize) let (expr_list, skip) = sexpr_parse(&tokens[i+1..].to_vec(), depth+1)?; i += skip; parsed += skip; - match tokens[i-skip] { - "(" => ret.push(SExpr::SList(expr_list)), - "#(" => ret.push(SExpr::SVector(expr_list)), - _ => unreachable!(), - }; + ret.push(SExpr::SList(expr_list)); } }, ")" => { @@ -251,19 +245,6 @@ pub fn sexpr_repr(ast: &SExpr) -> Result { let elements: Vec = list.iter().map(|ref el| sexpr_repr(&el).unwrap()).collect(); Ok(format!("({})", elements.join(" "))) }, - &SExpr::SVector(ref list) => { - let elements: Vec = list.iter().map(|ref el| sexpr_repr(&el).unwrap()).collect(); - Ok(format!("#({})", elements.join(" "))) - }, - /* - &SExpr::SQuote(ref list) => { - let mut ret: String = - list.iter().fold("(quote ".to_string(), - |acc, ref el| acc + " " + &sexpr_repr(&el).unwrap()); - ret.push_str(" )"); - Ok(ret) - }, - */ } } -- cgit v1.2.3