summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs26
-rw-r--r--src/tests.rs3
2 files changed, 17 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 5ee8d68..8ecb03e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -72,7 +72,7 @@ fn print_value(v: &Value) {
 
 
 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
-enum Mode {
+pub enum Mode {
   Integer,
   Decimal,
   Str,
@@ -113,15 +113,7 @@ fn main() {
     registers: baseline_registers(),
     stack: Vec::new(),
     mode: Mode::CommandChar,
-    readtables: BTreeMap::from([
-      (Mode::Integer, make_integer_readtable()),
-      (Mode::Decimal, make_decimal_readtable()),
-      (Mode::Str, make_string_readtable()),
-      (Mode::CommandChar, make_command_character_readtable()),
-      (Mode::CommandNamed, make_command_string_readtable()),
-      (Mode::RegisterChar, make_register_character_readtable()),
-      (Mode::RegisterStr, make_register_string_readtable()),
-    ]),
+    readtables: make_default_readtables(),
     wip_str: String::from(""),
     // TODO: I don't think we need a return stack
     // But this the closest thing we have right now
@@ -165,7 +157,7 @@ fn usize_to_decimal(input: usize) -> Decimal {
 
 type ReadAction = Rc<dyn Fn(char, &mut RPState) -> Result<(), Exit>>;
 
-struct ReadTable {
+pub struct ReadTable {
   action_map: BTreeMap<char, ReadAction>,
   default_action: ReadAction,
 }
@@ -223,6 +215,18 @@ struct RPState {
 //    Err(err_msg("(shuf) not implemented yet!".into()))
 // }
 
+pub fn make_default_readtables() -> BTreeMap<Mode, ReadTable> {
+  BTreeMap::from([
+    (Mode::Integer, make_integer_readtable()),
+    (Mode::Decimal, make_decimal_readtable()),
+    (Mode::Str, make_string_readtable()),
+    (Mode::CommandChar, make_command_character_readtable()),
+    (Mode::CommandNamed, make_command_string_readtable()),
+    (Mode::RegisterChar, make_register_character_readtable()),
+    (Mode::RegisterStr, make_register_string_readtable()),
+  ])
+}
+
 fn make_command_string_readtable() -> ReadTable {
   let mut result = ReadTable::new(move |c, state| {
     state.wip_str.push(c);
diff --git a/src/tests.rs b/src/tests.rs
index 013696b..166567f 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -6,10 +6,11 @@ mod tests {
 
     fn new_state() -> RPState {
         return RPState {
-            registers: baseline_regsiters(),
+            registers: baseline_registers(),
             stack: Vec::new(),
             eat_count: 0,
             mode: Mode::CommandChar,
+            readtables: make_default_readtables(),
             is_num_negative: false,
             wip_str: String::from(""),
             reg_command: String::from(""),