diff --git a/liquid-compiler/src/parser.rs b/liquid-compiler/src/parser.rs index 083f99d2e..65cc93d41 100644 --- a/liquid-compiler/src/parser.rs +++ b/liquid-compiler/src/parser.rs @@ -34,7 +34,7 @@ pub fn parse(elements: &[Element], options: &LiquidOptions) -> Result parse_expression(tokens, options)?, Element::Tag(ref tokens, _) => parse_tag(&mut iter, tokens, options)?, - Element::Raw(ref x) => Box::new(Text::new(x)), + Element::Raw(ref x) => Box::new(Text::new(x.as_str())), }; ret.push(render); token = iter.next(); @@ -202,7 +202,7 @@ fn parse_tag( // The whole nesting count machinery below is to ensure we only stop // collecting elements when we have an un-nested closing tag. - let end_tag = Token::Identifier("end".to_owned() + x); + let end_tag = Token::Identifier(format!("end{}", x)); let mut children = vec![]; let mut nesting_depth = 0; for t in iter { diff --git a/liquid-compiler/src/token.rs b/liquid-compiler/src/token.rs index 17e47572d..9c6bc0906 100644 --- a/liquid-compiler/src/token.rs +++ b/liquid-compiler/src/token.rs @@ -92,28 +92,27 @@ impl Token { impl fmt::Display for Token { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let out = match *self { - Token::Pipe => "|".to_owned(), - Token::Dot => ".".to_owned(), - Token::Colon => ":".to_owned(), - Token::Comma => ",".to_owned(), - Token::OpenSquare => "[".to_owned(), - Token::CloseSquare => "]".to_owned(), - Token::OpenRound => "(".to_owned(), - Token::CloseRound => ")".to_owned(), - Token::Question => "?".to_owned(), - Token::Dash => "-".to_owned(), - Token::DotDot => "..".to_owned(), - Token::Assignment => "=".to_owned(), - Token::Or => "or".to_owned(), - - Token::Comparison(ref x) => x.to_string(), - Token::Identifier(ref x) | Token::StringLiteral(ref x) => x.clone(), - Token::IntegerLiteral(ref x) => x.to_string(), - Token::FloatLiteral(ref x) => x.to_string(), - Token::BooleanLiteral(ref x) => x.to_string(), - }; - write!(f, "{}", out) + match *self { + Token::Pipe => write!(f, "|"), + Token::Dot => write!(f, "."), + Token::Colon => write!(f, ":"), + Token::Comma => write!(f, ","), + Token::OpenSquare => write!(f, "["), + Token::CloseSquare => write!(f, "]"), + Token::OpenRound => write!(f, "("), + Token::CloseRound => write!(f, ")"), + Token::Question => write!(f, "?"), + Token::Dash => write!(f, "-"), + Token::DotDot => write!(f, ".."), + Token::Assignment => write!(f, "="), + Token::Or => write!(f, "or"), + + Token::Comparison(ref x) => write!(f, "{}", x), + Token::Identifier(ref x) | Token::StringLiteral(ref x) => write!(f, "{}", x), + Token::IntegerLiteral(ref x) => write!(f, "{}", x), + Token::FloatLiteral(ref x) => write!(f, "{}", x), + Token::BooleanLiteral(ref x) => write!(f, "{}", x), + } } } diff --git a/liquid-interpreter/src/text.rs b/liquid-interpreter/src/text.rs index d56862c46..e5c3a603c 100644 --- a/liquid-interpreter/src/text.rs +++ b/liquid-interpreter/src/text.rs @@ -12,9 +12,9 @@ pub struct Text { impl Text { /// Create a raw template expression. - pub fn new(text: &str) -> Text { + pub fn new>(text: S) -> Text { Text { - text: text.to_owned(), + text: text.into(), } } }