hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
te_parser Class Reference

Math formula parser. More...

#include <tinyexpr.h>

Collaboration diagram for te_parser:
[legend]

Classes

struct  state

Public Member Functions

bool compile (std::string_view expression)
 Parses the input expression.
te_type evaluate ()
 Evaluates expression passed to compile() previously and returns its result.
te_type evaluate (std::string_view expression)
 Compiles and evaluates an expression and returns its result.
te_type get_result () const noexcept
bool success () const noexcept
bool success () const volatile noexcept
int64_t get_last_error_position () const noexcept
const std::string & get_last_error_message () const noexcept
void set_variables_and_functions (std::set< te_variable > vars)
 Sets the list of custom variables and functions.
void add_variable_or_function (te_variable var)
 Adds a custom variable or function.
void remove_variable_or_function (te_variable::name_type var)
 Removes a custom variable or function.
void remove_unused_variables_and_functions ()
 Removes any custom variables and functions that weren't used in the last compilation.
void set_unknown_symbol_resolver (te_usr_variant_type usr, const bool keepResolvedVariables=true)
 Sets a custom function to resolve unknown symbols in an expression.
std::set< te_variable > & get_variables_and_functions () noexcept
char get_decimal_separator () const noexcept
void set_decimal_separator (const char sep)
 Sets the decimal separator used for numbers.
void set_constant (const std::string_view name, const te_type value)
 Sets a constant variable's value.
te_type get_constant (const std::string_view name) const
 Retrieves a constant variable's value.
char get_list_separator () const noexcept
void set_list_separator (const char sep)
 Sets the separator used between function arguments.
bool is_function_used (const std::string_view name) const
bool is_variable_used (const std::string_view name) const
std::string list_available_functions_and_variables ()
const std::string & get_expression () const noexcept

Static Public Member Functions

static constexpr bool supports_32bit () noexcept
static constexpr bool supports_64bit () noexcept
static constexpr int get_max_integer_bitness () noexcept
static te_type get_max_integer ()
static std::string info ()

Static Public Attributes

static constexpr auto te_nan = std::numeric_limits<te_type>::quiet_NaN()
 NaN (not-a-number) constant to indicate an invalid value.
static constexpr int64_t npos = -1
 No position, which is what get_last_error_position() returns when there was no parsing error.

Private Member Functions

 te_parser ()=default
 te_parser (const te_parser &that)
te_parser & operator= (const te_parser &that)
 ~te_parser ()
te_type get_result () const volatile noexcept
int64_t get_last_error_position () const volatile noexcept
const std::set< te_variable > & get_variables_and_functions () const noexcept
char get_decimal_separator () const volatile noexcept
void set_decimal_separator (const char sep) volatile
char get_list_separator () const volatile noexcept
void set_list_separator (const char sep) volatile
void reset_state ()
 Reset everything from previous call.
void reset_usr_resolved_if_necessary ()
 Resets any resolved variables from USR if not being cached.
const te_expr * get_compiled_expression () const noexcept
 Gets the compiled expression, which will be the optimized version of the original expression.
const te_expr * get_compiled_expression () const volatile noexcept
std::set< te_variable >::iterator find_variable_or_function (const std::string_view name)
std::set< te_variable >::const_iterator find_variable_or_function (const std::string_view name) const
 TE_DEF_FUNCTION (0)
 TE_DEF_FUNCTION (1)
 TE_DEF_FUNCTION (2)
 TE_DEF_CLOSURE (0)
 TE_DEF_CLOSURE (1)
 TE_DEF_CLOSURE (2)
te_expr * te_compile (std::string_view expression, std::set< te_variable > &variables)
 Parses the input expression and binds variables.
