From 2d346a53120e2747646c97db122c668df4b2837c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 16 May 2020 00:30:09 +0800 Subject: [PATCH] add help --- src/main.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 422b793..20f9130 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,16 +5,14 @@ mod compiler; mod context; mod vm; -use std::{ - env, - fs::read_to_string, -}; +use std::{ env, fs::read_to_string, }; use err::*; use parser::*; use compiler::*; use context::*; use vm::*; +const VERSION: &str = env!("CARGO_PKG_VERSION"); // https://playsecurity.org/rawfile/grass_mud_horse_language_specification.md // https://p.rogram.me/grassmudhorse.js/grassmudhorse.js @@ -24,8 +22,16 @@ fn main() { let is_compile = env::args().any(|a| a == "-c" || a == "--compile"); let arg_file = env::args().filter(|a| !a.starts_with("-")).nth(1); + if is_debug { + println!("[DEBUG] Run in debug mode"); + } + if is_help { - println!("grassmudhorse.rs v0.1"); + println!("GrassMudHorse in Rust v{}\n", VERSION); + println!("grassmudhorse [OPTIONS] file_name"); + println!(" -h, --help print this message"); + println!(" -d, --debug run in debug mode"); + println!(" -c, --compile compile grassmudhorse source code"); return; } @@ -51,14 +57,14 @@ fn main() { if is_compile { match compile_lang(&input) { Ok(compiled) => println!("{}", compiled), - Err(err) => println!("Compile error: {}", err), + Err(err) => println!("[ERROR] Compile error: {}", err), } return; } let instructions = match parse_lang(&input) { Ok(i) => i, Err(err) => { - println!("Parse error: {}", err); + println!("[ERROR] Parse error: {}", err); return; }, }; @@ -77,7 +83,7 @@ fn main() { match vm.execute(&mut context) { Err(RuntimeError::EndVm) => (), - Err(err) => println!("Vm error: {}", err), + Err(err) => println!("[ERROR] Vm error: {}", err), Ok(_) => (), }