Remove stuff
Preparing for a very simple parser.
This commit is contained in:
parent
f42aec4132
commit
fafb58adfa
7 changed files with 49 additions and 152 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
|
|||
21
src/main.rs
21
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
use crate::values::Key;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Path(Vec<Key>);
|
||||
12
src/table.rs
12
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<String>),
|
||||
Table(Table),
|
||||
}
|
||||
|
||||
pub struct TableOwner(Rc<RefCell<HashMap<Key, Value>>>);
|
||||
|
||||
|
|
|
|||
17
src/value.rs
Normal file
17
src/value.rs
Normal file
|
|
@ -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<String>),
|
||||
Table(Table),
|
||||
|
||||
// Float(f64),
|
||||
// Nil,
|
||||
// Path(Table),
|
||||
}
|
||||
122
src/values.rs
122
src/values.rs
|
|
@ -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<String>),
|
||||
Table(Table),
|
||||
}
|
||||
|
||||
impl From<Box<String>> for Key {
|
||||
fn from(s: Box<String>) -> Self {
|
||||
Self::String(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> 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<bool> for Key {
|
||||
fn from(b: bool) -> Self {
|
||||
Self::Bool(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i64> for Key {
|
||||
fn from(i: i64) -> Self {
|
||||
Self::Int(i)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Table> 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<String>),
|
||||
Table(Table),
|
||||
|
||||
Float(f64),
|
||||
}
|
||||
|
||||
impl From<Box<String>> for Value {
|
||||
fn from(s: Box<String>) -> Self {
|
||||
Self::String(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> 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<bool> for Value {
|
||||
fn from(b: bool) -> Self {
|
||||
Self::Bool(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i64> for Value {
|
||||
fn from(i: i64) -> Self {
|
||||
Self::Int(i)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Table> for Value {
|
||||
fn from(t: Table) -> Self {
|
||||
Self::Table(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for Value {
|
||||
fn from(f: f64) -> Self {
|
||||
Self::Float(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Key> 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue