From 340e6334709823aaeeb97436a0f57948a15b8fd9 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 2 Sep 2020 23:05:03 -0700 Subject: [PATCH] fix state file errors --- compiler/src/compiler.rs | 16 +++++++++++++--- leo/commands/build.rs | 3 ++- package/src/inputs/pairs.rs | 2 +- package/src/inputs/state.rs | 4 ++-- typed/src/common/span.rs | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index f93aa0e197..cc2ec6aa4e 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -73,20 +73,29 @@ impl> Compiler { input_string: &str, input_path: PathBuf, state_string: &str, + state_path: PathBuf, ) -> Result<(), CompilerError> { let input_syntax_tree = LeoInputParser::parse_file(&input_string).map_err(|mut e| { e.set_path(input_path.clone()); e })?; - let state_syntax_tree = LeoInputParser::parse_file(&state_string)?; + let state_syntax_tree = LeoInputParser::parse_file(&state_string).map_err(|mut e| { + e.set_path(state_path.clone()); + + e + })?; self.program_input.parse_input(input_syntax_tree).map_err(|mut e| { e.set_path(input_path); e })?; - self.program_input.parse_state(state_syntax_tree)?; + self.program_input.parse_state(state_syntax_tree).map_err(|mut e| { + e.set_path(state_path); + + e + })?; Ok(()) } @@ -114,10 +123,11 @@ impl> Compiler { input_string: &str, input_path: PathBuf, state_string: &str, + state_path: PathBuf, ) -> Result { let mut compiler = Self::new(package_name, main_file_path, output_directory); - compiler.parse_input(input_string, input_path, state_string)?; + compiler.parse_input(input_string, input_path, state_string, state_path)?; compiler.parse_program()?; diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 27fcc88d2a..96f00ef056 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -113,7 +113,7 @@ impl CLI for BuildCommand { let (input_string, input_path) = InputFile::new(&package_name).read_from(&path)?; // Load the state file at `package_name.in` - let state_string = StateFile::new(&package_name).read_from(&path)?; + let (state_string, state_path) = StateFile::new(&package_name).read_from(&path)?; // Log compilation of files to console tracing::info!("Compiling main program... ({:?})", main_file_path); @@ -126,6 +126,7 @@ impl CLI for BuildCommand { &input_string, input_path, &state_string, + state_path, )?; // Compute the current program checksum diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index e2c00b05ae..c00c8ea908 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -70,7 +70,7 @@ impl TryFrom<&PathBuf> for InputPairs { pairs.insert(file_name.to_owned(), pair); } } else if file_extension == STATE_FILE_EXTENSION.trim_start_matches(".") { - let state_file = StateFile::new(file_name).read_from(&file)?; + let state_file = StateFile::new(file_name).read_from(&file)?.0; if pairs.contains_key(file_name) { let pair = pairs.get_mut(file_name).unwrap(); diff --git a/package/src/inputs/state.rs b/package/src/inputs/state.rs index a8c2043f5a..594d6e4cb6 100644 --- a/package/src/inputs/state.rs +++ b/package/src/inputs/state.rs @@ -49,11 +49,11 @@ impl StateFile { } /// Reads the state input variables from the given file path if it exists. - pub fn read_from(&self, path: &PathBuf) -> Result { + pub fn read_from(&self, path: &PathBuf) -> Result<(String, PathBuf), StateFileError> { let path = self.setup_file_path(path); let input = fs::read_to_string(&path).map_err(|_| StateFileError::FileReadError(path.clone()))?; - Ok(input) + Ok((input, path)) } /// Writes the standard input format to a file. diff --git a/typed/src/common/span.rs b/typed/src/common/span.rs index ac58c59c8b..b5af258eb2 100644 --- a/typed/src/common/span.rs +++ b/typed/src/common/span.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use pest::{Position, Span as AstSpan}; +use pest::Span as AstSpan; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]