Change Symbol -> Word for token

This commit is contained in:
greg 2017-12-01 03:00:42 -08:00
parent 3fcb840ce5
commit d235b47bc5

View File

@ -58,7 +58,7 @@ fn read(input: &str) -> Result<Vec<Sexp>, String> {
enum Token { enum Token {
LParen, LParen,
RParen, RParen,
Symbol(String) Word(String)
} }
#[derive(Debug)] #[derive(Debug)]
@ -90,7 +90,7 @@ fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> {
_ => true _ => true
} }
}).collect(); }).collect();
tokens.push(Symbol(format!("{}{}", c, sym))); tokens.push(Word(format!("{}{}", c, sym)));
} }
} }
} }
@ -100,7 +100,7 @@ fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> {
fn parse(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> { fn parse(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
use self::Token::*; use self::Token::*;
match tokens.next() { match tokens.next() {
Some(Symbol(s)) => Ok(Sexp::Atom(AtomT::Symbol(s))), Some(Word(s)) => Ok(Sexp::Atom(AtomT::Symbol(s))),
Some(LParen) => parse_sexp(tokens), Some(LParen) => parse_sexp(tokens),
Some(RParen) => Err(format!("Unexpected ')'")), Some(RParen) => Err(format!("Unexpected ')'")),
None => Err(format!("Unexpected end of input")), None => Err(format!("Unexpected end of input")),