Libecoli 0.11.1
Extensible COmmand LIne library
Loading...
Searching...
No Matches
Expression node

A node for parsing and evaluating expressions with operators. More...

Data Structures

struct  ec_node_expr_eval_ops

Typedefs

typedef int(* ec_node_expr_eval_var_t) (void **result, void *userctx, const struct ec_pnode *var)
typedef int(* ec_node_expr_eval_pre_op_t) (void **result, void *userctx, void *operand, const struct ec_pnode *operator)
typedef int(* ec_node_expr_eval_post_op_t) (void **result, void *userctx, void *operand, const struct ec_pnode *operator)
typedef int(* ec_node_expr_eval_bin_op_t) (void **result, void *userctx, void *operand1, const struct ec_pnode *operator, void *operand2)
typedef int(* ec_node_expr_eval_parenthesis_t) (void **result, void *userctx, const struct ec_pnode *open_paren, const struct ec_pnode *close_paren, void *value)
typedef void(* ec_node_expr_eval_free_t) (void *result, void *userctx)

Functions

struct ec_nodeec_node_expr (const char *id)
int ec_node_expr_set_val_node (struct ec_node *gen_node, struct ec_node *val_node)
int ec_node_expr_add_bin_op (struct ec_node *gen_node, struct ec_node *op)
int ec_node_expr_add_pre_op (struct ec_node *gen_node, struct ec_node *op)
int ec_node_expr_add_post_op (struct ec_node *gen_node, struct ec_node *op)
int ec_node_expr_add_parenthesis (struct ec_node *gen_node, struct ec_node *open, struct ec_node *close)
int ec_node_expr_eval (void **result, const struct ec_node *node, struct ec_pnode *parse, const struct ec_node_expr_eval_ops *ops, void *userctx)

Detailed Description

A node for parsing and evaluating expressions with operators.

Configuration Schema

No configuration schema.

Typedef Documentation

◆ ec_node_expr_eval_var_t

typedef int(* ec_node_expr_eval_var_t) (void **result, void *userctx, const struct ec_pnode *var)

Callback function type for evaluating a variable

Parameters
resultOn success, this pointer must be set by the user to point to a user structure describing the evaluated result.
userctxA user-defined context passed to all callback functions, which can be used to maintain a state or store global information.
varThe parse result referencing the variable.
Returns
0 on success (*result must be set), or -errno on error (*result is undefined).

Definition at line 32 of file node_expr.h.

◆ ec_node_expr_eval_pre_op_t

typedef int(* ec_node_expr_eval_pre_op_t) (void **result, void *userctx, void *operand, const struct ec_pnode *operator)

Callback function type for evaluating a prefix-operator

Parameters
resultOn success, this pointer must be set by the user to point to a user structure describing the evaluated result.
userctxA user-defined context passed to all callback functions, which can be used to maintain a state or store global information.
operandThe evaluated expression on which the operation should be applied.
operatorThe parse result referencing the operator.
Returns
0 on success (*result must be set, operand is freed), or -errno on error (*result is undefined, operand is not freed).

Definition at line 51 of file node_expr.h.

◆ ec_node_expr_eval_post_op_t

typedef int(* ec_node_expr_eval_post_op_t) (void **result, void *userctx, void *operand, const struct ec_pnode *operator)

Callback function type for evaluating a postfix-operator.

Same as ec_node_expr_eval_pre_op_t but for postfix operators.

Definition at line 63 of file node_expr.h.

◆ ec_node_expr_eval_bin_op_t

typedef int(* ec_node_expr_eval_bin_op_t) (void **result, void *userctx, void *operand1, const struct ec_pnode *operator,void *operand2)

Callback function type for evaluating a binary operator.

Parameters
resultOn success, this pointer must be set by the user to point to a user structure describing the evaluated result.
userctxA user-defined context passed to all callback functions.
operand1The evaluated left operand.
operatorThe parse result referencing the operator.
operand2The evaluated right operand.
Returns
0 on success (*result must be set, operands are freed), or -errno on error (*result is undefined, operands are not freed).

