summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 3866316..9055d5f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -117,6 +117,7 @@ fn main() {
       (Mode::Integer, make_integer_readtable()),
       (Mode::Decimal, make_decimal_readtable()),
       (Mode::Str, make_string_readtable()),
+      (Mode::CommandNamed, make_command_string_readtable()),
     ]),
     wip_str: String::from(""),
     // TODO: I don't think we need a return stack
@@ -219,10 +220,14 @@ struct RPState {
 //    Err(err_msg("(shuf) not implemented yet!".into()))
 // }
 
-fn command_str(c: char, state: &mut RPState) -> Result<(), Exit> {
-  if c != ')' {
+fn make_command_string_readtable() -> ReadTable {
+  let mut result = ReadTable::new(move |c, state| {
     state.wip_str.push(c);
-  } else if c == ')' {
+
+    Ok(())
+  });
+
+  result.set_action(')', move |_, state| {
     match state.wip_str.as_str() {
       // TODO:
       // (times)
@@ -238,22 +243,22 @@ fn command_str(c: char, state: &mut RPState) -> Result<(), Exit> {
             Value::Str(eval_body) => {
               state.wip_str.clear();
               state.mode = Mode::CommandChar;
-              return eval(&eval_body, state);
+              eval(&eval_body, state)
             }
             _ => {
-              return Err(err_msg(format!(
+              Err(err_msg(format!(
                   "Unable to execute ({}) as a named word", word)))
             }
           }
         } else {
-          return Err(err_msg(format!(
+          Err(err_msg(format!(
               "Unable to execute ({}) as a named word", word)))
         }
       }
     }
-  }
+  });
 
-  Ok(())
+  result
 }
 
 
@@ -586,7 +591,6 @@ fn eval(input: &str, state: &mut RPState) -> Result<(), Exit> {
     } else {
       match state.mode {
         Mode::CommandChar => command_char(c, state),
-        Mode::CommandNamed => command_str(c, state),
         Mode::RegisterChar => register_char(c, state),
         Mode::RegisterStr => register_str(c, state),
         _ => return Err(err_msg(