void next_token (state *theState)
te_expr * base (state *theState)
te_expr * base_impl (state *theState)
te_expr * power (state *theState)
te_expr * factor (state *theState)
te_expr * term (state *theState)
te_expr * expr_level1 (state *theState)
te_expr * expr_level2 (state *theState)
te_expr * expr_level3 (state *theState)
te_expr * expr_level4 (state *theState)
te_expr * expr_level5 (state *theState)
te_expr * expr_level6 (state *theState)
te_expr * expr_level7 (state *theState)
te_expr * expr_level8 (state *theState)
te_expr * expr_level9 (state *theState)
te_expr * list (state *theState)

Static Private Member Functions

static constexpr bool te_exceeds_uint32 (te_type val) noexcept
static bool number_to_bool (te_type val)
 Helper function to convert a number into boolean.
static void validate_name (const te_variable &var)
 Validates that a variable only contains legal characters (and has a valid length).
static constexpr bool is_name_char_valid (const char chr) noexcept
static size_t find_outside_of_string (const std::string &str, const char chr, const size_t startIndex)
static constexpr auto is_pure (const te_variable_flags type)
static constexpr auto is_variadic (const te_variable_flags type)
static auto get_arity (const te_variant_type &var)
static constexpr bool is_constant (const te_variant_type &var) noexcept
static constexpr te_type get_constant_value (const te_variant_type &var)
static constexpr bool is_variable (const te_variant_type &var) noexcept
static constexpr const te_type * get_variable (const te_variant_type &var)
static constexpr bool is_function (const te_variant_type &var)
static constexpr bool is_string (const te_variant_type &var) noexcept
static constexpr std::string_view get_string (const te_variant_type &var)
static constexpr bool is_arg_function (const te_variant_type &var) noexcept
static constexpr bool is_arg_closure (const te_variant_type &var) noexcept
static constexpr bool is_closure (const te_variant_type &var)
static constexpr bool is_any_function (const te_variant_type &var)
static constexpr bool is_any_closure (const te_variant_type &var)
static size_t get_parameter_count (const te_expr *texp)
static te_expr * new_expr (const te_variable_flags type, te_variant_type value, const std::initializer_list< te_expr * > &parameters)
static te_expr * new_expr (const te_variable_flags type, te_variant_type value)
static constexpr bool is_letter (const char chr) noexcept
static te_type te_eval (const te_expr *texp)
static void te_free (te_expr *texp)
static void te_free_parameters (te_expr *texp)
static void optimize (te_expr *texp)
static auto find_builtin (const std::string_view name)
static auto find_lookup (state *ste, const std::string_view name)

Private Attributes

std::set< te_variable > m_customFuncsAndVars
te_usr_variant_type m_unknownSymbolResolve {te_usr_noop{}}
bool m_keepResolvedVariables {true}
char m_decimalSeparator {'.'}
char m_listSeparator {','}
std::string m_expression
te_expr * m_compiledExpression {nullptr}
bool m_parseSuccess {false}
int64_t m_errorPos {0}
std::string m_lastErrorMessage
te_type m_result {te_nan}
std::set< te_variable::name_type > m_resolvedVariables
std::set< te_variable >::const_iterator m_currentVar
bool m_varFound {false}
std::set< te_variable::name_type, te_string_less > m_usedFunctions
std::set< te_variable::name_type, te_string_less > m_usedVars

Static Private Attributes

static constexpr double MAX_BITOPS_VAL {281474976710655}
static const std::set< te_variable > m_functions

Detailed Description

Math formula parser.

Definition at line 382 of file tinyexpr.h.

Constructor & Destructor Documentation

◆ te_parser() [1/2]

te_parser::te_parser ( )
privatedefault

◆ te_parser() [2/2]

te_parser::te_parser ( const te_parser & that)
inlineprivate

Definition at line 389 of file tinyexpr.h.

◆ ~te_parser()

te_parser::~te_parser ( )
inlineprivate

Definition at line 435 of file tinyexpr.h.

Member Function Documentation

◆ add_variable_or_function()

void te_parser::add_variable_or_function ( te_variable var)
inline

Adds a custom variable or function.

