diff options
author | Irene Knapp <ireneista@irenes.space> | 2024-04-05 18:37:56 -0700 |
---|---|---|
committer | Irene Knapp <ireneista@irenes.space> | 2024-04-05 18:37:56 -0700 |
commit | c4b01e0347b29a2f7d7c749816f09f12f9327c70 (patch) | |
tree | b953c8c5f47d1ab6c323b7f2390e37f342236b49 | |
parent | 0f089cac96360348a534d1a86d06842ab4d41e5b (diff) |
help text
Change-Id: I82e0af92d27819c933260cfe150dff08005cba02
-rw-r--r-- | src/main.rs | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 96e7abb..76a5753 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,9 +7,46 @@ use rust_decimal_macros::dec; use num_traits::pow::Pow; - mod tests; + +const HELP_TEXT: &str = + "LITERALS\n\ + 0-9 integers\n\ + _ toggle sign (or, as a command, negate the top item on the stack)\n\ + [...] string\n\ + (...) named command (see below)\n\ + \n\ + ARITHMETIC OPERATIONS\n\ + + add the top two items on the stack\n\ + - subtract the top item on the stack from the second item\n\ + * multiply the top two items on the stack\n\ + / divide the second item on the stack by the top item\n\ + % take the modulus of the second item by the base of the top item\n\ + ^ raise the second item to the power of the top item\n\ + v take the square root of the top item on the stack\n\ + \n\ + STACK OPERATIONS\n\ + d duplicate the top item on the stack\n\ + c clear the stack\n\ + , drop the top item from the stack\n\ + ! something semi-implemented\n\ + \n\ + REGISTER OPERATIONS\n\ + l load from register (register name as next character)\n\ + s store to register (register name as next character)\n\ + \n\ + CONTROL FLOW\n\ + x evaluate string\n\ + \n\ + META\n\ + p print the top item of the stack, leaving it in place\n\ + n print the top item of the stack, popping it\n\ + q quit (you can also ^D)\n\ + ? help (this message)\n\ + \n\ + Good luck!\n\n"; + #[derive(Debug,PartialEq,Eq,Clone)] enum Value { Str(String), @@ -194,8 +231,11 @@ fn command_char(c: char, state: &mut RPState) -> Result<(), Exit> { state.eat_count = 0; Ok(()) } - else if let 'p' | 'n' | 'q' | 'l' | 's' | 'v' | 'x' | 'd' | ',' | 'c' | '!' = c { + else if let 'p' | 'n' | 'q' | 'l' | 's' | 'v' | 'x' | 'd' | ',' | 'c' | '!' | '?' = c { match c { + '?' => { + print!("{}", HELP_TEXT); + }, '!' => { if state.stack.is_empty() { return Err(err_msg("Data underflow!".into())); |