From fafb58adfa82083e7be8d0e338b383943142cd7a Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 28 Sep 2021 23:32:48 +0200 Subject: [PATCH] Remove stuff Preparing for a very simple parser. --- Cargo.toml | 2 - src/builtin.rs | 23 ++++++++-- src/main.rs | 21 +-------- src/path.rs | 4 -- src/table.rs | 12 ++++- src/value.rs | 17 +++++++ src/values.rs | 122 ------------------------------------------------- 7 files changed, 49 insertions(+), 152 deletions(-) delete mode 100644 src/path.rs create mode 100644 src/value.rs delete mode 100644 src/values.rs diff --git a/Cargo.toml b/Cargo.toml index a621173..ed89aa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,4 @@ name = "tada" version = "0.1.0" edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/src/builtin.rs b/src/builtin.rs index 60fddb9..117061d 100644 --- a/src/builtin.rs +++ b/src/builtin.rs @@ -1,4 +1,21 @@ +// Possible future built-ins +// +// #get - Get table's value at a key/path +// #set - Set table's value at a key/path +// #raw - Interpret values literally (either recursively or only one layer) +// #path - Construct a path from a table +// #scope - Execute a command in a new sub-scope +// #loop - Repeat a command infinitely +// #break - Break out of an infinite loop (with a value?) +// #if - Conditionally execute one of two commands +// #print - Print a string to stdout +// #input - Read a line from stdin +// #read - Load the contents of a file as string +// #write - Store a string into a file +// Arithmetic: #add #sub #neg #shiftr #shiftl +// Booleans: #and #or #not #xor #andb #orb #notb #xorb +// Comparisons: #eq #neq #lt #le #gt #ge + +/// Built-in operations #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Builtin { - Print, -} +pub enum Builtin {} diff --git a/src/main.rs b/src/main.rs index 3c5a84b..86c6736 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,7 @@ -use crate::table::{Table, TableOwner}; - mod builtin; -mod path; mod table; -mod values; +mod value; fn main() { println!("Hello, world!"); - - let table_owner = TableOwner::new(); - - let table = Table::new(&table_owner); - - table.insert("Hello".into(), "World".into()); - table.insert(1.into(), "Goodbye".into()); - dbg!(&table); - - table.remove(&0.into()); - table.remove(&1.into()); - table.remove(&2.into()); - dbg!(&table); - - table.insert(true.into(), table.clone().into()); - dbg!(&table); } diff --git a/src/path.rs b/src/path.rs deleted file mode 100644 index ab2c10d..0000000 --- a/src/path.rs +++ /dev/null @@ -1,4 +0,0 @@ -use crate::values::Key; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Path(Vec); diff --git a/src/table.rs b/src/table.rs index 03e8282..ab1df14 100644 --- a/src/table.rs +++ b/src/table.rs @@ -1,10 +1,20 @@ use std::cell::RefCell; use std::collections::HashMap; +use std::convert::TryFrom; use std::fmt::Debug; use std::hash::{Hash, Hasher}; use std::rc::{Rc, Weak}; -use crate::values::{Key, Value}; +use crate::value::Value; + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Key { + Bool(bool), + // Builtin(Builtin), + Int(i64), + String(Box), + Table(Table), +} pub struct TableOwner(Rc>>); diff --git a/src/value.rs b/src/value.rs new file mode 100644 index 0000000..5bc718f --- /dev/null +++ b/src/value.rs @@ -0,0 +1,17 @@ +use std::fmt::Debug; + +use crate::table::Table; + +// TODO: Unwrap the Key part so this is only 16, not 24 bytes +#[derive(Debug, Clone, PartialEq)] +pub enum Value { + // Bool(bool), + // Builtin(Builtin), + Int(i64), + // String(Box), + Table(Table), + + // Float(f64), + // Nil, + // Path(Table), +} diff --git a/src/values.rs b/src/values.rs deleted file mode 100644 index 51b215a..0000000 --- a/src/values.rs +++ /dev/null @@ -1,122 +0,0 @@ -use std::fmt::Debug; - -use crate::builtin::Builtin; -use crate::path::Path; -use crate::table::Table; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Key { - Bool(bool), - Builtin(Builtin), - Int(i64), - Nil, - Path(Path), - String(Box), - Table(Table), -} - -impl From> for Key { - fn from(s: Box) -> Self { - Self::String(s) - } -} - -impl From for Key { - fn from(s: String) -> Self { - Self::String(Box::new(s)) - } -} - -impl From<&str> for Key { - fn from(s: &str) -> Self { - Self::String(Box::new(s.to_string())) - } -} - -impl From for Key { - fn from(b: bool) -> Self { - Self::Bool(b) - } -} - -impl From for Key { - fn from(i: i64) -> Self { - Self::Int(i) - } -} - -impl From for Key { - fn from(t: Table) -> Self { - Self::Table(t) - } -} - -// TODO: Unwrap the Key part so this is only 16, not 24 bytes -#[derive(Debug, Clone, PartialEq)] -pub enum Value { - Bool(bool), - Builtin(Builtin), - Int(i64), - Nil, - Path(Path), - String(Box), - Table(Table), - - Float(f64), -} - -impl From> for Value { - fn from(s: Box) -> Self { - Self::String(s) - } -} - -impl From for Value { - fn from(s: String) -> Self { - Self::String(Box::new(s)) - } -} - -impl From<&str> for Value { - fn from(s: &str) -> Self { - Self::String(Box::new(s.to_string())) - } -} - -impl From for Value { - fn from(b: bool) -> Self { - Self::Bool(b) - } -} - -impl From for Value { - fn from(i: i64) -> Self { - Self::Int(i) - } -} - -impl From
for Value { - fn from(t: Table) -> Self { - Self::Table(t) - } -} - -impl From for Value { - fn from(f: f64) -> Self { - Self::Float(f) - } -} - -impl From for Value { - fn from(k: Key) -> Self { - match k { - Key::Bool(b) => Self::Bool(b), - Key::Builtin(b) => Self::Builtin(b), - Key::Int(i) => Self::Int(i), - Key::Nil => Self::Nil, - Key::Path(p) => Self::Path(p), - Key::String(s) => Self::String(s), - Key::Table(t) => Self::Table(t), - } - } -}