slightly restructuring

fogti
Sep 26, 2021, 6:45 PM
OBYTQWLPCGBRJLHKBJZZN2JGI4XHXG4KV72EF2L7ZBVR6Z3U6CRQC

Dependencies

  • [2] ZLXYE6PV cargo clippy + fmt fixes
  • [3] NAZOIBER packlist: fix crash on empty input
  • [4] VLUIVUU5 initialize repository
  • [5] V4EAN7NN move some stuff around; more packlist stuff
  • [*] BUI22CYQ +zhed-packlist

Change contents

  • file deletion: valuemodel.rs (----------)
    [3.6555][3.6556:6593](),[3.6593][3.6594:6594]()
    use std::collections::HashMap;
    use uuid::Uuid;
    #[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
    pub enum Space {
    ParaBreak,
    }
    #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
    pub enum ListType {
    Unordered,
    Ordered,
    }
    #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
    pub enum Value {
    /// unbound variable, referenced by UUID to make renaming easier
    UnboundVar(Uuid),
    /// bound variable, referenced using [De Bruijn indices](https://en.wikipedia.org/wiki/De_Bruijn_index),
    /// starting at 0
    BoundVar(usize),
    /// tagged elements, no order of evaluation is guaranteed, arguments are lazily evaluated
    Tag(Uuid, Vec<Value>),
    Space(Space),
    List(ListType, Vec<Value>),
    }
    /** document data structure
    ## header stuff
    we omit any document type tags of older formats, because we don't want to
    differentiate that much here, because it would make parsing cumbersome.
    we rather differentiate directly via indexes. Historically, type tags were
    vastly different per format nonetheless, making them slightly incompatible.
    **/
    #[derive(Clone, Debug, Deserialize, Serialize)]
    pub struct Document {
    #[serde(flatten)]
    ident: Ident,
    unbound_vars: HashMap<Uuid, String>,
    toplevel: Vec<Value>,
    }
    pub struct Context<'a> {
    unbound_vars: &'a HashMap<Uuid, String>,
    bound_vars: Vec<String>,
    }
    impl Document {
    pub fn ctx(&self) -> Context<'_> {
    Context {
    unbound_vars: &self.unbound_vars,
    bound_vars: Vec::new(),
    }
    }
    }
    #[derive(Debug, thiserror::Error)]
    pub enum Error {
    #[error("unbound variable not found: {0}")]
    UnboundVarNotFound(Uuid),
    #[error("bound variable not found")]
    BoundVarNotFound,
    }
    impl<'a> Context<'a> {
    pub fn lookup_unbound_var(&self, id: &Uuid) -> Result<&'a str, Error> {
    }
    pub fn on_bound_var<F, R>(&mut self, name: String, f: F) -> R
    where
    F: FnOnce(&mut Self) -> R,
    {
    #[cfg(debug_assertions)]
    let name2 = name.clone();
    self.bound_vars.push(name);
    let tmp = catch_unwind(AssertUnwindSafe(|| f(self)));
    #[allow(unused_variables)]
    let tmp2 = self.bound_vars.pop();
    match tmp {
    Ok(x) => {
    #[cfg(debug_assertions)]
    if tmp2 != Some(name2) {
    panic!("mismatching bound vars");
    }
    x
    Err(y) => resume_unwind(y),
    }
    }
    pub fn lookup_bound_var(&self, id: usize) -> Result<&str, Error> {
    }
    }
    /// Formatter-oriented serialization, because we usually define that per formatter,
    /// and the structures which are serialized stay mostly the same.
    pub trait Serializer: Sized {
    type Ok;
    type Error: From<Error> + std::error::Error;
    fn serialize_value(self, v: &Value, ctx: &mut Context<'_>) -> Result<Self::Ok, Self::Error>;
    fn serialize_document(self, d: &Document) -> Result<Self::Ok, Self::Error>;
    }
    self.bound_vars
    .get(self.bound_vars.len() - 1 - id)
    .map(|i| i.as_str())
    .ok_or(Error::BoundVarNotFound)
    }
    use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
    self.unbound_vars
    .get(id)
    .map(|i| i.as_str())
    .ok_or_else(|| Error::UnboundVarNotFound(*id))
    use crate::Ident;
    use serde::{Deserialize, Serialize};
  • edit in crates/zhed-core/src/lib.rs at line 1
    [3.10686]
    [3.10687]
    #![no_std]
    extern crate alloc;
    use alloc::borrow::Cow;
  • edit in crates/zhed-core/src/lib.rs at line 6
    [3.10724][3.10724:10747]()
    use std::borrow::Cow;
  • edit in crates/zhed-core/src/lib.rs at line 8
    [3.10784][3.10784:10804]()
    pub mod valuemodel;
  • replacement in crates/zhed-core/Cargo.toml at line 3
    [3.11480][3.11480:11522]()
    description = "zhed core data structures"
    [3.11480]
    [3.11522]
    description = "zhed core data structures and traits"
  • edit in crates/zhed-core/Cargo.toml at line 9
    [3.11596][3.11596:11614]()
    thiserror = "1.0"
  • edit in crates/zhed-core/Cargo.toml at line 10
    [3.11615][3.11615:11702]()
    [dependencies.chrono]
    version = "0.4"
    default-features = false
    features = [ "serde" ]
  • edit in crates/zhed-core/Cargo.toml at line 12
    [3.11739]
    [3.11739]
    default-features = false
  • edit in Cargo.lock at line 43
    [3.1430][3.8028:8277](),[3.8028][3.8028:8277](),[3.8277][3.1431:1433]()
    [[package]]
    name = "chrono"
    version = "0.4.19"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
    dependencies = [
    "num-integer",
    "num-traits",
    "serde",
    ]
  • edit in Cargo.lock at line 74
    [3.2245][3.8292:8534](),[3.8292][3.8292:8534]()
    name = "num-integer"
    version = "0.1.44"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
    dependencies = [
    "autocfg",
    "num-traits",
    ]
    [[package]]
  • edit in Cargo.lock at line 351
    [3.10613][3.10613:10624]()
    "chrono",
  • edit in Cargo.lock at line 352
    [3.12159][3.12159:12173]()
    "thiserror",
  • edit in Cargo.lock at line 360
    [7.3956]
    [3.12223]
    name = "zhed-models"
    version = "0.0.0"
    dependencies = [
    "serde",
    "thiserror",
    "zhed-core",
    ]
    [[package]]
  • edit in Cargo.lock at line 375
    [3.10722]
    [[package]]
    name = "ztx-core"
    version = "0.0.0"
    dependencies = [
    "thiserror",
    ]