From 753247ee836d407026db04a192bcdeb59ad75802 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 28 Nov 2017 03:37:16 -0800 Subject: [PATCH] Some halfwritten stuff --- src/rukka_lang/mod.rs | 58 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index e8e3827..55a3ec2 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -18,19 +18,67 @@ impl ProgrammingLanguageInterface for Rukka { fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> ReplOutput { let mut output = ReplOutput::default(); - output.add_output(eval(input)); + output.add_output(parse(input).and_then(|x| eval(x)).unwrap()); output } } -fn eval(input: &str) -> String { - let a = List { next: None }; - let b = List { next: Some(&a) }; +fn eval(ast: Sexp) -> Result { + Ok(format!("Everything is ()")) +} - format!("Everything is () {:?}", b) +enum Token { + LParen, + RParen, + Symbol(String) +} + +fn tokenize(input: &str) -> Vec { + let mut iter = input.chars().peekable(); + let mut tokens = Vec::new(); + loop { + match iter.next() { + None => break, + Some('(') => tokens.push(LParen), + Some(')') => tokens.push(RParen), + Some(c) if c.is_whitespace() => continue, + Some(c) => { + let mut sym = String::new(); + loop { + match iter.peek() { + None | Some('(') | Some(')') => break, + Some(c) if c.is_whitespace() => break, + Some(c) => sym.push_char(c), + } + iter.next(); + } + tokens.push(Symbol(sym)); + } + } + } + tokens +} + +fn parse(input: &str) -> Result { + let _tokens = tokenize(input); + Ok(Sexp::Atom(AtomT::Number(1))) +} + +#[derive(Debug)] +enum Sexp { + Atom(AtomT), + List(Vec), +} + +#[derive(Debug)] +enum AtomT { + Symbol(String), + Number(u64), } #[derive(Debug)] struct List<'a> { next: Option<&'a List<'a>>, + data: usize } +