4 * Date: Tue Jan 12 17:07:59 2010
6 * GNU recutils - SEX Abstract Syntax Trees
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/>.
33 enum rec_sex_ast_node_type_e
69 typedef struct rec_sex_ast_node_s
*rec_sex_ast_node_t
;
70 typedef struct rec_sex_ast_s
*rec_sex_ast_t
;
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
,
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
,
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 */