Update documentation

This commit is contained in:
howardwu 2020-07-28 22:36:10 -07:00
parent d3894ff546
commit d440c2b57e
2 changed files with 18 additions and 8 deletions

View File

@ -1 +1,9 @@
# leo-ast # 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.

View File

@ -21,20 +21,22 @@ fn main() -> Result<(), ParserError> {
// Check that the correct number of command-line arguments were passed in. // Check that the correct number of command-line arguments were passed in.
if cli_arguments.len() < 2 || cli_arguments.len() > 3 { if cli_arguments.len() < 2 || cli_arguments.len() > 3 {
eprintln!("Error - invalid number of command-line arguments"); eprintln!("Warning - an invalid number of command-line arguments were provided.");
println!("\nCommand-line usage:\n\n\tleo_ast {{input_filename}}.leo {{optional_output_filepath}}\n"); println!(
"\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n"
);
return Ok(()); // Exit innocently return Ok(()); // Exit innocently
} }
// Create the input filepath. // Construct the input filepath.
let input_filepath = Path::new(&cli_arguments[1]); 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)?; let serialized_ast = to_leo_ast(&input_filepath)?;
println!("{}", serialized_ast); println!("{}", serialized_ast);
// Create the output filepath. // Determine the output directory.
let output_filepath = match cli_arguments.len() == 3 { let output_directory = match cli_arguments.len() == 3 {
true => format!( true => format!(
"{}/{}.json", "{}/{}.json",
cli_arguments[2], cli_arguments[2],
@ -43,8 +45,8 @@ fn main() -> Result<(), ParserError> {
false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()), false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()),
}; };
// Write the serialized abstract syntax tree to the output filepath. // Write the serialized abstract syntax tree to the output directory.
fs::write(Path::new(&output_filepath), serialized_ast)?; fs::write(Path::new(&output_directory), serialized_ast)?;
Ok(()) Ok(())
} }