diff --git a/src/parser/nodes/constant.rs b/src/parser/nodes/constant.rs new file mode 100644 index 0000000..cd40049 --- /dev/null +++ b/src/parser/nodes/constant.rs @@ -0,0 +1,24 @@ +/* parser/nodes/constant.rs + * Eryn Wells + */ + +use std::fmt; +use types::{Boolean, Number}; +use super::TreeDebug; + +pub trait ConstantValue {} +impl ConstantValue for Boolean {} +impl ConstantValue for Number {} + +#[derive(Debug)] +pub struct Constant { + value: V +} + +impl TreeDebug for Constant {} + +impl Constant { + pub fn new(value: V) -> Constant { + Constant { value: value } + } +} diff --git a/src/parser/nodes/mod.rs b/src/parser/nodes/mod.rs index ad2ba69..28a824d 100644 --- a/src/parser/nodes/mod.rs +++ b/src/parser/nodes/mod.rs @@ -2,6 +2,23 @@ * Eryn Wells */ +use std::fmt; + pub use self::constant::Constant; mod constant; +mod program; + +trait TreeDebug: fmt::Debug { + fn tree_indent(indent: u8) -> String { + (0..10).fold(String::new(), |mut acc, i| { + acc.push(' '); + acc + }) + } + + fn tree_fmt(&self, f: &mut fmt::Formatter, indent: u8) -> fmt::Result { + write!(f, "{}{:?}", self.tree_indent(indent), self) + } +} + diff --git a/src/parser/nodes/program.rs b/src/parser/nodes/program.rs new file mode 100644 index 0000000..0c47ce0 --- /dev/null +++ b/src/parser/nodes/program.rs @@ -0,0 +1,26 @@ +/* parser/nodes/program.rs + * Eryn Wells + */ + +use std::fmt; + +use super::TreeDebug; +use super::Constant; + +pub struct Program { + forms: Vec, +} + +impl TreeDebug for Program { + fn tree_fmt(&self, f: fmt::Formatter, indent: u8) -> fmt::Result { + let spaces = self.tree_indent(indent); + let mut result = write!(f, "{}Program", spaces); + for form in self.forms { + if result.is_err() { + break; + } + result = form.tree_fmt(f, indent + 2); + } + result + } +}