diff --git a/src/ast/mod.rs b/src/ast/mod.rs index e4a2a87..351c985 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -25,6 +25,8 @@ use std::convert::Into; use std::hash::Hash; use std::hash::Hasher; +use std::fmt; + macro_rules! enum_type_equality { ( $slf:ident, $r:expr, $( $l:pat ),* ) => { match $slf { @@ -267,7 +269,7 @@ macro_rules! make_selector { /// let berry = {best = "strawberry", unique = "acai"}.best; /// let third = ["uno", "dos", "tres"].1; /// ''' -#[derive(Debug, PartialEq, Clone)] +#[derive(PartialEq, Clone)] pub struct SelectorList { pub head: Box, pub tail: Option>, @@ -280,6 +282,24 @@ impl SelectorList { } } +impl fmt::Debug for SelectorList { + fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { + write!(w, "Selector({})", self) + } +} + +impl fmt::Display for SelectorList { + fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { + try!(write!(w, "{}", self.head)); + if let Some(ref tok_vec) = self.tail { + for t in tok_vec.iter() { + try!(write!(w, ".{}", t.fragment)); + } + } + return Ok(()); + } +} + /// An ordered list of Name = Value pairs. /// /// This is usually used as the body of a tuple in the UCG AST. @@ -709,6 +729,44 @@ impl Expression { } } +impl fmt::Display for Expression { + fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { + match self { + &Expression::Simple(ref v) => { + try!(write!(w, "{}", v.to_string())); + } + &Expression::Binary(_) => { + try!(write!(w, "")); + } + &Expression::Compare(_) => { + try!(write!(w, "")); + } + &Expression::ListOp(_) => { + try!(write!(w, "")); + } + &Expression::Copy(_) => { + try!(write!(w, "")); + } + &Expression::Grouped(_) => { + try!(write!(w, "()")); + } + &Expression::Format(_) => { + try!(write!(w, "")); + } + &Expression::Call(_) => { + try!(write!(w, "")); + } + &Expression::Macro(_) => { + try!(write!(w, "")); + } + &Expression::Select(_) => { + try!(write!(w, "