 |
Belle II Software
release-05-02-19
|
13 #include <framework/utilities/Utils.h>
29 class FormulaParserBase {
61 typedef std::variant<std::string, double>
InputToken;
89 [[noreturn]]
void raiseError(
const std::runtime_error& e);
139 typedef typename VariableConstructor::type
VariableType;
141 typedef std::variant<VariableType, double>
OutputToken;
155 throw std::runtime_error(
"empty string");
157 throw std::runtime_error(
"could not parse, stack size not 1, probably a bug, please report");
161 [](
double d) ->
VariableType {
return VariableConstructor()(d); }
163 }
catch (std::runtime_error& e) {
183 [op](
auto a,
auto b) ->
OutputToken {
return VariableConstructor()(op, a, b); },
192 [](
const std::string & s) ->
OutputToken {
return VariableConstructor()(s); },
205 struct StringFormulaConstructor {
212 type operator()(
const std::string& name) {
return "'" + name +
"'"; }
Helper struct for the C++17 std::visit overload pattern to allow simple use of variants.
EOperator checkForOperator(char next)
Check if the next character is a operator.
VisitOverload(Ts...) -> VisitOverload< Ts... >
Function for the C++17 std::visit overload pattern to allow simple use of variants.
void flushCurrentVariable()
Flush the currently parsed variable name and add it to the state either as variable or number.
void addOperator(EOperator op)
Add an operator to the internal state, convert them to reverse polish notation using the shunting yar...
static ENumberStatus checkNumber(ENumberStatus current, char next)
Check if a string literal with a given number status continues to be a valid number if next is append...
static double applyOperator(EOperator op, double a, double b)
Apply operator on two values.
void flushPendingOperators()
Flush all pending operators at the end of processing.
Abstract base class for different kinds of events.
void processString(const std::string &formula)
Process the given formula and store the final state.
void raiseError(const std::runtime_error &e)
Format the given runtime_error with context information and rethrow a new one.
static void assertOperatorUsable(size_t stacksize)
Make sure we have enough operands to use an operator.
static char operatorToChar(EOperator op) noexcept
Convert operator code to character.