Some halfwritten stuff
This commit is contained in:
parent
6223fc20f3
commit
753247ee83
@ -18,19 +18,67 @@ impl ProgrammingLanguageInterface for Rukka {
|
|||||||
|
|
||||||
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> ReplOutput {
|
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> ReplOutput {
|
||||||
let mut output = ReplOutput::default();
|
let mut output = ReplOutput::default();
|
||||||
output.add_output(eval(input));
|
output.add_output(parse(input).and_then(|x| eval(x)).unwrap());
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval(input: &str) -> String {
|
fn eval(ast: Sexp) -> Result<String, String> {
|
||||||
let a = List { next: None };
|
Ok(format!("Everything is ()"))
|
||||||
let b = List { next: Some(&a) };
|
}
|
||||||
|
|
||||||
format!("Everything is () {:?}", b)
|
enum Token {
|
||||||
|
LParen,
|
||||||
|
RParen,
|
||||||
|
Symbol(String)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tokenize(input: &str) -> Vec<Token> {
|
||||||
|
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<Sexp, String> {
|
||||||
|
let _tokens = tokenize(input);
|
||||||
|
Ok(Sexp::Atom(AtomT::Number(1)))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Sexp {
|
||||||
|
Atom(AtomT),
|
||||||
|
List(Vec<Sexp>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum AtomT {
|
||||||
|
Symbol(String),
|
||||||
|
Number(u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct List<'a> {
|
struct List<'a> {
|
||||||
next: Option<&'a List<'a>>,
|
next: Option<&'a List<'a>>,
|
||||||
|
data: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user