Intersperse
This commit is contained in:
parent
6eb0fc8834
commit
35e715dfd6
@ -29,14 +29,13 @@ impl ProgrammingLanguageInterface for Rukka {
|
|||||||
Ok(sexps) => sexps
|
Ok(sexps) => sexps
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut text = String::new();
|
let output_str: String = sexps.into_iter().enumerate().map(|(i, sexp)| {
|
||||||
for (i, sexp) in sexps.into_iter().enumerate() {
|
|
||||||
match eval(sexp) {
|
match eval(sexp) {
|
||||||
Ok(result) => text.push_str(&format!("{}: {}", i, result)),
|
Ok(result) => format!("{}: {}", i, result),
|
||||||
Err(err) => text.push_str(&format!("{} Error: {}", i, err)),
|
Err(err) => format!("{} Error: {}", i, err),
|
||||||
}
|
}
|
||||||
}
|
}).intersperse(format!("\n")).collect();
|
||||||
output.add_output(text);
|
output.add_output(output_str);
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,19 +73,14 @@ fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> {
|
|||||||
Some('(') => tokens.push(LParen),
|
Some('(') => tokens.push(LParen),
|
||||||
Some(')') => tokens.push(RParen),
|
Some(')') => tokens.push(RParen),
|
||||||
Some(c) if c.is_whitespace() => continue,
|
Some(c) if c.is_whitespace() => continue,
|
||||||
Some(c) => {
|
Some(_) => {
|
||||||
let mut sym = String::new();
|
let sym: String = input.peeking_take_while(|next| {
|
||||||
sym.push(c);
|
match *next {
|
||||||
loop {
|
'(' | ')' => false,
|
||||||
match input.peek().map(|x| *x) {
|
c if c.is_whitespace() => false,
|
||||||
Some('(') | Some(')') | None => break,
|
_ => true
|
||||||
Some(c) if c.is_whitespace() => break,
|
|
||||||
Some(c) => {
|
|
||||||
sym.push(c);
|
|
||||||
input.next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}).collect();
|
||||||
tokens.push(Symbol(sym));
|
tokens.push(Symbol(sym));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user