mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-19 07:32:26 +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 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>;
|
||||||
|
@ -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))?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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,
|
|
||||||
§ion.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()),
|
§ion.span,
|
||||||
InputValue::try_from((definition.type_, definition.value))?,
|
)
|
||||||
);
|
.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ProgramState {
|
Ok(ProgramState { state })
|
||||||
state,
|
|
||||||
record,
|
|
||||||
state_leaf,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user