aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs51
1 files changed, 5 insertions, 46 deletions
diff --git a/src/main.rs b/src/main.rs
index 0f67aa4..9a025b9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,7 +9,7 @@ mod cexpr;
use cexpr::CExpr;
-fn repl(verbose: bool) {
+fn repl(_verbose: bool) {
let stdin = io::stdin();
let mut stdout = io::stdout();
@@ -25,55 +25,14 @@ fn repl(verbose: bool) {
stdout.write(b"\nCiao!\n").unwrap();
return;
}
- // TODO: use debug or something instead of "verbose"?
- let tokens = match sexpr::sexpr_tokenize(&raw_input) {
- Ok(tokens) => {
- if verbose { println!("Tokens: {}", tokens.join(", ")); };
- tokens
- },
- Err(e) => {
- println!("couldn't tokenize: {}", e);
- continue;
- }
- };
- let ast = match sexpr::sexpr_parse(&tokens, 0) {
- Ok((mut ast_list, _)) => {
- if verbose {
- for ast in &ast_list {
- println!("AST: {}", sexpr::sexpr_repr(ast).unwrap());
- };
- };
- // We're a REPL, so only one expression at a time
- if ast_list.len() > 1 {
- println!("one expression at a time on the REPL, please!");
- continue;
- } else if ast_list.len() == 0 {
- sexpr::SExpr::SNull
- } else {
- let ast = ast_list.pop().unwrap();
- ast
- }
- },
+ let expr = match CExpr::from_str(&raw_input) {
+ Ok(expr) => expr,
Err(e) => {
- println!("couldn't parse: {}", e);
+ println!("error: {}", e);
continue;
}
};
- let expr = match CExpr::from_sexpr(&ast) {
- Ok(v) => v,
- Err(e) => {
- println!("couldn't parse as math: {}", e);
- continue;
- },
- };
- match expr.to_sexpr() {
- Ok(out) => println!("{}", sexpr::sexpr_repr(&ast).unwrap()),
- Err(e) => {
- println!("couldn't return to sexpr: {}", e);
- continue;
- },
-
- }
+ println!("{}", expr);
}
}