#macro (m $x $y) ... #end
and each one produces an instance of this class. Evaluating a macro involves setting the
parameters (here {$x $y)} and evaluating the macro body. Macro arguments are call-by-name, which
means that we need to set each parameter variable to the node in the parse tree that corresponds
to it, and arrange for that node to be evaluated when the variable is actually referenced.
There are two ways to invoke a macro. #m('foo', 'bar') sets $x and $y. #@m('foo', 'bar') ... #end sets $x and $y, and also sets $bodyContent to the template text
....
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | Macro.MacroEvaluationContext
The context for evaluation within macros. |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final Node | |
| private final String | |
| private final ImmutableList |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int | |
| pack-priv void | render(EvaluationContext context, List<ExpressionNode> thunks, Node bodyContent, StringBuilder output)
Renders a call to this macro with the arguments in |
| definitionLineNumber | back to summary |
|---|---|
| private final int definitionLineNumber | |
| macroBody | back to summary |
|---|---|
| private final Node macroBody | |
| name | back to summary |
|---|---|
| private final String name | |
| parameterNames | back to summary |
|---|---|
| private final ImmutableList<String> parameterNames | |
| Macro | back to summary |
|---|---|
| pack-priv Macro(int definitionLineNumber, String name, List<String> parameterNames, Node macroBody) | |
| parameterCount | back to summary |
|---|---|
| pack-priv int parameterCount() | |
| render | back to summary |
|---|---|
| pack-priv void render(EvaluationContext context, List<ExpressionNode> thunks, Node bodyContent, StringBuilder output) Renders a call to this macro with the arguments in | |
EvaluationContext
but intercepts reads of the macro's parameters so that they result in a call-by-name evaluation
of whatever was passed as the parameter. For example, if you write...
#macro (mymacro $x)
$x $x
#end
#mymacro($foo.bar(23))
...then the #mymacro call will result in $foo.bar(23) being evaluated twice,
once for each time $x appears. The way this works is that $x is a thunk.
Historically a thunk is a piece of code to evaluate an expression in the context where it
occurs, for call-by-name procedures as in Algol 60. Here, it is not exactly a piece of code,
but it has the same responsibility.
| Modifier and Type | Field and Description |
|---|---|
| private final Node | |
| private final EvaluationContext | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| pack-priv | MacroEvaluationContext(Map<String, ExpressionNode> parameterThunks, EvaluationContext originalEvaluationContext, Node bodyContent)
|
| Modifier and Type | Method and Description |
|---|---|
| public Map | getMacros()
Implements com. |
| public Object | |
| public ImmutableSet | publicMethodsWithName(Class<?> startClass, String name)
Implements com. MethodFinder#publicMethodsWithName.
|
| public Runnable | setVar(final String var, Object value)
Implements com. |
| public boolean |
| bodyContent | back to summary |
|---|---|
| private final Node bodyContent | |
| originalEvaluationContext | back to summary |
|---|---|
| private final EvaluationContext originalEvaluationContext | |
| parameterThunks | back to summary |
|---|---|
| private final Map<String, ExpressionNode> parameterThunks | |
| MacroEvaluationContext | back to summary |
|---|---|
| pack-priv MacroEvaluationContext(Map<String, ExpressionNode> parameterThunks, EvaluationContext originalEvaluationContext, Node bodyContent) | |
| getMacros | back to summary |
|---|---|
| public Map Implements com. Doc from com. Returns a modifiable mapping from macro names to macros. Initially this map starts off with the
macros that were defined in the root template. As
| |
| getVar | back to summary |
|---|---|
| public Object getVar(String var) Implements com.
| |
| publicMethodsWithName | back to summary |
|---|---|
| public ImmutableSet Implements com. Doc from com. See
| |
| setVar | back to summary |
|---|---|
| public Runnable setVar(final String var, Object value) Implements com. Doc from com. Sets the given variable to the given value. | |
| varIsDefined | back to summary |
|---|---|
| public boolean varIsDefined(String var) Implements com.
| |