From 2738119f1736da89c404be484b78facb18a5aa61 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 3 Dec 2017 06:04:53 -0800 Subject: [PATCH] Quotes --- src/rukka_lang/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 45778c1..fd22e30 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -58,6 +58,7 @@ fn read(input: &str) -> Result, String> { enum Token { LParen, RParen, + Quote, Word(String) } @@ -81,6 +82,7 @@ fn tokenize(input: &mut Peekable) -> Vec { None => break, Some('(') => tokens.push(LParen), Some(')') => tokens.push(RParen), + Some('\'') => tokens.push(Quote), Some(c) if c.is_whitespace() => continue, Some(c) => { let sym: String = input.peeking_take_while(|next| { @@ -103,6 +105,10 @@ fn parse(tokens: &mut Peekable>) -> Result { Some(Word(s)) => Ok(Sexp::Atom(AtomT::Symbol(s))), Some(LParen) => parse_sexp(tokens), Some(RParen) => Err(format!("Unexpected ')'")), + Some(Quote) => { + let quoted = parse(tokens)?; + Ok(Sexp::List(vec![Sexp::Atom(AtomT::Symbol(format!("quote"))), quoted])) + }, None => Err(format!("Unexpected end of input")), } }