indexmap key is now a symbol

This commit is contained in:
damirka 2022-02-22 01:11:58 +03:00
parent 5586c42266
commit 4c18eb91b7
5 changed files with 20 additions and 36 deletions

View File

@ -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>;

View File

@ -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))?,
);
}

View File

@ -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,
&section.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,
&section.span,
)
.into());
}
}
Ok(ProgramState {
state,
record,
state_leaf,
})
Ok(ProgramState { state })
}
}

View File

@ -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.