20221212
[devspec.git] / devspec.en_US / project / recutils / src / rec-sex-ast.h
bloba461e1fda92755cbc523fe0a87f8c568adf8b2ea
1 /* -*- mode: C -*-
3 * File: rec-sex-ast.h
4 * Date: Tue Jan 12 17:07:59 2010
6 * GNU recutils - SEX Abstract Syntax Trees
8 */
10 /* Copyright (C) 2010-2019 Jose E. Marchesi */
12 /* This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #ifndef REC_SEX_AST_H
27 #define REC_SEX_AST_H
29 #include <config.h>
31 #include <stdbool.h>
33 enum rec_sex_ast_node_type_e
35 REC_SEX_NOVAL,
37 /* Operations. */
38 REC_SEX_OP_NEG,
39 REC_SEX_OP_ADD,
40 REC_SEX_OP_SUB,
41 REC_SEX_OP_MUL,
42 REC_SEX_OP_DIV,
43 REC_SEX_OP_MOD,
44 REC_SEX_OP_EQL,
45 REC_SEX_OP_NEQ,
46 REC_SEX_OP_MAT,
47 REC_SEX_OP_LT,
48 REC_SEX_OP_GT,
49 REC_SEX_OP_LTE,
50 REC_SEX_OP_GTE,
51 REC_SEX_OP_AND,
52 REC_SEX_OP_OR,
53 REC_SEX_OP_NOT,
54 REC_SEX_OP_SHA,
55 REC_SEX_OP_SAMETIME,
56 REC_SEX_OP_IMPLIES,
57 REC_SEX_OP_BEFORE,
58 REC_SEX_OP_AFTER,
59 REC_SEX_OP_COND,
60 REC_SEX_OP_CONCAT,
62 /* Values. */
63 REC_SEX_INT,
64 REC_SEX_REAL,
65 REC_SEX_STR,
66 REC_SEX_NAME
69 typedef struct rec_sex_ast_node_s *rec_sex_ast_node_t;
70 typedef struct rec_sex_ast_s *rec_sex_ast_t;
73 * Public functions.
77 /* Creation and destruction of ASTs. */
78 rec_sex_ast_t rec_sex_ast_new ();
79 void rec_sex_ast_destroy (rec_sex_ast_t ast);
81 /* Running the AST. */
82 /* Not here but in rec-sex.c int rec_sex_ast_run (rec_sex_ast_t ast, rec_record_t record); */
84 rec_sex_ast_node_t rec_sex_ast_top (rec_sex_ast_t ast);
85 void rec_sex_ast_set_top (rec_sex_ast_t ast, rec_sex_ast_node_t node);
87 /* Nodes management. */
88 rec_sex_ast_node_t rec_sex_ast_node_new (void);
89 void rec_sex_ast_node_destroy (rec_sex_ast_node_t node);
91 enum rec_sex_ast_node_type_e rec_sex_ast_node_type (rec_sex_ast_node_t node);
92 void rec_sex_ast_node_set_type (rec_sex_ast_node_t node,
93 enum rec_sex_ast_node_type_e type);
95 int rec_sex_ast_node_int (rec_sex_ast_node_t node);
96 void rec_sex_ast_node_set_int (rec_sex_ast_node_t node, int num);
97 double rec_sex_ast_node_real (rec_sex_ast_node_t node);
98 void rec_sex_ast_node_set_real (rec_sex_ast_node_t node, double num);
99 char *rec_sex_ast_node_str (rec_sex_ast_node_t node);
100 void rec_sex_ast_node_set_str (rec_sex_ast_node_t node, char *str);
101 const char *rec_sex_ast_node_name (rec_sex_ast_node_t node);
102 const char *rec_sex_ast_node_subname (rec_sex_ast_node_t node);
103 void rec_sex_ast_node_set_name (rec_sex_ast_node_t node, const char *name, const char *subname);
105 int rec_sex_ast_node_num_children (rec_sex_ast_node_t node);
107 rec_sex_ast_node_t rec_sex_ast_node_child (rec_sex_ast_node_t node,
108 int n);
110 void rec_sex_ast_node_link (rec_sex_ast_node_t parent,
111 rec_sex_ast_node_t child);
113 void rec_sex_ast_node_reset (rec_sex_ast_node_t node);
114 int rec_sex_ast_node_index (rec_sex_ast_node_t node);
115 void rec_sex_ast_node_set_index (rec_sex_ast_node_t node,
116 int index);
118 void rec_sex_ast_print (rec_sex_ast_t ast);
120 void rec_sex_ast_node_fix (rec_sex_ast_node_t node, char *val);
121 void rec_sex_ast_node_unfix (rec_sex_ast_node_t node);
122 bool rec_sex_ast_node_fixed (rec_sex_ast_node_t node);
123 char *rec_sex_ast_node_fixed_val (rec_sex_ast_node_t node);
125 /* This function returns 'true' if there is a node on AST of type
126 REC_SEX_NAME where NAME.name == NAME and NAME.idx <= IDX. */
127 bool rec_sex_ast_name_p (rec_sex_ast_t ast, const char *name, size_t idx);
129 /* This function returns 'true' if there is a node on AST of type
130 REC_SEX_NAME where NAME.name == NAME and the parent of the node is
131 of type REC_SEX_OP_SHA, i.e. it recognizes #NAME in the source. */
132 bool rec_sex_ast_hash_name_p (rec_sex_ast_t ast, const char *name);
134 #endif /* rec-sex-ast.h */
137 /* End of rec-sex-ast.h */