Parameters
varThe variable/function to add.
Note
Prefer using set_variables_and_functions() as it will be more optimal (fewer sorts will need to be performed).
Exceptions
std::runtime_errorThrows an exception if an illegal character is found in the variable name.

Definition at line 594 of file tinyexpr.h.

◆ base()

te_expr * te_parser::base ( state * theState)
nodiscardprivate

◆ base_impl()

te_expr * te_parser::base_impl ( state * theState)
nodiscardprivate

◆ compile()

bool te_parser::compile ( std::string_view expression)

Parses the input expression.

Parameters
expressionThe formula to compile.
Returns
Whether the expression compiled or not. (This can be checked by calling success() afterward as well.)
See also
success().
Note
Returns NaN if division or modulus by zero occurs.
Exceptions
std::runtime_errorThrows an exception in the case of arithmetic overflows (e.g., 1 << 64 would cause an overflow).

◆ evaluate() [1/2]

te_type te_parser::evaluate ( )
nodiscard

Evaluates expression passed to compile() previously and returns its result.

Returns
The result, or NaN on error.
Exceptions
std::runtime_errorThrows an exception in the case of arithmetic overflows (e.g., 1 << 64 would cause an overflow).

◆ evaluate() [2/2]

te_type te_parser::evaluate ( std::string_view expression)
nodiscard

Compiles and evaluates an expression and returns its result.

Parameters
expressionThe formula to compile and evaluate.
Returns
The result, or NaN on error.
Note
Returns NaN if division or modulus by zero occurs.
Exceptions
std::runtime_errorThrows an exception in the case of arithmetic overflows (e.g., 1 << 64 would cause an overflow).

◆ expr_level1()

te_expr * te_parser::expr_level1 ( state * theState)
nodiscardprivate

◆ expr_level2()

te_expr * te_parser::expr_level2 ( state * theState)
nodiscardprivate

◆ expr_level3()

te_expr * te_parser::expr_level3 ( state * theState)
nodiscardprivate

◆ expr_level4()

te_expr * te_parser::expr_level4 ( state * theState)
nodiscardprivate

◆ expr_level5()

te_expr * te_parser::expr_level5 ( state * theState)
nodiscardprivate

◆ expr_level6()

te_expr * te_parser::expr_level6 ( state * theState)
nodiscardprivate

◆ expr_level7()

te_expr * te_parser::expr_level7 ( state * theState)
nodiscardprivate

◆ expr_level8()

te_expr * te_parser::expr_level8 ( state * theState)
nodiscardprivate

◆ expr_level9()

te_expr * te_parser::expr_level9 ( state * theState)
nodiscardprivate

◆ factor()

te_expr * te_parser::factor ( state * theState)
nodiscardprivate

◆ find_builtin()

auto te_parser::find_builtin ( const std::string_view name)
inlinestaticnodiscardprivate

Definition at line 1177 of file tinyexpr.h.

◆ find_lookup()

auto te_parser::find_lookup ( state * ste,
const std::string_view name )
inlinestaticnodiscardprivate

Definition at line 1184 of file tinyexpr.h.

◆ find_outside_of_string()

size_t te_parser::find_outside_of_string ( const std::string & str,
const char chr,
const size_t startIndex )
inlinestaticnodiscardprivate
Returns
The position of chr at or after startIndex, skipping quoted string literals, or std::string::npos if not found.
Parameters
strThe string to search.
chrThe character to search for.
startIndexWhere to begin accepting matches.
Note
Quote state is tracked from the start of str, so this stays correct after the caller has erased earlier sections.

Definition at line 892 of file tinyexpr.h.

◆ find_variable_or_function() [1/2]

std::set< te_variable >::iterator te_parser::find_variable_or_function ( const std::string_view name)
inlinenodiscardprivate
Returns
An iterator to the custom variable or function with the given name, or end of get_variables_and_functions() if not found.
Parameters
nameThe name of the function or variable to search for.

Definition at line 910 of file tinyexpr.h.

