Class MacroExpression
- Namespace
- CMS.MacroEngine
- Assembly
- CMS.MacroEngine.dll
Macro expression - represents a syntactic tree of the macro expression.
public class MacroExpression
- Inheritance
-
objectMacroExpression
- Extension Methods
Constructors
MacroExpression(List<MacroElement>)
Constructor.
protected MacroExpression(List<MacroElement> elements)
Parameters
elementsList<MacroElement>Elements of the source expression
MacroExpression(List<MacroElement>, int, int)
Constructor.
protected MacroExpression(List<MacroElement> elements, int startIndex, int endIndex)
Parameters
elementsList<MacroElement>Elements of the source expression
startIndexintIndex of the first item of this expression
endIndexintIndex of the last item of this expression
Fields
mChildren
Children expressions (parameters of method or subexpression).
protected List<MacroExpression> mChildren
Field Value
- List<MacroExpression>
mParameters
Parameters for the given expression (backward compatibility).
protected List<MacroExpression> mParameters
Field Value
- List<MacroExpression>
mPriority
Priority of the method.
protected int mPriority
Field Value
- int
mSyntacticTreeTable
Hash table with cached parsed expressions to speedup the macro evaluation.
protected static SafeDictionary<string, MacroExpression> mSyntacticTreeTable
Field Value
- SafeDictionary<string, MacroExpression>
Properties
Children
Child expressions of the expression.
public List<MacroExpression> Children { get; }
Property Value
- List<MacroExpression>
EndIndex
Ending index of the expression in the source.
protected int EndIndex { get; set; }
Property Value
- int
Name
Name of the data member or method call.
public string Name { get; protected set; }
Property Value
- string
Next
Next expression to evaluate.
protected MacroExpression Next { get; set; }
Property Value
Parameters
Parameters for the given expression; i.e. |(paramname)value expressions.
public List<MacroExpression> Parameters { get; }
Property Value
- List<MacroExpression>
Parent
Parent expression.
public MacroExpression Parent { get; set; }
Property Value
Previous
Previous expression (the expression from which this expression is the next).
protected MacroExpression Previous { get; set; }
Property Value
Priority
Gets the element priority.
protected int Priority { get; }
Property Value
- int
SourceElements
Elements from the source expression.
protected List<MacroElement> SourceElements { get; set; }
Property Value
- List<MacroElement>
StartIndex
Starting index of the expression in the source.
protected int StartIndex { get; set; }
Property Value
- int
Type
Returns the expression type.
public ExpressionType Type { get; protected set; }
Property Value
Value
Value of the value expression (is null for expression types like method, property, etc.).
public object Value { get; protected set; }
Property Value
- object
Methods
CheckSyntax(string)
Checks the syntactic tree of parsed expression if everything is OK and ready for correct evaluation.
protected void CheckSyntax(string originalExpression)
Parameters
originalExpressionstringExpression which was parsed
ExtractParameter(string, string, int)
Extracts specified parameter of Rule expression.
public static MacroExpression ExtractParameter(string expression, string methodName, int parameter)
Parameters
expressionstringExpression with rule method
methodNamestringName of the method to extract parameter of
parameterintIndex of the parameter
Returns
GetElement(int)
Gets the element on specific index of this expression.
protected MacroElement GetElement(int index)
Parameters
indexintIndex to get, starting with 0
Returns
GetInfixMethodCall(bool)
Returns string representation of the method in format MyMethod(First, Second, Third).
protected string GetInfixMethodCall(bool debugMode)
Parameters
debugModeboolDebug mode
Returns
- string
GetPrefixMethodCall(bool)
Returns string representation of the method in format First.MyMethod(Second, Third).
protected string GetPrefixMethodCall(bool debugMode)
Parameters
debugModeboolDebug mode
Returns
- string
GetPriority(string)
Gets the priority of the evaluation for the given method.
protected int GetPriority(string methodName)
Parameters
methodNamestringMethod name
Returns
- int
GetRoot()
Gets the root of the expression.
protected MacroExpression GetRoot()
Returns
HasNumberOfChildren(int)
Returns true if the current expression node has exactly specified number of children.
protected bool HasNumberOfChildren(int number)
Parameters
numberintNumber of children
Returns
- bool
InitMethodOnResult(bool)
Transfers the current result to a first child (for the parameter of method).
protected void InitMethodOnResult(bool isCalledOnResult)
Parameters
isCalledOnResultboolIf true, method is called on data member (i.e. x.method() or postfix operator such as ++), otherwise the call is infix (i.e. method(x) or infix operator such as +)
InitPropertyOnDataMember()
Transfers the current result to a first child.
protected void InitPropertyOnDataMember()
IsFlatOperator(string)
Returns true for operators which can be made flat - without subexpressions (||, &&, +, etc.)
protected bool IsFlatOperator(string op)
Parameters
opstringOperator to check
Returns
- bool
IsMethodWithName(string)
Returns true if the type of current expression is MethodCall with specified name.
protected bool IsMethodWithName(string name)
Parameters
namestringName of the method
Returns
- bool
IsSpecialCommand(string)
Returns true for special commands such as break or continue, otherwise false.
protected bool IsSpecialCommand(string name)
Parameters
namestringName of the command
Returns
- bool
MakeChildOfPrevious()
Makes current element child of the previous element if exists.
protected void MakeChildOfPrevious()
MakeFlatter()
Modifies the syntactic tree of the expression to the flat structure. Changes expressions like "(a || b) || c" to "a || b || c", etc.
public void MakeFlatter()
Parse(int, bool)
Parses the expression.
protected void Parse(int startIndex, bool supressError)
Parameters
startIndexintStarting index for the parsing (within the expression, starts with 0)
supressErrorboolIf true no exceptions are thrown
ParseAll(bool)
Parses the whole expression tree.
protected MacroExpression ParseAll(bool supressError)
Parameters
supressErrorboolIf true no exceptions are thrown
Returns
ParseExpression(string, bool)
Returns the root of parsed expression. Uses cache of the parsed expressions to speedup the process.
public static MacroExpression ParseExpression(string expression, bool supressError = false)
Parameters
expressionstringExpression string to parse
supressErrorboolIf true no exceptions are thrown
Returns
Exceptions
- SyntacticAnalysisException
Syntax error if
supressErroris false- LexicalAnalysisException
Lexical analysis error if
supressErroris false
ParseParameters(ref int, ElementType, ElementType)
Parses the method or indexer parameters.
protected void ParseParameters(ref int index, ElementType openParenthesis, ElementType closeParenthesis)
Parameters
indexintIndex in the expression, adjusted to after the end element
openParenthesisElementTypeOpening parenthesis for these parameters
closeParenthesisElementTypeClosing parenthesis for these parameters
ReplaceChild(MacroExpression, MacroExpression)
Replaces the given child expression with the given one.
protected void ReplaceChild(MacroExpression oldExp, MacroExpression newExp)
Parameters
oldExpMacroExpressionOld child expression
newExpMacroExpressionNew child expression
SyntaxError(int, bool)
Aborts the parsing of the expression due to a syntactic error
protected void SyntaxError(int lexemIndex, bool supressError = false)
Parameters
lexemIndexintPosition within the lexeme list
supressErrorboolIf true no exceptions are thrown
Exceptions
- SyntacticAnalysisException
Syntax error if
supressErroris false
ToString()
Returns string representation of this MacroExpression.
public override string ToString()
Returns
- string
ToString(bool)
Returns string representation of this MacroExpression.
public string ToString(bool debugMode)
Parameters
debugModeboolIf true, debug mode is on
Returns
- string
ToStringBlock(bool)
Handles block of code: { [some code] }
protected string ToStringBlock(bool debugMode)
Parameters
debugModeboolDetermines whether the string representation is made for debug purposes
Returns
- string
ToStringCommand(bool)
Handles special commands like return, break, etc.
protected string ToStringCommand(bool debugMode)
Parameters
debugModeboolDetermines whether the string representation is made for debug purposes
Returns
- string
ToStringConstant()
Handles constants (string literal, numbers, booleans, etc.).
protected string ToStringConstant()
Returns
- string
ToStringControlFlowStatements(bool)
Handles structures like [commandname] { [some code] }
protected string ToStringControlFlowStatements(bool debugMode)
Parameters
debugModeboolDetermines whether the string representation is made for debug purposes
Returns
- string
ToStringIndexer(bool)
Handles indexer expressions.
protected string ToStringIndexer(bool debugMode)
Parameters
debugModeboolDetermines whether the string representation is made for debug purposes
Returns
- string
ToStringMethod(bool)
Handles classic method calls.
protected string ToStringMethod(bool debugMode)
Parameters
debugModeboolDetermines whether the string representation is made for debug purposes
Returns
- string
ToStringProperty(bool)
Handles properties.
protected string ToStringProperty(bool debugMode)
Parameters
debugModeboolDetermines whether the string representation is made for debug purposes
Returns
- string