From f0dc5f2e646d701445563ba5234e42196816c91a Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Wed, 31 Jan 2024 12:38:00 -0600 Subject: [PATCH] delete the old parser --- src/main.rs | 1 - src/parse.rs | 112 --------------------------------------------------- src/shell.rs | 23 ----------- 3 files changed, 136 deletions(-) delete mode 100644 src/parse.rs diff --git a/src/main.rs b/src/main.rs index 359df32..cdd19c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ mod lex; mod line; mod log; mod output; -mod parse; mod parse2; mod prompt; mod shell; diff --git a/src/parse.rs b/src/parse.rs deleted file mode 100644 index 09ac45d..0000000 --- a/src/parse.rs +++ /dev/null @@ -1,112 +0,0 @@ -use crate::error::ParseError; -use std::{cell::RefCell, fmt, rc::Rc}; - -#[derive(PartialEq, Clone)] -pub enum Element { - Empty, - Command(String), - Literal(String), - Glob(String), -} - -impl fmt::Debug for Element { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - match self { - Element::Empty => write!(f, "()"), - Element::Command(cmd) => write!(f, "cmd<{}>", cmd), - Element::Literal(lit) => write!(f, "lit<{}>", lit), - Element::Glob(glob) => write!(f, "glob<{}>", glob), - } - } -} - -pub struct Node { - pub elem: Element, - pub parent: Option>>, - pub children: Vec>>, -} - -impl Node { - pub fn new(elem: Element) -> Self { - Self { - elem, - parent: None, - children: Vec::new(), - } - } - - pub fn empty() -> Self { - Self::new(Element::Empty) - } - - #[allow(dead_code)] - pub fn child_of(parent: Rc>, elem: Element) -> Self { - Self { - elem, - parent: Some(parent), - children: Vec::new(), - } - } -} - -impl fmt::Debug for Node { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "{:?}", self.elem)?; - if self.children.len() > 0 { - write!(f, "[")?; - for child in self.children.iter() { - write!(f, "{:?}", child.borrow())?; - } - write!(f, "]")?; - } - Ok(()) - } -} - -pub struct Tree { - target: Rc>, -} - -impl fmt::Debug for Tree { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "{:?}", self.target.borrow()) - } -} - -pub struct ChildIter { - /// pointer to the node in the tree whose children we are looking at. - parent: Rc>, - idx: usize, -} - -impl Iterator for ChildIter { - type Item = Tree; - - fn next(&mut self) -> Option { - if self.idx >= self.parent.borrow().children.len() { - None - } else { - let child = Rc::clone(&self.parent.borrow().children[self.idx]); - self.idx += 1; - Some(Tree { target: child }) - } - } -} - -impl From for Node { - fn from(value: Tree) -> Self { - value.target.replace(Node::empty()) - } -} - -impl From for Tree { - fn from(value: Node) -> Self { - Self { - target: Rc::new(RefCell::new(value)), - } - } -} - -pub fn parse>(text: S) -> Result { - todo!() -} diff --git a/src/shell.rs b/src/shell.rs index 0a78035..abfc9cd 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -4,7 +4,6 @@ use crate::{ line::Line, log::*, output, - parse::{Element, Node}, }; use std::path::{Path, PathBuf}; @@ -112,28 +111,6 @@ impl Shell { } } - pub fn exec(&mut self, root: Node) -> Result { - match root.elem { - Element::Empty => Ok(true), - Element::Command(cmd) => { - let args: Vec = root - .children - .iter() - .map(|node| match &node.borrow().elem { - Element::Literal(v) => v.clone(), - _ => todo!(), - }) - .collect(); - self.eval( - cmd.to_string(), - args.iter().map(|arg| arg.as_str()).collect(), - ) - } - Element::Literal(_) => todo!(), - Element::Glob(_) => todo!(), - } - } - pub fn eval(&mut self, cmd: String, args: Vec<&str>) -> Result { match cmd.as_str() { "pwd" => {