Skip to content

Commit

Permalink
refactor: Better highlight some allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 25, 2018
1 parent 6b96f92 commit 60b29d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions liquid-compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn parse(elements: &[Element], options: &LiquidOptions) -> Result<Vec<Box<Re
let render = match *token.unwrap() {
Element::Expression(ref tokens, _) => 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();
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 21 additions & 22 deletions liquid-compiler/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions liquid-interpreter/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub struct Text {

impl Text {
/// Create a raw template expression.
pub fn new(text: &str) -> Text {
pub fn new<S: Into<String>>(text: S) -> Text {
Text {
text: text.to_owned(),
text: text.into(),
}
}
}
Expand Down

0 comments on commit 60b29d0

Please # to comment.