diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2021-10-17 18:47:36 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2021-10-17 18:47:36 -0700 |
commit | cf36381b394678bd528466c563c520517a916810 (patch) | |
tree | d6416ca192f8c8c2d066a6cc1cb1ca68f5350e7d /src/sexpr.rs | |
parent | d797df5488bf7ed84b6a53cc503bec15262a31bf (diff) | |
download | casual-cf36381b394678bd528466c563c520517a916810.tar.gz casual-cf36381b394678bd528466c563c520517a916810.zip |
sexpr: simplify by removing quote and vector types
Diffstat (limited to 'src/sexpr.rs')
-rw-r--r-- | src/sexpr.rs | 25 |
1 files changed, 3 insertions, 22 deletions
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<SExpr>), - SVector(Vec<SExpr>), - //SQuote(Vec<SExpr>), } //////////// 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<SExpr>, 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<SExpr>, 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<String, String> { let elements: Vec<String> = list.iter().map(|ref el| sexpr_repr(&el).unwrap()).collect(); Ok(format!("({})", elements.join(" "))) }, - &SExpr::SVector(ref list) => { - let elements: Vec<String> = 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) - }, - */ } } |