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 mod input_value;
pub use input_value::*; pub use input_value::*;
pub mod parameter; // pub mod parameter;
pub use parameter::*; // pub use parameter::*;
pub mod program_input; pub mod program_input;
pub use program_input::*; pub use program_input::*;
@ -39,6 +39,6 @@ use indexmap::IndexMap;
use leo_errors::{InputError, LeoError, Result}; use leo_errors::{InputError, LeoError, Result};
use leo_span::{sym, Span, Symbol}; use leo_span::{sym, Span, Symbol};
use serde::{Deserialize, Serialize}; 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 { for definition in section.definitions {
target.insert( target.insert(
Parameter::from(definition.clone()), definition.name.name,
InputValue::try_from((definition.type_, definition.value))?, InputValue::try_from((definition.type_, definition.value))?,
); );
} }

View File

@ -20,44 +20,31 @@ use super::*;
#[derive(Debug, Clone, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ProgramState { pub struct ProgramState {
pub state: Definitions, pub state: Definitions,
pub record: Definitions,
pub state_leaf: Definitions,
} }
impl TryFrom<ParsedInputFile> for ProgramState { impl TryFrom<ParsedInputFile> for ProgramState {
type Error = LeoError; type Error = LeoError;
fn try_from(input: ParsedInputFile) -> Result<Self> { fn try_from(input: ParsedInputFile) -> Result<Self> {
let mut state = IndexMap::new(); let mut state = IndexMap::new();
let mut record = IndexMap::new();
let mut state_leaf = IndexMap::new();
for section in input.sections { for section in input.sections {
let target = match section.name { if matches!(section.name, sym::state | sym::record | sym::state_leaf) {
sym::state => &mut state, for definition in section.definitions {
sym::record => &mut record, state.insert(
sym::state_leaf => &mut state_leaf, definition.name.name,
_ => { InputValue::try_from((definition.type_, definition.value))?,
return Err(InputError::unexpected_section( );
&["state", "record", "state_leaf"],
section.name,
&section.span,
)
.into())
} }
}; } else {
return Err(InputError::unexpected_section(
for definition in section.definitions { &["state", "record", "state_leaf"],
target.insert( section.name,
Parameter::from(definition.clone()), &section.span,
InputValue::try_from((definition.type_, definition.value))?, )
); .into());
} }
} }
Ok(ProgramState { Ok(ProgramState { state })
state,
record,
state_leaf,
})
} }
} }

View File

@ -15,10 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::create_errors; use crate::create_errors;
use std::{ use std::fmt::{Debug, Display};
error::Error as ErrorArg,
fmt::{Debug, Display},
};
create_errors!( create_errors!(
/// InputError enum that represents all the errors for the inputs part of `leo-ast` crate. /// InputError enum that represents all the errors for the inputs part of `leo-ast` crate.