Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ExpressionParser.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "CoreTypes.h"
7#include "HAL/PlatformCrt.h"
8#include "Misc/ExpressionParserTypes.h"
9#include "Templates/ValueOrError.h"
10
11/** An expression parser, responsible for lexing, compiling, and evaluating expressions.
12 * The parser supports 3 functions:
13 * 1. Lexing the expression into a set of user defined tokens,
14 * 2. Compiling the tokenized expression to an efficient reverse-polish execution order,
15 * 3. Evaluating the compiled tokens
16 *
17 * See ExpressionParserExamples.cpp for example usage.
18 */
19
20namespace ExpressionParser
21{
24
25 /** Lex the specified string, using the specified grammar */
26 LexResultType Lex(const TCHAR* InExpression, const FTokenDefinitions& TokenDefinitions);
27
28 /** Compile the specified expression into an array of Reverse-Polish order nodes for evaluation, according to our grammar definition */
29 CompileResultType Compile(const TCHAR* InExpression, const FTokenDefinitions& TokenDefinitions, const FExpressionGrammar& InGrammar);
30
31 /** Compile the specified tokens into an array of Reverse-Polish order nodes for evaluation, according to our grammar definition */
32 CompileResultType Compile(TArray<FExpressionToken> InTokens, const FExpressionGrammar& InGrammar);
33
34 /** Evaluate the specified expression using the specified token definitions, grammar definition, and evaluation environment */
35 FExpressionResult Evaluate(const TCHAR* InExpression, const FTokenDefinitions& InTokenDefinitions, const FExpressionGrammar& InGrammar, const IOperatorEvaluationEnvironment& InEnvironment);
36
37 /** Evaluate the specified pre-compiled tokens using an evaluation environment */
38 FExpressionResult Evaluate(const TArray<FCompiledToken>& CompiledTokens, const IOperatorEvaluationEnvironment& InEnvironment);
39
40 /** Templated versions of evaluation functions used when passing a specific jump table and context */
41 template<typename ContextType>
42 FExpressionResult Evaluate(const TCHAR* InExpression, const FTokenDefinitions& InTokenDefinitions, const FExpressionGrammar& InGrammar, const TOperatorJumpTable<ContextType>& InJumpTable, const ContextType* InContext = nullptr)
43 {
46 }
47
48 template<typename ContextType>
49 FExpressionResult Evaluate(const TArray<FCompiledToken>& CompiledTokens, const TOperatorJumpTable<ContextType>& InJumpTable, const ContextType* InContext = nullptr)
50 {
53 }
54}
TValueOrError< FExpressionNode, FExpressionError > FExpressionResult
FExpressionResult Evaluate(const TArray< FCompiledToken > &CompiledTokens, const TOperatorJumpTable< ContextType > &InJumpTable, const ContextType *InContext=nullptr)
TValueOrError< TArray< FExpressionToken >, FExpressionError > LexResultType
FExpressionResult Evaluate(const TArray< FCompiledToken > &CompiledTokens, const IOperatorEvaluationEnvironment &InEnvironment)
CompileResultType Compile(TArray< FExpressionToken > InTokens, const FExpressionGrammar &InGrammar)
FExpressionResult Evaluate(const TCHAR *InExpression, const FTokenDefinitions &InTokenDefinitions, const FExpressionGrammar &InGrammar, const TOperatorJumpTable< ContextType > &InJumpTable, const ContextType *InContext=nullptr)
LexResultType Lex(const TCHAR *InExpression, const FTokenDefinitions &TokenDefinitions)
FExpressionResult Evaluate(const TCHAR *InExpression, const FTokenDefinitions &InTokenDefinitions, const FExpressionGrammar &InGrammar, const IOperatorEvaluationEnvironment &InEnvironment)
TValueOrError< TArray< FCompiledToken >, FExpressionError > CompileResultType
CompileResultType Compile(const TCHAR *InExpression, const FTokenDefinitions &TokenDefinitions, const FExpressionGrammar &InGrammar)