◆ find_variable_or_function() [2/2]

std::set< te_variable >::const_iterator te_parser::find_variable_or_function ( const std::string_view name) const
inlinenodiscardprivate
Returns
An iterator to the custom variable or function with the given name, or end of get_variables_and_functions() if not found.
Parameters
nameThe name of the function or variable to search for.

Definition at line 926 of file tinyexpr.h.

◆ get_arity()

auto te_parser::get_arity ( const te_variant_type & var)
inlinestaticnodiscardprivate
Returns
Number of parameters that a function/variable takes.

Definition at line 949 of file tinyexpr.h.

◆ get_compiled_expression() [1/2]

const te_expr * te_parser::get_compiled_expression ( ) const
inlinenodiscardprivatenoexcept

Gets the compiled expression, which will be the optimized version of the original expression.

Returns
The compiled expression.

Definition at line 840 of file tinyexpr.h.

◆ get_compiled_expression() [2/2]

const te_expr * te_parser::get_compiled_expression ( ) const volatile
inlinenodiscardprivatenoexcept

Definition at line 846 of file tinyexpr.h.

◆ get_constant()

te_type te_parser::get_constant ( const std::string_view name) const
inlinenodiscard

Retrieves a constant variable's value.

Parameters
nameThe name of the (constant) variable.
Returns
The value of the constant variable if found, NaN otherwise.

Definition at line 718 of file tinyexpr.h.

◆ get_constant_value()

constexpr te_type te_parser::get_constant_value ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate

Definition at line 973 of file tinyexpr.h.

◆ get_decimal_separator() [1/2]

char te_parser::get_decimal_separator ( ) const
inlinenodiscardnoexcept
Returns
The decimal separator used for numbers.

Definition at line 659 of file tinyexpr.h.

◆ get_decimal_separator() [2/2]

char te_parser::get_decimal_separator ( ) const volatile
inlinenodiscardprivatenoexcept

Definition at line 665 of file tinyexpr.h.

◆ get_expression()

const std::string & te_parser::get_expression ( ) const
inlinenodiscardnoexcept
Returns
The last formula passed to the parser.
Note
Comments will be stripped from the original expression.

Definition at line 788 of file tinyexpr.h.

◆ get_last_error_message()

const std::string & te_parser::get_last_error_message ( ) const
inlinenodiscardnoexcept
Returns
Any error message from the last parse.

Definition at line 566 of file tinyexpr.h.

◆ get_last_error_position() [1/2]

int64_t te_parser::get_last_error_position ( ) const
inlinenodiscardnoexcept
Returns
The zero-based index into the last parsed expression where the parse failed, or te_parser::npos if no error occurred.
Note
Call success() to see if the last parse succeeded or not.

Definition at line 554 of file tinyexpr.h.

◆ get_last_error_position() [2/2]

int64_t te_parser::get_last_error_position ( ) const volatile
inlinenodiscardprivatenoexcept

Definition at line 560 of file tinyexpr.h.

◆ get_list_separator() [1/2]

char te_parser::get_list_separator ( ) const
inlinenodiscardnoexcept
Returns
The separator used between function arguments.

Definition at line 734 of file tinyexpr.h.

◆ get_list_separator() [2/2]

char te_parser::get_list_separator ( ) const volatile
inlinenodiscardprivatenoexcept

Definition at line 740 of file tinyexpr.h.

◆ get_max_integer()

te_type te_parser::get_max_integer ( )
inlinestaticnodiscard
Returns
The largest integer value that the parser can handle without truncation.

Definition at line 485 of file tinyexpr.h.

◆ get_max_integer_bitness()

constexpr int te_parser::get_max_integer_bitness ( )
inlinestaticnodiscardconstexprnoexcept
Returns
The bits available in the internal data type.
This will affect the largest integer size that can be used in bitwise operations.

Definition at line 478 of file tinyexpr.h.

◆ get_parameter_count()

