Skip to content

Commit

Permalink
fix(interpreter): Clarify names
Browse files Browse the repository at this point in the history
One day I'll find names I like.

BREAKING CHANGE: `Output` -> `FilterChain`
  • Loading branch information
epage committed Sep 24, 2018
1 parent 3b12c53 commit 6b96f92
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions liquid-compiler/src/parser.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -117,10 +117,10 @@ pub fn parse_indexes(mut tokens: &[Token]) -> Result<Vec<Index>> {
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<Output> {
pub fn parse_output(tokens: &[Token]) -> Result<FilterChain> {
let entry = tokens[0].to_arg()?;

let mut filters = vec![];
Expand All @@ -140,7 +140,7 @@ pub fn parse_output(tokens: &[Token]) -> Result<Output> {

match iter.peek() {
Some(&&Token::Pipe) | None => {
filters.push(FilterPrototype::new(name, args));
filters.push(FilterCall::new(name, args));
continue;
}
_ => (),
Expand Down Expand Up @@ -168,10 +168,10 @@ pub fn parse_output(tokens: &[Token]) -> Result<Output> {
}
}

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
Expand Down Expand Up @@ -338,18 +338,18 @@ 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")),
Argument::Val(Value::scalar(2.0)),
Argument::Val(Value::scalar("3")),
],
),
FilterPrototype::new("blabla", vec![]),
FilterCall::new("blabla", vec![]),
]
)
);
Expand Down
24 changes: 12 additions & 12 deletions liquid-interpreter/src/output.rs
Expand Up @@ -12,22 +12,22 @@ use super::Renderable;

/// A `Value` filter.
#[derive(Clone, Debug, PartialEq)]
pub struct FilterPrototype {
pub struct FilterCall {
name: String,
arguments: Vec<Argument>,
}

impl FilterPrototype {
impl FilterCall {
/// Create filter expression.
pub fn new(name: &str, arguments: Vec<Argument>) -> FilterPrototype {
FilterPrototype {
pub fn new(name: &str, arguments: Vec<Argument>) -> 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,
Expand All @@ -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<FilterPrototype>,
filters: Vec<FilterCall>,
}

impl Output {
impl FilterChain {
/// Create a new expression.
pub fn new(entry: Argument, filters: Vec<FilterPrototype>) -> Output {
Output { entry, filters }
pub fn new(entry: Argument, filters: Vec<FilterCall>) -> Self {
Self { entry, filters }
}

/// Process `Value` expression within `context`'s stack.
Expand Down Expand Up @@ -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,
Expand All @@ -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")?;
Expand Down
4 changes: 2 additions & 2 deletions src/tags/assign_tag.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 6b96f92

Please sign in to comment.