Skip to content

Commit

Permalink
refactor(runtime): Transfer Error, Kind, ... to drake-types
Browse files Browse the repository at this point in the history
  • Loading branch information
watcol committed Jul 26, 2022
1 parent 166c1dc commit da24526
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
56 changes: 1 addition & 55 deletions drake-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,7 @@ use drake_types::ast::{
Expression, ExpressionKind, Key, KeyKind, Literal, Pattern, PatternKind, Statement,
StatementKind, TableHeaderKind,
};
use drake_types::runtime::{Element, Table, Value};

/// Snapshots for the runtime.
#[derive(Clone, Debug, PartialEq)]
pub struct Snapshot<L> {
pub root: Table<L>,
pub errors: Vec<Error<L>>,
}

/// Errors for runtimes
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error<L> {
DuplicateKey {
existing: Range<L>,
found: Range<L>,
},
KindMismatch {
expect: Vec<Kind>,
found: Kind,
span: Range<L>,
},
UnallowedDefaultValue {
span: Range<L>,
},
NotSupported {
feature: &'static str,
span: Range<L>,
},
Unexpected,
}

/// Name of value kinds for errors.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Kind {
Character,
String,
Integer,
Float,
Array,
Table,
}

impl Kind {
/// Evaluates a kind from the value.
pub fn from_value<L>(val: &Value<L>) -> Self {
match val {
Value::Character(_) => Self::Character,
Value::String(_) => Self::String,
Value::Integer(_) => Self::Integer,
Value::Float(_) => Self::Float,
Value::Array(_) => Self::Array,
Value::Table(_) => Self::Table,
}
}
}
use drake_types::runtime::{Element, Error, Kind, Snapshot, Table, Value};

#[derive(Clone, Debug, PartialEq)]
struct Environment<L> {
Expand Down
54 changes: 54 additions & 0 deletions drake-types/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,57 @@ impl<L> Table<L> {
self.local.values_mut().for_each(|elem| elem.default = true);
}
}

/// Snapshots for the runtime.
#[derive(Clone, Debug, PartialEq)]
pub struct Snapshot<L> {
pub root: Table<L>,
pub errors: Vec<Error<L>>,
}

/// Errors for runtimes
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error<L> {
DuplicateKey {
existing: Range<L>,
found: Range<L>,
},
KindMismatch {
expect: Vec<Kind>,
found: Kind,
span: Range<L>,
},
UnallowedDefaultValue {
span: Range<L>,
},
NotSupported {
feature: &'static str,
span: Range<L>,
},
Unexpected,
}

/// Name of value kinds for errors.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Kind {
Character,
String,
Integer,
Float,
Array,
Table,
}

impl Kind {
/// Evaluates a kind from the value.
pub fn from_value<L>(val: &Value<L>) -> Self {
match val {
Value::Character(_) => Self::Character,
Value::String(_) => Self::String,
Value::Integer(_) => Self::Integer,
Value::Float(_) => Self::Float,
Value::Array(_) => Self::Array,
Value::Table(_) => Self::Table,
}
}
}

0 comments on commit da24526

Please sign in to comment.