size_t te_parser::get_parameter_count ( const te_expr * texp)
inlinestaticnodiscardprivate
Returns
A node's real argument count, excluding a closure's context slot.
Note
Use this instead of get_arity() for te_arg_fun/te_arg_confun nodes, whose arity is only known once base() has parsed them.

Definition at line 1077 of file tinyexpr.h.

◆ get_result() [1/2]

te_type te_parser::get_result ( ) const
inlinenodiscardnoexcept
Returns
The last call to evaluate()'s result (which will be NaN on error).

Definition at line 527 of file tinyexpr.h.

◆ get_result() [2/2]

te_type te_parser::get_result ( ) const volatile
inlinenodiscardprivatenoexcept

Definition at line 533 of file tinyexpr.h.

◆ get_string()

constexpr std::string_view te_parser::get_string ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate

Definition at line 1005 of file tinyexpr.h.

◆ get_variable()

constexpr const te_type * te_parser::get_variable ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate

Definition at line 984 of file tinyexpr.h.

◆ get_variables_and_functions() [1/2]

const std::set< te_variable > & te_parser::get_variables_and_functions ( ) const
inlinenodiscardprivatenoexcept

Definition at line 647 of file tinyexpr.h.

◆ get_variables_and_functions() [2/2]

std::set< te_variable > & te_parser::get_variables_and_functions ( )
inlinenodiscardnoexcept
Returns
The list of custom variables and functions.

Definition at line 653 of file tinyexpr.h.

◆ info()

std::string te_parser::info ( )
staticnodiscard
Returns
Information about how the parser is configured, its capabilities, etc.

◆ is_any_closure()

constexpr bool te_parser::is_any_closure ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate
Returns
true for any context function, including the ones taking te_arg.

Definition at line 1069 of file tinyexpr.h.

◆ is_any_function()

constexpr bool te_parser::is_any_function ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate
Returns
true for any function, including the ones taking te_arg.

Definition at line 1062 of file tinyexpr.h.

◆ is_arg_closure()

constexpr bool te_parser::is_arg_closure ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivatenoexcept

Definition at line 1016 of file tinyexpr.h.

◆ is_arg_function()

constexpr bool te_parser::is_arg_function ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivatenoexcept

Definition at line 1011 of file tinyexpr.h.

◆ is_closure()

constexpr bool te_parser::is_closure ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate

Definition at line 1036 of file tinyexpr.h.

◆ is_constant()

constexpr bool te_parser::is_constant ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivatenoexcept

Definition at line 968 of file tinyexpr.h.

◆ is_function()

constexpr bool te_parser::is_function ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivate

Definition at line 990 of file tinyexpr.h.

◆ is_function_used()

bool te_parser::is_function_used ( const std::string_view name) const
inlinenodiscard
Returns
true if name is a function that had been used in the last parsed formula.
Parameters
nameThe name of the function.
See also
compile() and evaluate().

Definition at line 768 of file tinyexpr.h.

◆ is_letter()

constexpr bool te_parser::is_letter ( const char chr)
inlinestaticnodiscardconstexprprivatenoexcept

Definition at line 1147 of file tinyexpr.h.

◆ is_name_char_valid()

constexpr bool te_parser::is_name_char_valid ( const char chr)
inlinestaticnodiscardconstexprprivatenoexcept
Returns
true if character is valid for a function or variable name.
Parameters
chrThe character to review.

Definition at line 877 of file tinyexpr.h.

◆ is_pure()

constexpr auto te_parser::is_pure ( const te_variable_flags type)
inlinestaticnodiscardconstexprprivate

Definition at line 938 of file tinyexpr.h.

◆ is_string()

constexpr bool te_parser::is_string ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivatenoexcept

Definition at line 1000 of file tinyexpr.h.

◆ is_variable()

constexpr bool te_parser::is_variable ( const te_variant_type & var)
inlinestaticnodiscardconstexprprivatenoexcept

