From e439a2fdff58aee1f18203770575f99ae83579e6 Mon Sep 17 00:00:00 2001 From: damirka Date: Mon, 21 Feb 2022 21:52:12 +0300 Subject: [PATCH] added additional argument to examples --- parser/examples/input_parser.rs | 28 ++++++++++++++-------------- parser/src/lib.rs | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/parser/examples/input_parser.rs b/parser/examples/input_parser.rs index a39ab3b590..39765ee28e 100644 --- a/parser/examples/input_parser.rs +++ b/parser/examples/input_parser.rs @@ -19,24 +19,23 @@ use leo_span::symbol::create_session_if_not_set_then; use std::{env, fs, path::Path}; -fn to_leo_tree(filepath: &Path) -> Result { - // Loads the Leo code as a string from the given file path. - let program_filepath = filepath.to_path_buf(); - let program_string = fs::read_to_string(&program_filepath).expect("failed to open input file"); +fn to_leo_tree(input_filepath: &Path, state_filepath: &Path) -> Result { + // Loads the inputs a string from the given file path. + let input_string = fs::read_to_string(&input_filepath.to_path_buf()).expect("failed to open an input file"); + let state_string = fs::read_to_string(&state_filepath.to_path_buf()).expect("failed to open a state file"); // Parses the Leo file constructing an ast which is then serialized. create_session_if_not_set_then(|_| { Handler::with(|handler| { - let input = leo_parser::parse_program_input( + let input = leo_parser::parse_program_inputs( &handler, - program_string.clone(), - filepath.to_str().unwrap(), - program_string, - filepath.to_str().unwrap(), + input_string.clone(), + input_filepath.to_str().unwrap(), + state_string, + state_filepath.to_str().unwrap(), )?; let json = input.to_json_string()?; - println!("{}", json); Ok(json) }).map_err(|e| e.to_string()) }) @@ -47,23 +46,24 @@ fn main() -> Result<(), String> { let cli_arguments = env::args().collect::>(); // 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() < 3 || cli_arguments.len() > 4 { eprintln!("Warning - an invalid number of command-line arguments were provided."); println!( - "\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.in {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n" + "\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.in {{PATH/TO/STATE_FILENAME}}.in {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n" ); return Ok(()); // Exit innocently } // Construct the input filepath. let input_filepath = Path::new(&cli_arguments[1]); + let state_filepath = Path::new(&cli_arguments[2]); // Construct the serialized syntax tree. - let serialized_leo_tree = to_leo_tree(input_filepath)?; + let serialized_leo_tree = to_leo_tree(input_filepath, state_filepath)?; println!("{}", serialized_leo_tree); // Determine the output directory. - let output_directory = match cli_arguments.len() == 3 { + let output_directory = match cli_arguments.len() == 4 { true => format!( "{}/{}.json", cli_arguments[2], diff --git a/parser/src/lib.rs b/parser/src/lib.rs index e2dcd1bbf4..c045c2fb61 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -42,8 +42,8 @@ pub fn parse_ast, Y: AsRef>(handler: &Handler, path: T, sourc Ok(Ast::new(parser::parse(handler, path.as_ref(), source.as_ref())?)) } -/// Parses program input from from the input file path and state file path -pub fn parse_program_input, Y: AsRef, T2: AsRef, Y2: AsRef>( +/// Parses program inputs from from the input file path and state file path +pub fn parse_program_inputs, Y: AsRef, T2: AsRef, Y2: AsRef>( handler: &Handler, input_string: T, input_path: Y,