Add for loop
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
7182024342
commit
42e0056374
16 changed files with 775 additions and 44 deletions
25
src/lib.rs
25
src/lib.rs
|
|
@ -1,19 +1,19 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use displaydoc::Display;
|
||||
use serde::Serialize;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::emit::Instruction;
|
||||
use crate::emit::VMInstructions;
|
||||
use crate::input::NomoInput;
|
||||
use crate::value::NomoValue;
|
||||
use crate::value::NomoValueError;
|
||||
|
||||
pub mod ast;
|
||||
pub mod emit;
|
||||
pub mod eval;
|
||||
pub mod input;
|
||||
pub mod parser;
|
||||
pub mod value;
|
||||
|
||||
#[derive(Debug, Error, Display)]
|
||||
pub enum NomoError {
|
||||
|
|
@ -89,7 +89,7 @@ struct Template {
|
|||
}
|
||||
|
||||
pub struct Context {
|
||||
values: BTreeMap<String, serde_json::Value>,
|
||||
values: HashMap<String, NomoValue>,
|
||||
}
|
||||
|
||||
impl Default for Context {
|
||||
|
|
@ -101,23 +101,26 @@ impl Default for Context {
|
|||
impl Context {
|
||||
pub fn new() -> Context {
|
||||
Context {
|
||||
values: BTreeMap::new(),
|
||||
values: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_insert(
|
||||
&mut self,
|
||||
key: impl Into<String>,
|
||||
value: impl Serialize,
|
||||
) -> Result<(), serde_json::Error> {
|
||||
self.values.insert(key.into(), serde_json::to_value(value)?);
|
||||
value: impl TryInto<NomoValue, Error = NomoValueError>,
|
||||
) -> Result<(), NomoValueError> {
|
||||
self.values.insert(key.into(), value.try_into()?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key: impl Into<String>, value: impl Serialize) {
|
||||
self.try_insert(key, value)
|
||||
.expect("inserted value should serialize without error");
|
||||
pub fn insert(&mut self, key: impl Into<String>, value: impl Into<NomoValue>) {
|
||||
self.values.insert(key.into(), value.into());
|
||||
}
|
||||
|
||||
pub fn values(&self) -> &HashMap<String, NomoValue> {
|
||||
&self.values
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue