mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-19 16:21:45 +03:00
indexmap key is now a symbol
This commit is contained in:
parent
5586c42266
commit
4c18eb91b7
@ -23,8 +23,8 @@ pub use input::*;
|
||||
pub mod input_value;
|
||||
pub use input_value::*;
|
||||
|
||||
pub mod parameter;
|
||||
pub use parameter::*;
|
||||
// pub mod parameter;
|
||||
// pub use parameter::*;
|
||||
|
||||
pub mod program_input;
|
||||
pub use program_input::*;
|
||||
@ -39,6 +39,6 @@ use indexmap::IndexMap;
|
||||
use leo_errors::{InputError, LeoError, Result};
|
||||
use leo_span::{sym, Span, Symbol};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
// use std::fmt;
|
||||
|
||||
type Definitions = IndexMap<Parameter, InputValue>;
|
||||
type Definitions = IndexMap<Symbol, InputValue>;
|
||||
|
@ -48,7 +48,7 @@ impl TryFrom<ParsedInputFile> for ProgramInput {
|
||||
|
||||
for definition in section.definitions {
|
||||
target.insert(
|
||||
Parameter::from(definition.clone()),
|
||||
definition.name.name,
|
||||
InputValue::try_from((definition.type_, definition.value))?,
|
||||
);
|
||||
}
|
||||
|
@ -20,44 +20,31 @@ use super::*;
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct ProgramState {
|
||||
pub state: Definitions,
|
||||
pub record: Definitions,
|
||||
pub state_leaf: Definitions,
|
||||
}
|
||||
|
||||
impl TryFrom<ParsedInputFile> for ProgramState {
|
||||
type Error = LeoError;
|
||||
fn try_from(input: ParsedInputFile) -> Result<Self> {
|
||||
let mut state = IndexMap::new();
|
||||
let mut record = IndexMap::new();
|
||||
let mut state_leaf = IndexMap::new();
|
||||
|
||||
for section in input.sections {
|
||||
let target = match section.name {
|
||||
sym::state => &mut state,
|
||||
sym::record => &mut record,
|
||||
sym::state_leaf => &mut state_leaf,
|
||||
_ => {
|
||||
return Err(InputError::unexpected_section(
|
||||
&["state", "record", "state_leaf"],
|
||||
section.name,
|
||||
§ion.span,
|
||||
)
|
||||
.into())
|
||||
if matches!(section.name, sym::state | sym::record | sym::state_leaf) {
|
||||
for definition in section.definitions {
|
||||
state.insert(
|
||||
definition.name.name,
|
||||
InputValue::try_from((definition.type_, definition.value))?,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
for definition in section.definitions {
|
||||
target.insert(
|
||||
Parameter::from(definition.clone()),
|
||||
InputValue::try_from((definition.type_, definition.value))?,
|
||||
);
|
||||
} else {
|
||||
return Err(InputError::unexpected_section(
|
||||
&["state", "record", "state_leaf"],
|
||||
section.name,
|
||||
§ion.span,
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ProgramState {
|
||||
state,
|
||||
record,
|
||||
state_leaf,
|
||||
})
|
||||
Ok(ProgramState { state })
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::create_errors;
|
||||
use std::{
|
||||
error::Error as ErrorArg,
|
||||
fmt::{Debug, Display},
|
||||
};
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
create_errors!(
|
||||
/// InputError enum that represents all the errors for the inputs part of `leo-ast` crate.
|
||||
|
Loading…
Reference in New Issue
Block a user