Description of ExpressionManager (1) Does safe evaluation of PHP expressions. Only registered Functions, and known Variables are allowed.
(a) Functions include any math, string processing, conditional, formatting, etc. functions (2) This class replaces LimeSurvey's <= 1.91+ process of resolving strings that contain LimeReplacementFields (a) String is split by expressions (by curly braces, but safely supporting strings and escaped curly braces) (b) Expressions (things surrounded by curly braces) are evaluated - thereby doing LimeReplacementField substitution and/or more complex calculations (c) Non-expressions are left intact (d) The array of stringParts are re-joined to create the desired final string. (3) The core of ExpressionScript Engine is a Recursive Descent Parser (RDP), based off of one build via JavaCC by TMSWhite in 1999. (a) Functions that start with RDP_ should not be touched unless you really understand compiler design.
author | LimeSurvey Team (limesurvey.org) |
---|---|
author | Thomas M. White (TMSWhite) |
package | Default |
__construct()
addPackageForExpressionManager(string $name,array $definition): void
string
of package
addRegexpExtraAttributes(array<mixed,string> $extraAttributes,boolean $static = true): void
array<mixed,string>
boolean
is a static attribute , unused currently since there are no way to create the EM js system
asSplitStringOnExpressions(string $src): array
This version properly handles nested curly braces and curly braces within strings within curly braces - both of which are needed to better support JavaScript Users still need to add a space or carriage return after opening braces (and ideally before closing braces too) to avoid having them treated as expressions.
string
array
ClearSubstitutionInfo()
When re-displaying same page, need to avoid generating double the amount of tailoring content.
ExpandThisVar(string $src): string
string
string
ExpressionManagerStartEvent(): void
flatten_array(array $a): array
array
array
GetAllJsVarsUsed(): array
array
GetAllowableFunctions(): string
string
GetAllVarsUsed(): array
array
GetCurrentSubstitutionInfo(): array
array
GetErrors(): array
array
GetJavaScriptEquivalentOfExpression(): string
string
the JavaScript expresssion
GetJavaScriptFunctionForReplacement(integer $questionNum,string $elementId,string $eqn): string
integer
No longer used
string
string
No longer used
string
: javascript part
GetJavascriptTestforExpression(string $expected,integer $num): string
string
integer
string
GetJsVarFor(string $name): string
string
string
GetJsVarsUsed(): array
array
GetLastPrettyPrintExpression()
getMismatchInformation(\Token $arg1,\Token $arg2): array<mixed,boolean>
GetOnPageJsVarsUsed(): array
array
GetPrettyPrintString(): string
string
HTML
getRegexpStaticValidAttributes()
getRegexpValidAttributes()
GetResult(): mixed
mixed
GetVarAttribute(string $name,string|null $attr,string $default): string
string
string|null
string
string
GetVarsUsed(): array
array
GetWarnings(): array
array
gT(string $string,string $sEscapeMode = 'html'): string
string
to translate
string
Valid values are html (this is the default, js and unescaped)
string
: translated string
HasErrors(): boolean
boolean
HasSyntaxErrors(): boolean
boolean
ProcessBooleanExpression(string $expr,integer $groupSeq = -1,integer $questionSeq = -1): boolean
string
integer
integer
boolean
RDP_AddError(string $errMsg,array|null $token): void
string
array|null
RDP_AddWarning(\EMWarningInterface $warning): void
RDP_Evaluate(string $expr,boolean $onlyparse = false,boolean $resetErrorsAndWarnings = true): boolean
string
boolean
boolean
boolean
RDP_EvaluateAdditiveExpression(): boolean
boolean
RDP_EvaluateBinary(array $token): boolean
array
boolean
RDP_EvaluateConstantVarOrFunction(): boolean|null
boolean|null
RDP_EvaluateEqualityExpression(): boolean
boolean
RDP_EvaluateExpression(): boolean
boolean
RDP_EvaluateExpressions(): boolean
boolean
RDP_EvaluateFunction(): boolean|null
boolean|null
RDP_EvaluateLogicalAndExpression(): boolean
boolean
RDP_EvaluateLogicalOrExpression(): boolean
boolean
RDP_EvaluateMultiplicativeExpression(): boolean
boolean
RDP_EvaluatePrimaryExpression(): boolean|null
boolean|null
RDP_EvaluateRelationExpression(): boolean
boolean
RDP_EvaluateUnary(array $token): boolean
array
boolean
RDP_EvaluateUnaryExpression(): boolean|null
boolean|null
RDP_GetErrors(): array
array
RDP_isValidFunction(string $name): boolean
string
boolean
RDP_isValidVariable(string $name): boolean
string
boolean
RDP_isWritableVariable(string $name): boolean
string
boolean
RDP_RunFunction(array $funcNameToken,array $params): boolean|null
array
array
boolean|null
RDP_SetVariableValue(string $op,string $name,string $value): integer
string
string
string
integer
RDP_StackPop(): \token
\token
RDP_StackPush(array $token)
array
RDP_Tokenize(string $sSource,boolean $bOnEdit = false): array
string
: the string to tokenize
boolean
: on edition, actually don't remove space
array
RegisterFunctions(array $functions)
$functions is an array of key to value mappings like this: See $this->RDP_ValidFunctions for examples of the syntax
array
ResetErrors(): void
see | \Related issue #16738: https://bugs.limesurvey.org/view.php?id=16738 |
---|---|
link | ProcessBooleanExpression didn't reset RDP_errors anb RDP_warnings, need a way to reset for Survey logic checking |
ResetErrorsAndWarnings(): void
ResetWarnings(): void
see | \Related issue #15547: Invalid error count on Survey Logic file for subquestion relevance |
---|---|
link | ProcessBooleanExpression didn't reset RDP_errors anb RDP_warnings, need a way to reset for Survey logic checking |
SetJsVarsUsed( $vars): void
SetPrettyPrintSource(string $expr)
string
SetSurveyMode(string $mode)
string
ShowAllowableFunctions(): string
string
sProcessStringContainingExpressions(string $src,integer $questionNum,integer $numRecursionLevels = 1,integer $whichPrettyPrintIteration = 1,integer $groupSeq = -1,integer $questionSeq = -1,boolean $staticReplacement = false): string
string
integer
integer
integer
integer
integer
boolean
string
sProcessStringContainingExpressionsHelper(string $src,integer $questionNum,boolean $staticReplacement = false): string
string
integer
boolean
string
StartProcessingGroup( $sid = null, $rooturl = '', $hyperlinkSyntaxHighlighting = true)
Tokenize(string $sSource,boolean $bOnEdit): array
string
: the string to tokenize
boolean
: on edition, actually don't remove space
array
aRDP_regexpVariableAttribute :
aRDP_regexpStaticAttribute :
RDP_ExpressionRegex :
RDP_TokenType :
RDP_TokenizerRegex :
RDP_CategorizeTokensRegex :
RDP_ValidFunctions :
RDP_expr :
RDP_tokens :
RDP_count :
RDP_pos :
RDP_errs :array<mixed,array>
var | information about current errors : array with string, $token (EM internal array). Reset in RDP_Evaluate (and only in RDP_Evaluate) |
---|
array<mixed,array>
RDP_warnings :array<mixed,array>
var | information about current warnings : array with string, $token (EM internal array) and optional link Reset in RDP_Evaluate or manually |
---|
array<mixed,array>
RDP_onlyparse :
RDP_stack :
RDP_result :
RDP_evalStatus :
varsUsed :
resetErrorsAndWarningsOnEachPart :
allVarsUsed :
prettyPrintSource :
substitutionNum :
substitutionInfo :array
var |
---|
array
jsExpression :
questionSeq :
groupSeq :
surveyMode :
sid :
hyperlinkSyntaxHighlighting :
sgqaNaming :