From db1659a987cd240b78e45666617248d3d0cc7d64 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 12 Feb 2021 23:14:29 +0100 Subject: [PATCH] =?UTF-8?q?Rename=20any=20template=20to=20func=20template?= =?UTF-8?q?=20=E2=9C=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/value.rs | 21 +++++++++++---------- src/exec/mod.rs | 6 +++--- src/parse/mod.rs | 2 +- src/parse/tokens.rs | 2 +- src/prelude.rs | 4 ++-- src/pretty.rs | 12 ++++++------ src/syntax/token.rs | 2 +- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/eval/value.rs b/src/eval/value.rs index e175b9ffc..b731acf95 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -55,7 +55,7 @@ impl Value { where F: Fn(&mut ExecContext) + 'static, { - Self::Template(vec![TemplateNode::Any(TemplateAny::new(name, f))]) + Self::Template(vec![TemplateNode::Func(TemplateFunc::new(name, f))]) } /// The name of the stored value's type. @@ -121,19 +121,20 @@ pub enum TemplateNode { }, /// A template that was converted from a string. Str(String), - /// A template that can implement custom behaviour. - Any(TemplateAny), + /// A function template that can implement custom behaviour. + Func(TemplateFunc), } -/// A reference-counted dynamic template node (can implement custom behaviour). +/// A reference-counted dynamic template node that can implement custom +/// behaviour. #[derive(Clone)] -pub struct TemplateAny { +pub struct TemplateFunc { name: String, f: Rc, } -impl TemplateAny { - /// Create a new dynamic template value from a rust function or closure. +impl TemplateFunc { + /// Create a new function template from a rust function or closure. pub fn new(name: impl Into, f: F) -> Self where F: Fn(&mut ExecContext) + 'static, @@ -147,14 +148,14 @@ impl TemplateAny { } } -impl PartialEq for TemplateAny { +impl PartialEq for TemplateFunc { fn eq(&self, _: &Self) -> bool { // TODO: Figure out what we want here. false } } -impl Deref for TemplateAny { +impl Deref for TemplateFunc { type Target = dyn Fn(&mut ExecContext); fn deref(&self) -> &Self::Target { @@ -162,7 +163,7 @@ impl Deref for TemplateAny { } } -impl Debug for TemplateAny { +impl Debug for TemplateFunc { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct("TemplateAny").finish() } diff --git a/src/exec/mod.rs b/src/exec/mod.rs index a9a44c109..cafc55cdb 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -10,7 +10,7 @@ use std::rc::Rc; use crate::diag::Pass; use crate::env::Env; -use crate::eval::{ExprMap, TemplateAny, TemplateNode, Value, ValueTemplate}; +use crate::eval::{ExprMap, TemplateFunc, TemplateNode, Value, ValueTemplate}; use crate::geom::Spec; use crate::layout::{self, Expansion, NodeSpacing, NodeStack}; use crate::pretty::pretty; @@ -156,12 +156,12 @@ impl Exec for TemplateNode { match self { Self::Tree { tree, map } => tree.exec_with_map(ctx, &map), Self::Str(s) => ctx.push_text(s), - Self::Any(any) => any.exec(ctx), + Self::Func(func) => func.exec(ctx), } } } -impl Exec for TemplateAny { +impl Exec for TemplateFunc { fn exec(&self, ctx: &mut ExecContext) { self(ctx); } diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 8780efafa..e9cf2a609 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -100,7 +100,7 @@ fn node(p: &mut Parser, at_start: &mut bool) -> Option { return Some(Node::Expr(template(p))); } - // Function template. + // Bracket function. Token::HashBracket => { *at_start = false; return Some(Node::Expr(bracket_call(p)?)); diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs index e3550707d..4019363c2 100644 --- a/src/parse/tokens.rs +++ b/src/parse/tokens.rs @@ -73,7 +73,7 @@ impl<'s> Iterator for Tokens<'s> { '{' => Token::LeftBrace, '}' => Token::RightBrace, - // Keywords, function templates, colors. + // Keywords, bracket functions, colors. '#' => self.hash(start), // Whitespace. diff --git a/src/prelude.rs b/src/prelude.rs index 1251bd29a..33542ad34 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -3,8 +3,8 @@ pub use crate::diag::{Diag, Pass}; #[doc(no_inline)] pub use crate::eval::{ - CastResult, Eval, EvalContext, TemplateAny, TemplateNode, Value, ValueAny, ValueArgs, - ValueArray, ValueDict, ValueTemplate, + CastResult, Eval, EvalContext, TemplateFunc, TemplateNode, Value, ValueAny, + ValueArgs, ValueArray, ValueDict, ValueTemplate, }; #[doc(no_inline)] pub use crate::exec::{Exec, ExecContext}; diff --git a/src/pretty.rs b/src/pretty.rs index 41fd6d78e..e040d3ae8 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -128,7 +128,7 @@ impl PrettyWithMap for Node { let value = &map[&(expr as *const _)]; value.pretty(p); } else if let Expr::Call(call) = expr { - // Format function templates appropriately. + // Format bracket functions appropriately. pretty_bracketed(call, p, false) } else { expr.pretty(p); @@ -360,7 +360,7 @@ impl Pretty for ExprCall { } } -/// Pretty print a function template, with body or chaining when possible. +/// Pretty print a bracket function, with body or chaining when possible. pub fn pretty_bracketed(call: &ExprCall, p: &mut Printer, chained: bool) { if chained { p.push_str(" | "); @@ -539,12 +539,12 @@ impl Pretty for TemplateNode { match self { Self::Tree { tree, map } => tree.pretty_with_map(p, Some(map)), Self::Str(s) => p.push_str(s), - Self::Any(any) => any.pretty(p), + Self::Func(func) => func.pretty(p), } } } -impl Pretty for TemplateAny { +impl Pretty for TemplateFunc { fn pretty(&self, p: &mut Printer) { p.push_str("]", ); diff --git a/src/syntax/token.rs b/src/syntax/token.rs index 411e835fe..3171c8877 100644 --- a/src/syntax/token.rs +++ b/src/syntax/token.rs @@ -191,7 +191,7 @@ impl<'s> Token<'s> { pub fn name(self) -> &'static str { match self { Self::LeftBracket => "opening bracket", - Self::HashBracket => "start of function template", + Self::HashBracket => "start of bracket function", Self::RightBracket => "closing bracket", Self::LeftBrace => "opening brace", Self::RightBrace => "closing brace",