diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-02-12 23:14:29 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-02-12 23:14:29 +0100 |
| commit | db1659a987cd240b78e45666617248d3d0cc7d64 (patch) | |
| tree | 90b2ed3d59e19de743f14f2677af49b522900578 | |
| parent | 094462cbdda15f19d2dc071b18201f656b8ddcd4 (diff) | |
Rename any template to func template ✏
| -rw-r--r-- | src/eval/value.rs | 21 | ||||
| -rw-r--r-- | src/exec/mod.rs | 6 | ||||
| -rw-r--r-- | src/parse/mod.rs | 2 | ||||
| -rw-r--r-- | src/parse/tokens.rs | 2 | ||||
| -rw-r--r-- | src/prelude.rs | 4 | ||||
| -rw-r--r-- | src/pretty.rs | 12 | ||||
| -rw-r--r-- | 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 e175b9ff..b731acf9 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<dyn Fn(&mut ExecContext)>, } -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<F>(name: impl Into<String>, 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 a9a44c10..cafc55cd 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 8780efaf..e9cf2a60 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<Node> { 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 e3550707..4019363c 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 1251bd29..33542ad3 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 41fd6d78..e040d3ae 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("<node "); p.push_str(self.name()); @@ -741,7 +741,7 @@ mod tests { roundtrip("{v(1)}"); roundtrip("{v(a: 1, b)}"); - // Function templates. + // Bracket functions. roundtrip("#[v]"); roundtrip("#[v 1]"); roundtrip("#[v 1, 2][*Ok*]"); @@ -800,7 +800,7 @@ mod tests { tree: Rc::new(vec![Node::Strong]), map: HashMap::new(), }, - TemplateNode::Any(TemplateAny::new("example", |_| {})), + TemplateNode::Func(TemplateFunc::new("example", |_| {})), ], "[*<node example>]", ); diff --git a/src/syntax/token.rs b/src/syntax/token.rs index 411e835f..3171c887 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", |