Definition at line 979 of file tinyexpr.h.

◆ is_variable_used()

bool te_parser::is_variable_used ( const std::string_view name) const
inlinenodiscard
Returns
true if name is a variable that had been used in the last parsed formula.
Parameters
nameThe name of the variable.
See also
compile() and evaluate().

Definition at line 777 of file tinyexpr.h.

◆ is_variadic()

constexpr auto te_parser::is_variadic ( const te_variable_flags type)
inlinestaticnodiscardconstexprprivate

Definition at line 943 of file tinyexpr.h.

◆ list()

te_expr * te_parser::list ( state * theState)
nodiscardprivate

◆ list_available_functions_and_variables()

std::string te_parser::list_available_functions_and_variables ( )
nodiscard
Returns
A report of all available functions and variables.

◆ new_expr() [1/2]

te_expr * te_parser::new_expr ( const te_variable_flags type,
te_variant_type value )
inlinestaticnodiscardprivate

Definition at line 1138 of file tinyexpr.h.

◆ new_expr() [2/2]

te_expr * te_parser::new_expr ( const te_variable_flags type,
te_variant_type value,
const std::initializer_list< te_expr * > & parameters )
inlinestaticnodiscardprivate

Definition at line 1124 of file tinyexpr.h.

◆ next_token()

void te_parser::next_token ( state * theState)
private

◆ number_to_bool()

bool te_parser::number_to_bool ( te_type val)
inlinestaticnodiscardprivate

Helper function to convert a number into boolean.

This takes NaN into account, returning for NaN.

Parameters
valThe value to examine.
Returns
true if the value is non-zero and also valid (not NaN or infinite).

Definition at line 799 of file tinyexpr.h.

◆ operator=()

te_parser & te_parser::operator= ( const te_parser & that)
inlineprivate

Definition at line 409 of file tinyexpr.h.

◆ optimize()

void te_parser::optimize ( te_expr * texp)
staticprivate

◆ power()

te_expr * te_parser::power ( state * theState)
nodiscardprivate

◆ remove_unused_variables_and_functions()

void te_parser::remove_unused_variables_and_functions ( )
inline

Removes any custom variables and functions that weren't used in the last compilation.

This can be useful if the parser is preloaded with a large number of variables and functions that needs to be pruned after the first expression is parsed.

Warning
After calling this, any custom variables and functions that weren't found in the previously parsed expression will no longer be available.

Definition at line 619 of file tinyexpr.h.

◆ remove_variable_or_function()

void te_parser::remove_variable_or_function ( te_variable::name_type var)
inline

Removes a custom variable or function.

Parameters
varThe variable/function to remove (by name).

Definition at line 601 of file tinyexpr.h.

◆ reset_state()

void te_parser::reset_state ( )
inlineprivate

Reset everything from previous call.

Definition at line 810 of file tinyexpr.h.

◆ reset_usr_resolved_if_necessary()

void te_parser::reset_usr_resolved_if_necessary ( )
inlineprivate

Resets any resolved variables from USR if not being cached.

Definition at line 827 of file tinyexpr.h.

◆ set_constant()

void te_parser::set_constant ( const std::string_view name,
const te_type value )
inline

Sets a constant variable's value.

Parameters
nameThe name of the (constant) variable.
valueThe new value to set the constant to.
Note
If the constant variable hasn't been added yet (via set_variables_and_functions()), then this will add it.
If a variable with the provided name is found but is not a constant, then this will be ignored.

Definition at line 698 of file tinyexpr.h.

◆ set_decimal_separator() [1/2]

void te_parser::set_decimal_separator ( const char sep)
inline

Sets the decimal separator used for numbers.

Parameters
sepThe decimal separator.
Exceptions
std::runtime_errorThrows an exception if an illegal character is used.

Definition at line 673 of file tinyexpr.h.

◆ set_decimal_separator() [2/2]

void te_parser::set_decimal_separator ( const char sep) volatile
inlineprivate

