From d04c5973ea5a40d518faf704b7b88dcfecd81e0d Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Thu, 13 Oct 2022 18:47:28 +0200 Subject: [PATCH] =?UTF-8?q?Improve=20the=20arguments=20=F0=9F=A6=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/discord.xml | 2 +- Cargo.toml | 3 +-- src/arguments.rs | 11 +++++++++++ src/bf_interpreter/error.rs | 4 ---- src/main.rs | 6 ++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.idea/discord.xml b/.idea/discord.xml index 817edf2..30bd411 100644 --- a/.idea/discord.xml +++ b/.idea/discord.xml @@ -2,6 +2,6 @@ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 821c434..2da4aa8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ keywords = [ "interpreter", "repl", "bf", - "bf-interpreter", "bf-repl", "brainfuck-interpreter", "brainfuck-repl", @@ -34,7 +33,7 @@ exclude = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = { version = "4.0.14", features = ["derive", "color", "cargo"] } +clap = { version = "4.0.14", features = ["derive", "color", "cargo", "wrap_help", "suggestions"] } log = "0.4.17" pretty_env_logger = "0.4.0" colored = "2.0.0" diff --git a/src/arguments.rs b/src/arguments.rs index 0c0ecb0..986e921 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -20,9 +20,20 @@ pub struct Args { pub enum Feature { /// If the value is you want decrement the value and the value is 0, don't set the value to 255, otherwise decrement the value. /// If the value is you want increment the value and the value is 255, don't set the value to 0, otherwise increment the value. + /// The alias are: `nrv` + #[clap(alias = "nrv")] NoReverseValue, /// If the pointer at the end of the array, set the pointer to 0, otherwise increment the pointer. /// If the pointer at the beginning of the array, set the pointer to the end of the array, otherwise decrement the pointer. + /// The alias are: `rp` + #[clap(alias = "rp")] ReversePointer, + /// Allow the use of utf8 characters (32 bit), otherwise only 8 bit characters are allowed. + /// Use this feature with caution because it increases the cell size from 8 bits to 32 bits. + /// It also allow you to use the emoji in your brainfuck code :D, + /// This is if you can preserve your mind so that you can access their digital value :). + /// The `u32` in rust can only store values from 0 to 4294967295, but we can only use 0 to 1114111 (0x10FFFF) for now. + /// The alias are: `utf8` + #[clap(alias = "utf8")] AllowUtf8, } diff --git a/src/bf_interpreter/error.rs b/src/bf_interpreter/error.rs index 41047c9..24bcba0 100644 --- a/src/bf_interpreter/error.rs +++ b/src/bf_interpreter/error.rs @@ -102,10 +102,6 @@ mod tests { ); assert_eq!(error.code, 13); - /*let error = InterpreterErrorKind::FlushError(e).to_error(); - assert_eq!(error.to_string(), "Failed to read byte from stdin: no bytes available"); - assert_eq!(error.code, 14);*/ - let error = InterpreterErrorKind::UnmatchedBracket.to_error(); assert_eq!(error.to_string(), "Unmatched bracket"); assert_eq!(error.code, 15); diff --git a/src/main.rs b/src/main.rs index 79fa966..2b64ad9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,13 +19,11 @@ fn main() { let args = Args::parse(); info!("Parsed command line arguments: {:?}", args); - let term = console::Term::stdout(); - info!("Initializing interpreter"); let mut interpreter = Interpreter::new( args.array_size, args.features.unwrap_or_else(|| vec![]), - term, + console::Term::stdout(), ); match args.source { @@ -41,7 +39,7 @@ fn main() { println!( "{}", format!( - "Successfully ran brainfuck source code from file: {}", + "Successfully run brainfuck source code from file: {}", source ) .bold()