MacroParser
Overview
The MacroParser class is an expression parser class that provides functionality needed to replace expression variables with their values.
This class is an important part of the Macro Processor conception and is a base class for the SqlMacroProcessor class.
This ConsoleApplication example shows how the MacroParser can be used to parse an expression:
static void Main(String[] args)
{
String lMacro = "{var1} should be equal to {Now()}";
var lMacroParser = new RemObjects.DataAbstract.Server.MacroParser();
// register 'Now' function
lMacroParser.RegisterProc("Now", delegate { return DateTime.Now.ToShortTimeString(); }, 0);
// register a variable
lMacroParser.AddVariable("var1").Value = DateTime.Now.ToLongTimeString();
// evaluate macro
Console.WriteLine(lMacroParser.Eval(lMacro, '\`));
}
Output: 15:47:36 should be equal to 15:47
Location
- Reference: RemObjects.DataAbstract.Server.dll
- Namespace: RemObjects.DataAbstract.Server
constructor
Creates a new instance of the MacroParser class.
constructor
MacroParser()
Sub New()
AddVariable
Creates a new macro variable and adds it to the internal macro variables list.
method AddVariable(aName: String): MacroVariable
MacroVariable AddVariable(String aName)
Function AddVariable(aName As String) As MacroVariable
Parameters:
- aName:
ClearMacros
method ClearMacros
void ClearMacros()
Sub ClearMacros()
ClearVariables
Clears the internal list of registered macro variables.
method ClearVariables
void ClearVariables()
Sub ClearVariables()
CustomMacroHandler
property CustomMacroHandler: CustomMacroCallback read write;
CustomMacroCallback CustomMacroHandler { get; set; }
Property CustomMacroHandler() As CustomMacroCallback
Eval
Evaluates the given expression, substituting macro tags with specific variable values or macro function results.
String constants within provided expressions can be delimited using the TextDelimiter char.
method Eval(Text: String; TextDelimiter: Char): String
String Eval(String Text, Char TextDelimiter)
Function Eval(Text As String, TextDelimiter As Char) As String
Parameters:
- Text: Expression to process
- TextDelimiter: String constants delimiter
EvalToken
Evaluates the provided macro token. This method calls the macro function or replaces the macro variable placeholder with its value.
method EvalToken(Text: String): String
String EvalToken(String Text)
Function EvalToken(Text As String) As String
Parameters:
- Text: Macro expression token
FindVariable
Gets the macro variable with the specified name from the registered variables. Search is not case-sensitive.
If there is no variable with the provided name, null is returned.
method FindVariable(aName: String): MacroVariable
MacroVariable FindVariable(String aName)
Function FindVariable(aName As String) As MacroVariable
Parameters:
- aName: Variable name
RegisterMacro
method RegisterMacro(name: String; callback: Func<array of String, String>; paramCount: Int32)
void RegisterMacro(String name, Func<array of String, String> callback, Int32 paramCount)
Sub RegisterMacro(name As String, callback As Func<array of String, String>, paramCount As Int32)
Parameters:
- name:
- callback:
- paramCount:
CustomMacroHandler
property CustomMacroHandler: CustomMacroCallback read write;
CustomMacroCallback CustomMacroHandler { get; set; }
Property CustomMacroHandler() As CustomMacroCallback
constructor
Creates a new instance of the MacroParser class.
constructor
MacroParser()
Sub New()
AddVariable
Creates a new macro variable and adds it to the internal macro variables list.
method AddVariable(aName: String): MacroVariable
MacroVariable AddVariable(String aName)
Function AddVariable(aName As String) As MacroVariable
Parameters:
- aName:
ClearMacros
method ClearMacros
void ClearMacros()
Sub ClearMacros()
ClearVariables
Clears the internal list of registered macro variables.
method ClearVariables
void ClearVariables()
Sub ClearVariables()
Eval
Evaluates the given expression, substituting macro tags with specific variable values or macro function results.
String constants within provided expressions can be delimited using the TextDelimiter char.
method Eval(Text: String; TextDelimiter: Char): String
String Eval(String Text, Char TextDelimiter)
Function Eval(Text As String, TextDelimiter As Char) As String
Parameters:
- Text: Expression to process
- TextDelimiter: String constants delimiter
EvalToken
Evaluates the provided macro token. This method calls the macro function or replaces the macro variable placeholder with its value.
method EvalToken(Text: String): String
String EvalToken(String Text)
Function EvalToken(Text As String) As String
Parameters:
- Text: Macro expression token
FindVariable
Gets the macro variable with the specified name from the registered variables. Search is not case-sensitive.
If there is no variable with the provided name, null is returned.
method FindVariable(aName: String): MacroVariable
MacroVariable FindVariable(String aName)
Function FindVariable(aName As String) As MacroVariable
Parameters:
- aName: Variable name
RegisterMacro
method RegisterMacro(name: String; callback: Func<array of String, String>; paramCount: Int32)
void RegisterMacro(String name, Func<array of String, String> callback, Int32 paramCount)
Sub RegisterMacro(name As String, callback As Func<array of String, String>, paramCount As Int32)
Parameters:
- name:
- callback:
- paramCount:
-
SqlMacroProcessor
- AccessMacroProcessor
- DBISAMMacroProcessor
- DefaultSqlMacroProcessor
- ElevateDBMacroProcessor
- FirebirdMacroProcessor
- InterbaseMacroProcessor
- MSSQLMacroProcessor
- MSSQL2005MacroProcessor
- MSSQL2008MacroProcessor
- MSSQL2012MacroProcessor
- MySQLMacroProcessor
- NexusDBMacroProcessor
- OracleMacroProcessor
- PostgreSQLMacroProcessor
- SQLiteMacroProcessor
- SybaseAdvantageMacroProcessor