Move the list to its own file.

This commit is contained in:
Tom Alexander 2022-12-03 20:38:56 -05:00
parent 170ddec9a9
commit 89148a623c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 30 additions and 7 deletions

29
src/parser/list.rs Normal file
View File

@ -0,0 +1,29 @@
use std::rc::Rc;
pub struct List<T> {
head: Option<Rc<Node<T>>>,
}
pub struct Node<T> {
data: T,
parent: Option<Rc<Node<T>>>,
}
impl<T> List<T> {
pub fn new() -> Self {
List { head: None }
}
pub fn push_front(&self, data: T) -> List<T> {
List {
head: Some(Rc::new(Node {
data: data,
parent: self.head.clone(),
})),
}
}
pub fn get_data(&self) -> &T {
&self.data
}
}

View File

@ -1,3 +1,4 @@
mod list;
mod new_context;
mod nom_context;
mod parser_with_context;

View File

@ -1,8 +1 @@
pub struct List<T> {
head: Option<Rc<Node<T>>>,
}
pub struct Node<T> {
data: T,
parent: Option<Rc<Node<T>>>,
}