From d440c2b57e5330ed5f9e6df6feb80691300f15b7 Mon Sep 17 00:00:00 2001 From: howardwu Date: Tue, 28 Jul 2020 22:36:10 -0700 Subject: [PATCH] Update documentation --- ast/README.md | 8 ++++++++ ast/src/main.rs | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ast/README.md b/ast/README.md index 99f60d0df8..1752725766 100644 --- a/ast/README.md +++ b/ast/README.md @@ -1 +1,9 @@ # leo-ast + +## Command-line instructions + +To generate an AST of the Leo program and save it as a JSON file , run: +``` +leo_ast {PATH/TO/INPUT_FILENAME}.leo {PATH/TO/OUTPUT_DIRECTORY (optional)} +``` +If no output directory is provided, then the program will store the JSON file in the local working directory. diff --git a/ast/src/main.rs b/ast/src/main.rs index 9c288c18d2..04c082da1b 100644 --- a/ast/src/main.rs +++ b/ast/src/main.rs @@ -21,20 +21,22 @@ fn main() -> Result<(), ParserError> { // Check that the correct number of command-line arguments were passed in. if cli_arguments.len() < 2 || cli_arguments.len() > 3 { - eprintln!("Error - invalid number of command-line arguments"); - println!("\nCommand-line usage:\n\n\tleo_ast {{input_filename}}.leo {{optional_output_filepath}}\n"); + eprintln!("Warning - an invalid number of command-line arguments were provided."); + println!( + "\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n" + ); return Ok(()); // Exit innocently } - // Create the input filepath. + // Construct the input filepath. let input_filepath = Path::new(&cli_arguments[1]); - // Create the serialized abstract syntax tree. + // Construct the serialized abstract syntax tree. let serialized_ast = to_leo_ast(&input_filepath)?; println!("{}", serialized_ast); - // Create the output filepath. - let output_filepath = match cli_arguments.len() == 3 { + // Determine the output directory. + let output_directory = match cli_arguments.len() == 3 { true => format!( "{}/{}.json", cli_arguments[2], @@ -43,8 +45,8 @@ fn main() -> Result<(), ParserError> { false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()), }; - // Write the serialized abstract syntax tree to the output filepath. - fs::write(Path::new(&output_filepath), serialized_ast)?; + // Write the serialized abstract syntax tree to the output directory. + fs::write(Path::new(&output_directory), serialized_ast)?; Ok(()) }