static class Macro.MacroEvaluationContext extends java.lang.Object implements EvaluationContext
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.EvaluationContext.PlainEvaluationContext| Modifier and Type | Field and Description |
|---|---|
private EvaluationContext |
originalEvaluationContext |
private java.util.Map<java.lang.String,Node> |
parameterThunks |
| Constructor and Description |
|---|
MacroEvaluationContext(java.util.Map<java.lang.String,Node> parameterThunks,
EvaluationContext originalEvaluationContext) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
getVar(java.lang.String var) |
java.lang.Runnable |
setVar(java.lang.String var,
java.lang.Object value)
Sets the given variable to the given value.
|
boolean |
varIsDefined(java.lang.String var) |
private final java.util.Map<java.lang.String,Node> parameterThunks
private final EvaluationContext originalEvaluationContext
MacroEvaluationContext(java.util.Map<java.lang.String,Node> parameterThunks, EvaluationContext originalEvaluationContext)
public java.lang.Object getVar(java.lang.String var)
getVar in interface EvaluationContextpublic boolean varIsDefined(java.lang.String var)
varIsDefined in interface EvaluationContextpublic java.lang.Runnable setVar(java.lang.String var,
java.lang.Object value)
EvaluationContextsetVar in interface EvaluationContext$x after #foreach ($x in ...).