- java.lang.Object
-
- javax0.jamal.engine.UserDefinedMacro
-
- All Implemented Interfaces:
Evaluable
,Identified
,UserDefinedMacro
public class UserDefinedMacro extends java.lang.Object implements UserDefinedMacro
Stores the information about a user defined macro and can also evaluate it using actual parameter string values.
-
-
Constructor Summary
Constructors Constructor Description UserDefinedMacro(Processor processor, java.lang.String id, java.lang.String content, java.lang.String... parameters)
Creates a new user defined macro.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
evaluate(java.lang.String... actualValues)
Evaluate the content of the user defined macro using the actual values for the parameter values.int
expectedNumberOfArguments()
java.lang.String
getId()
Get the name / identifier of the user defined macro.
-
-
-
Constructor Detail
-
UserDefinedMacro
public UserDefinedMacro(Processor processor, java.lang.String id, java.lang.String content, java.lang.String... parameters) throws BadSyntax
Creates a new user defined macro.- Parameters:
processor
- is the context of the evaluation. Through this object a macro can access the evaluation environment.id
- the identifier of the macro. This is the string that stands after thedefine
keyword when the user defined macro is defined. This is a unique identified in the context where the macro is reachable and usable.content
- the text of the macro that stands after the=
character and before the macro closing character.parameters
- the names of the parameters. These do not actually need to be real identifiers, alphanumeric or something like that. The only requirement is that there is no comma in these names. It is recommended though to use usual identifiers.- Throws:
BadSyntax
- is thrown if one of the parameter names contain another parameter name. This would not be safe because this way the result of the macro would be dependent on the evaluation order of the parameters.
-
-
Method Detail
-
getId
public java.lang.String getId()
Get the name / identifier of the user defined macro.- Specified by:
getId
in interfaceIdentified
- Returns:
- the id.
-
evaluate
public java.lang.String evaluate(java.lang.String... actualValues) throws BadSyntax
Evaluate the content of the user defined macro using the actual values for the parameter values.- Specified by:
evaluate
in interfaceEvaluable
- Parameters:
actualValues
- the actual string values for the parameters- Returns:
- the string that is the result of the evaluation
- Throws:
BadSyntaxAt
- if the user defined macro is a script and the script evaluation throws exception. This exception is thrown if the number of the actual values is not the same as the number of the parameters.BadSyntax
-
expectedNumberOfArguments
public int expectedNumberOfArguments()
- Specified by:
expectedNumberOfArguments
in interfaceEvaluable
-
-