Definition at line 88 of file node_expr.h.

◆ ec_node_expr_eval_parenthesis_t

typedef int(* ec_node_expr_eval_parenthesis_t) (void **result, void *userctx, const struct ec_pnode *open_paren, const struct ec_pnode *close_paren, void *value)

Callback function type for evaluating a parenthesized expression.

Parameters
resultOn success, this pointer must be set by the user to point to a user structure describing the evaluated result.
userctxA user-defined context passed to all callback functions.
open_parenThe parse result referencing the opening parenthesis.
close_parenThe parse result referencing the closing parenthesis.
valueThe evaluated expression inside the parentheses.
Returns
0 on success (*result must be set, value is freed), or -errno on error (*result is undefined, value is not freed).

Definition at line 114 of file node_expr.h.

◆ ec_node_expr_eval_free_t

typedef void(* ec_node_expr_eval_free_t) (void *result, void *userctx)

Callback function type for freeing an evaluated result.

Parameters
resultThe result to free.
userctxA user-defined context passed to all callback functions.

Definition at line 130 of file node_expr.h.

Function Documentation

◆ ec_node_expr()

struct ec_node * ec_node_expr ( const char * id)

Create an expression node.

Parameters
idThe node identifier.
Returns
The node, or NULL on error (errno is set).

◆ ec_node_expr_set_val_node()

int ec_node_expr_set_val_node ( struct ec_node * gen_node,
struct ec_node * val_node )

Set the value (terminal) node for an expression.

Parameters
gen_nodeThe expression node.
val_nodeThe node matching values. It is consumed and will be freed when the parent is freed, or immediately on error.
Returns
0 on success, -1 on error (errno is set).

◆ ec_node_expr_add_bin_op()

int ec_node_expr_add_bin_op ( struct ec_node * gen_node,
struct ec_node * op )

Add a binary operator to an expression node.

Parameters
gen_nodeThe expression node.
opThe operator node. It is consumed and will be freed when the parent is freed, or immediately on error.
Returns
0 on success, -1 on error (errno is set).

◆ ec_node_expr_add_pre_op()

int ec_node_expr_add_pre_op ( struct ec_node * gen_node,
struct ec_node * op )

Add a prefix operator to an expression node.

Parameters
gen_nodeThe expression node.
opThe operator node. It is consumed and will be freed when the parent is freed, or immediately on error.
Returns
0 on success, -1 on error (errno is set).

◆ ec_node_expr_add_post_op()

int ec_node_expr_add_post_op ( struct ec_node * gen_node,
struct ec_node * op )

Add a postfix operator to an expression node.

Parameters
gen_nodeThe expression node.
opThe operator node. It is consumed and will be freed when the parent is freed, or immediately on error.
Returns
0 on success, -1 on error (errno is set).

◆ ec_node_expr_add_parenthesis()

int ec_node_expr_add_parenthesis ( struct ec_node * gen_node,
struct ec_node * open,
struct ec_node * close )

Add parentheses to an expression node.

Parameters
gen_nodeThe expression node.
openThe opening parenthesis node. It is consumed and will be freed when the parent is freed, or immediately on error.
closeThe closing parenthesis node. It is consumed and will be freed when the parent is freed, or immediately on error.
Returns
0 on success, -1 on error (errno is set).

◆ ec_node_expr_eval()

int ec_node_expr_eval ( void ** result,
const struct ec_node * node,
struct ec_pnode * parse,
const struct ec_node_expr_eval_ops * ops,
void * userctx )

Evaluate a parsed expression.

Parameters
resultOn success, this pointer will be set to the evaluated result.
nodeThe expression node.
parseThe parse tree to evaluate.
opsThe evaluation callbacks.
userctxA user-defined context passed to all callbacks.
Returns
0 on success, -1 on error (errno is set).