From 89148a623c4c62ecb48e0c8a2c6bf86143178b62 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 3 Dec 2022 20:38:56 -0500 Subject: [PATCH] Move the list to its own file. --- src/parser/list.rs | 29 +++++++++++++++++++++++++++++ src/parser/mod.rs | 1 + src/parser/new_context.rs | 7 ------- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 src/parser/list.rs diff --git a/src/parser/list.rs b/src/parser/list.rs new file mode 100644 index 00000000..235a5831 --- /dev/null +++ b/src/parser/list.rs @@ -0,0 +1,29 @@ +use std::rc::Rc; + +pub struct List { + head: Option>>, +} + +pub struct Node { + data: T, + parent: Option>>, +} + +impl List { + pub fn new() -> Self { + List { head: None } + } + + pub fn push_front(&self, data: T) -> List { + List { + head: Some(Rc::new(Node { + data: data, + parent: self.head.clone(), + })), + } + } + + pub fn get_data(&self) -> &T { + &self.data + } +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 74d94558..4a9a2727 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,3 +1,4 @@ +mod list; mod new_context; mod nom_context; mod parser_with_context; diff --git a/src/parser/new_context.rs b/src/parser/new_context.rs index f184433a..8b137891 100644 --- a/src/parser/new_context.rs +++ b/src/parser/new_context.rs @@ -1,8 +1 @@ -pub struct List { - head: Option>>, -} -pub struct Node { - data: T, - parent: Option>>, -}