From 6b96f92be169aad4d9393cb48d9ad37e856d014a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 24 Sep 2018 17:45:13 -0600 Subject: [PATCH] fix(interpreter): Clarify names One day I'll find names I like. BREAKING CHANGE: `Output` -> `FilterChain` --- liquid-compiler/src/parser.rs | 18 +++++++++--------- liquid-interpreter/src/output.rs | 24 ++++++++++++------------ src/tags/assign_tag.rs | 4 ++-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/liquid-compiler/src/parser.rs b/liquid-compiler/src/parser.rs index d53120480..083f99d2e 100644 --- a/liquid-compiler/src/parser.rs +++ b/liquid-compiler/src/parser.rs @@ -10,7 +10,7 @@ use std::slice::Iter; use liquid_interpreter::Renderable; use liquid_interpreter::Text; use liquid_interpreter::Variable; -use liquid_interpreter::{FilterPrototype, Output}; +use liquid_interpreter::{FilterCall, FilterChain}; use liquid_value::Index; use super::error::{Error, Result}; @@ -117,10 +117,10 @@ pub fn parse_indexes(mut tokens: &[Token]) -> Result> { Ok(indexes) } -/// Creates an Output, a wrapper around values, variables and filters +/// Creates an FilterChain, a wrapper around values, variables and filters /// used internally, from a list of Tokens. This is mostly useful /// for correctly parsing complex expressions with filters. -pub fn parse_output(tokens: &[Token]) -> Result { +pub fn parse_output(tokens: &[Token]) -> Result { let entry = tokens[0].to_arg()?; let mut filters = vec![]; @@ -140,7 +140,7 @@ pub fn parse_output(tokens: &[Token]) -> Result { match iter.peek() { Some(&&Token::Pipe) | None => { - filters.push(FilterPrototype::new(name, args)); + filters.push(FilterCall::new(name, args)); continue; } _ => (), @@ -168,10 +168,10 @@ pub fn parse_output(tokens: &[Token]) -> Result { } } - filters.push(FilterPrototype::new(name, args)); + filters.push(FilterCall::new(name, args)); } - Ok(Output::new(entry, filters)) + Ok(FilterChain::new(entry, filters)) } // a tag can be either a single-element tag or a block, which can contain other @@ -338,10 +338,10 @@ mod test_parse_output { let result = parse_output(&tokens); assert_eq!( result.unwrap(), - Output::new( + FilterChain::new( Argument::Var(Variable::new("abc")), vec![ - FilterPrototype::new( + FilterCall::new( "def", vec![ Argument::Val(Value::scalar("1")), @@ -349,7 +349,7 @@ mod test_parse_output { Argument::Val(Value::scalar("3")), ], ), - FilterPrototype::new("blabla", vec![]), + FilterCall::new("blabla", vec![]), ] ) ); diff --git a/liquid-interpreter/src/output.rs b/liquid-interpreter/src/output.rs index d7e2fe094..215d9d2cb 100644 --- a/liquid-interpreter/src/output.rs +++ b/liquid-interpreter/src/output.rs @@ -12,22 +12,22 @@ use super::Renderable; /// A `Value` filter. #[derive(Clone, Debug, PartialEq)] -pub struct FilterPrototype { +pub struct FilterCall { name: String, arguments: Vec, } -impl FilterPrototype { +impl FilterCall { /// Create filter expression. - pub fn new(name: &str, arguments: Vec) -> FilterPrototype { - FilterPrototype { + pub fn new(name: &str, arguments: Vec) -> FilterCall { + FilterCall { name: name.to_owned(), arguments, } } } -impl fmt::Display for FilterPrototype { +impl fmt::Display for FilterCall { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -40,15 +40,15 @@ impl fmt::Display for FilterPrototype { /// A `Value` expression. #[derive(Clone, Debug, PartialEq)] -pub struct Output { +pub struct FilterChain { entry: Argument, - filters: Vec, + filters: Vec, } -impl Output { +impl FilterChain { /// Create a new expression. - pub fn new(entry: Argument, filters: Vec) -> Output { - Output { entry, filters } + pub fn new(entry: Argument, filters: Vec) -> Self { + Self { entry, filters } } /// Process `Value` expression within `context`'s stack. @@ -79,7 +79,7 @@ impl Output { } } -impl fmt::Display for Output { +impl fmt::Display for FilterChain { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -90,7 +90,7 @@ impl fmt::Display for Output { } } -impl Renderable for Output { +impl Renderable for FilterChain { fn render_to(&self, writer: &mut Write, context: &mut Context) -> Result<()> { let entry = self.evaluate(context)?; write!(writer, "{}", entry).chain("Failed to render")?; diff --git a/src/tags/assign_tag.rs b/src/tags/assign_tag.rs index acfb8fe07..8e0d64931 100644 --- a/src/tags/assign_tag.rs +++ b/src/tags/assign_tag.rs @@ -7,13 +7,13 @@ use compiler::LiquidOptions; use compiler::Token; use compiler::{expect, parse_output, unexpected_token_error}; use interpreter::Context; -use interpreter::Output; +use interpreter::FilterChain; use interpreter::Renderable; #[derive(Clone, Debug)] struct Assign { dst: String, - src: Output, + src: FilterChain, } impl Assign {