mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-11 01:45:48 +03:00
fix state file errors
This commit is contained in:
parent
0bb8c42731
commit
340e633470
@ -73,20 +73,29 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
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<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
input_string: &str,
|
||||
input_path: PathBuf,
|
||||
state_string: &str,
|
||||
state_path: PathBuf,
|
||||
) -> Result<Self, CompilerError> {
|
||||
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()?;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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<String, StateFileError> {
|
||||
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.
|
||||
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use pest::{Position, Span as AstSpan};
|
||||
use pest::Span as AstSpan;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user