Definition at line 682 of file tinyexpr.h.

◆ set_list_separator() [1/2]

void te_parser::set_list_separator ( const char sep)
inline

Sets the separator used between function arguments.

Parameters
sepThe list separator.
Exceptions
std::runtime_errorThrows an exception if an illegal character is used.

Definition at line 748 of file tinyexpr.h.

◆ set_list_separator() [2/2]

void te_parser::set_list_separator ( const char sep) volatile
inlineprivate

Definition at line 756 of file tinyexpr.h.

◆ set_unknown_symbol_resolver()

void te_parser::set_unknown_symbol_resolver ( te_usr_variant_type usr,
const bool keepResolvedVariables = true )
inline

Sets a custom function to resolve unknown symbols in an expression.

Parameters
usrThe function to use to resolve unknown symbols.
keepResolvedVariablestrue to cache any resolved variables into the parser. This means that they will not need to be resolved again on subsequent calls to evaluate().
Pass false to this if you wish to re-resolve any previously resolved variables on later evaluations. This can be useful for when a resolved variable's value is volatile and needs to be re-resolved on every use.

Definition at line 639 of file tinyexpr.h.

◆ set_variables_and_functions()

void te_parser::set_variables_and_functions ( std::set< te_variable > vars)
inline

Sets the list of custom variables and functions.

Parameters
varsThe list of variables and functions.
Note
Valid variable and function names must begin with a letter from a-z (A-Z), followed by additional English letters, numbers, periods, or underscores.
Exceptions
std::runtime_errorThrows an exception if an illegal character is found in any variable name.

Definition at line 579 of file tinyexpr.h.

◆ success() [1/2]

bool te_parser::success ( ) const
inlinenodiscardnoexcept
Returns
Whether the last call to compile() was successful.
See also
get_last_error_position().

Definition at line 540 of file tinyexpr.h.

◆ success() [2/2]

bool te_parser::success ( ) const volatile
inlinenodiscardnoexcept

Definition at line 545 of file tinyexpr.h.

◆ supports_32bit()

constexpr bool te_parser::supports_32bit ( )
inlinestaticnodiscardconstexprnoexcept
Returns
true if the parser's internal type can hold uint32_t without truncation.

Definition at line 449 of file tinyexpr.h.

◆ supports_64bit()

constexpr bool te_parser::supports_64bit ( )
inlinestaticnodiscardconstexprnoexcept
Returns
true if the parser's internal type can hold uint64_t without truncation.

Definition at line 457 of file tinyexpr.h.

◆ te_compile()

te_expr * te_parser::te_compile ( std::string_view expression,
std::set< te_variable > & variables )
nodiscardprivate

Parses the input expression and binds variables.

Parameters
expressionThe formula to parse.
variablesThe collection of custom functions and variables to add to the parser.
Returns
null on error.

◆ TE_DEF_CLOSURE() [1/3]

te_parser::TE_DEF_CLOSURE ( 0 )
private

◆ TE_DEF_CLOSURE() [2/3]

te_parser::TE_DEF_CLOSURE ( 1 )
private

◆ TE_DEF_CLOSURE() [3/3]

te_parser::TE_DEF_CLOSURE ( 2 )
private

◆ TE_DEF_FUNCTION() [1/3]

te_parser::TE_DEF_FUNCTION ( 0 )
private

◆ TE_DEF_FUNCTION() [2/3]

te_parser::TE_DEF_FUNCTION ( 1 )
private

◆ TE_DEF_FUNCTION() [3/3]

te_parser::TE_DEF_FUNCTION ( 2 )
private

◆ te_eval()

te_type te_parser::te_eval ( const te_expr * texp)
staticnodiscardprivate

◆ te_exceeds_uint32()

constexpr bool te_parser::te_exceeds_uint32 ( te_type val)
inlinestaticnodiscardconstexprprivatenoexcept
Returns
true if val is too large to convert to a uint32_t.

