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


 

constructor

Creates a new instance of the MacroParser class.

 

constructor

 

MacroParser()

 

Sub New()

AddVariable

 

method AddVariable(name: String): MacroVariable

 

MacroVariable AddVariable(String name)

 

Function AddVariable(name As String) As MacroVariable

Parameters:

  • name:

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

Creates a new macro variable and adds it to the internal macro variables list.

 

method Eval(source: String; delimiter: Char): String

 

String Eval(String source, Char delimiter)

 

Function Eval(source As String, delimiter As Char) As String

Parameters:

  • source: Expression to process
  • delimiter: String constants delimiter

EvalToken

Creates a new macro variable and adds it to the internal macro variables list.

 

method EvalToken(source: String): String

 

String EvalToken(String source)

 

Function EvalToken(source As String) As String

Parameters:

  • source: Variable name

FindVariable

 

method FindVariable(name: String): MacroVariable

 

MacroVariable FindVariable(String name)

 

Function FindVariable(name As String) As MacroVariable

Parameters:

  • 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 (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

 

method AddVariable(name: String): MacroVariable

 

MacroVariable AddVariable(String name)

 

Function AddVariable(name As String) As MacroVariable

Parameters:

  • name:

ClearMacros

 

method ClearMacros

 

void ClearMacros()

 

Sub ClearMacros()

ClearVariables

Clears the internal list of registered macro variables.

 

method ClearVariables

 

void ClearVariables()

 

Sub ClearVariables()

Eval

Creates a new macro variable and adds it to the internal macro variables list.

 

method Eval(source: String; delimiter: Char): String

 

String Eval(String source, Char delimiter)

 

Function Eval(source As String, delimiter As Char) As String

Parameters:

  • source: Expression to process
  • delimiter: String constants delimiter

EvalToken

Creates a new macro variable and adds it to the internal macro variables list.

 

method EvalToken(source: String): String

 

String EvalToken(String source)

 

Function EvalToken(source As String) As String

Parameters:

  • source: Variable name

FindVariable

 

method FindVariable(name: String): MacroVariable

 

MacroVariable FindVariable(String name)

 

Function FindVariable(name As String) As MacroVariable

Parameters:

  • 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 (Of String(), String), paramCount As Int32)

Parameters:

  • name:
  • callback:
  • paramCount: