api documentation for ec_parse
[protos/libecoli.git] / include / ecoli_node_expr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3  */
4
5 /**
6  * @defgroup nodes Nodes
7  * @{
8  */
9
10 #ifndef ECOLI_NODE_EXPR_
11 #define ECOLI_NODE_EXPR_
12
13 #include <ecoli_node.h>
14
15 /**
16  * Callback function type for evaluating a variable
17  *
18  * @param result
19  *   On success, this pointer must be set by the user to point
20  *   to a user structure describing the evaluated result.
21  * @param userctx
22  *   A user-defined context passed to all callback functions, which
23  *   can be used to maintain a state or store global information.
24  * @param var
25  *   The parse result referencing the variable.
26  * @return
27  *   0 on success (*result must be set), or -errno on error (*result
28  *   is undefined).
29  */
30 typedef int (*ec_node_expr_eval_var_t)(
31         void **result, void *userctx,
32         const struct ec_pnode *var);
33
34 /**
35  * Callback function type for evaluating a prefix-operator
36  *
37  * @param result
38  *   On success, this pointer must be set by the user to point
39  *   to a user structure describing the evaluated result.
40  * @param userctx
41  *   A user-defined context passed to all callback functions, which
42  *   can be used to maintain a state or store global information.
43  * @param operand
44  *   The evaluated expression on which the operation should be applied.
45  * @param var
46  *   The parse result referencing the operator.
47  * @return
48  *   0 on success (*result must be set, operand is freed),
49  *   or -errno on error (*result is undefined, operand is not freed).
50  */
51 typedef int (*ec_node_expr_eval_pre_op_t)(
52         void **result, void *userctx,
53         void *operand,
54         const struct ec_pnode *operator);
55
56 typedef int (*ec_node_expr_eval_post_op_t)(
57         void **result, void *userctx,
58         void *operand,
59         const struct ec_pnode *operator);
60
61 typedef int (*ec_node_expr_eval_bin_op_t)(
62         void **result, void *userctx,
63         void *operand1,
64         const struct ec_pnode *operator,
65         void *operand2);
66
67 typedef int (*ec_node_expr_eval_parenthesis_t)(
68         void **result, void *userctx,
69         const struct ec_pnode *open_paren,
70         const struct ec_pnode *close_paren,
71         void * value);
72
73 typedef void (*ec_node_expr_eval_free_t)(
74         void *result, void *userctx);
75
76
77 struct ec_node *ec_node_expr(const char *id);
78 int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node);
79 int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op);
80 int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op);
81 int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op);
82 int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
83         struct ec_node *open, struct ec_node *close);
84
85 struct ec_node_expr_eval_ops {
86         ec_node_expr_eval_var_t eval_var;
87         ec_node_expr_eval_pre_op_t eval_pre_op;
88         ec_node_expr_eval_post_op_t eval_post_op;
89         ec_node_expr_eval_bin_op_t eval_bin_op;
90         ec_node_expr_eval_parenthesis_t eval_parenthesis;
91         ec_node_expr_eval_free_t eval_free;
92 };
93
94 int ec_node_expr_eval(void **result, const struct ec_node *node,
95         struct ec_pnode *parse, const struct ec_node_expr_eval_ops *ops,
96         void *userctx);
97
98 #endif
99
100 /** @} */