Definition at line 465 of file tinyexpr.h.

◆ te_free()

void te_parser::te_free ( te_expr * texp)
inlinestaticprivate

Definition at line 1165 of file tinyexpr.h.

◆ te_free_parameters()

void te_parser::te_free_parameters ( te_expr * texp)
staticprivate

◆ term()

te_expr * te_parser::term ( state * theState)
nodiscardprivate

◆ validate_name()

void te_parser::validate_name ( const te_variable & var)
inlinestaticprivate

Validates that a variable only contains legal characters (and has a valid length).

Parameters
varThe variable to validate.
Exceptions
std::runtime_errorThrows an exception if an illegal character is found.

Definition at line 855 of file tinyexpr.h.

Member Data Documentation

◆ m_compiledExpression

te_expr* te_parser::m_compiledExpression {nullptr}
private

Definition at line 1238 of file tinyexpr.h.

◆ m_currentVar

std::set<te_variable>::const_iterator te_parser::m_currentVar
private

Definition at line 1247 of file tinyexpr.h.

◆ m_customFuncsAndVars

std::set<te_variable> te_parser::m_customFuncsAndVars
private

Definition at line 1227 of file tinyexpr.h.

◆ m_decimalSeparator

char te_parser::m_decimalSeparator {'.'}
private

Definition at line 1233 of file tinyexpr.h.

◆ m_errorPos

int64_t te_parser::m_errorPos {0}
private

Definition at line 1241 of file tinyexpr.h.

◆ m_expression

std::string te_parser::m_expression
private

Definition at line 1237 of file tinyexpr.h.

◆ m_functions

const std::set<te_variable> te_parser::m_functions
staticprivate

Definition at line 1224 of file tinyexpr.h.

◆ m_keepResolvedVariables

bool te_parser::m_keepResolvedVariables {true}
private

Definition at line 1231 of file tinyexpr.h.

◆ m_lastErrorMessage

std::string te_parser::m_lastErrorMessage
private

Definition at line 1242 of file tinyexpr.h.

◆ m_listSeparator

char te_parser::m_listSeparator {','}
private

Definition at line 1234 of file tinyexpr.h.

◆ m_parseSuccess

bool te_parser::m_parseSuccess {false}
private

Definition at line 1240 of file tinyexpr.h.

◆ m_resolvedVariables

std::set<te_variable::name_type> te_parser::m_resolvedVariables
private

Definition at line 1245 of file tinyexpr.h.

◆ m_result

te_type te_parser::m_result {te_nan}
private

Definition at line 1243 of file tinyexpr.h.

◆ m_unknownSymbolResolve

te_usr_variant_type te_parser::m_unknownSymbolResolve {te_usr_noop{}}
private

Definition at line 1229 of file tinyexpr.h.

◆ m_usedFunctions

std::set<te_variable::name_type, te_string_less> te_parser::m_usedFunctions
private

Definition at line 1250 of file tinyexpr.h.

◆ m_usedVars

std::set<te_variable::name_type, te_string_less> te_parser::m_usedVars
private

Definition at line 1251 of file tinyexpr.h.

◆ m_varFound

bool te_parser::m_varFound {false}
private

Definition at line 1248 of file tinyexpr.h.

◆ MAX_BITOPS_VAL

double te_parser::MAX_BITOPS_VAL {281474976710655}
staticconstexprprivate

Definition at line 444 of file tinyexpr.h.

◆ npos

int64_t te_parser::npos = -1
staticconstexpr

No position, which is what get_last_error_position() returns when there was no parsing error.

Definition at line 441 of file tinyexpr.h.

◆ te_nan

auto te_parser::te_nan = std::numeric_limits<te_type>::quiet_NaN()
staticconstexpr

NaN (not-a-number) constant to indicate an invalid value.

Definition at line 438 of file tinyexpr.h.


The documentation for this class was generated from the following file:
  • /home/runner/work/hummingbird/hummingbird/include/utils/tinyexpr.h