RPA Toolkit
20ae56a6cb3e745e946b9cc1e9e1b0d1ed73b5a5
[rpatk.git] / rpa / rparecord.h
1 /*
2  *  Regular Pattern Analyzer (RPA)
3  *  Copyright (c) 2009-2010 Martin Stoilov
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  *  Martin Stoilov <martin@rpasearch.com>
19  */
20
21 /**
22  * \file rparecord.h
23  * \brief The public interface for working with the produced Abstract Syntax Tree (AST).
24  *
25  *
26  * <h2>Synopsis</h2>
27  * Upon a successful call to \ref rpa_stat_parse, the parser produces a stack of \ref rparecord_t records.
28  * There are two kinds of records: \ref RPA_RECORD_START and \ref RPA_RECORD_END. \ref RPA_RECORD_START marks
29  * the beginning of a branch and \ref RPA_RECORD_END marks the end of that branch. Empty branches are specified by
30  * a record \ref RPA_RECORD_START followed immediately by \ref RPA_RECORD_END (no child records in between).
31  * Empty branches are considered leaves.
32  *
33  */
34
35
36 #ifndef _RPARECORD_H_
37 #define _RPARECORD_H_
38
39 #include "rtypes.h"
40 #include "rarray.h"
41 #include "rlist.h"
42 #include "rpavm.h"
43
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #define RPA_RECORD_NONE (0)
50 #define RPA_RECORD_START (1 << 0)
51 #define RPA_RECORD_END (1 << 1)
52 //#define RPA_RECORD_MATCH (1 << 2)
53 #define RPA_RECORD_HEAD (1 << 3)
54 #define RPA_RECORD_TAIL (1 << 4)
55
56 #define RPA_RECORD_INVALID_UID ((ruint32)-1)
57
58 /**
59  * \typedef rparecord_t
60  * \brief Abstract Syntax Tree (AST) construction element.
61  */
62 typedef struct rparecord_s {
63         rlong next;
64         const rchar *rule;
65         const rchar *input;
66         rsize_t inputsiz;
67         ruint32 type;
68         ruint32 top;
69         ruint32 size;
70         ruint32 ruleuid;
71         ruint32 usertype;
72         rword userdata;
73 } rparecord_t;
74
75
76 typedef rlong (*rpa_recordtree_callback)(rarray_t *records, rlong rec, rpointer userdata);
77
78 rlong rpa_recordtree_walk(rarray_t *src, rlong rec, rlong level, rpa_recordtree_callback callaback, rpointer userdata);
79 rlong rpa_recordtree_get(rarray_t *records, rlong rec, rulong type);
80 rlong rpa_recordtree_firstchild(rarray_t *records, rlong rec, rulong type);
81 rlong rpa_recordtree_lastchild(rarray_t *records, rlong rec, rulong type);
82 rlong rpa_recordtree_next(rarray_t *records, rlong rec, rulong type);
83 rlong rpa_recordtree_prev(rarray_t *records, rlong rec, rulong type);
84 rlong rpa_recordtree_parent(rarray_t *records, rlong rec, rulong type);
85 rlong rpa_recordtree_rotatedown(rarray_t *records, rlong parent);                       /* Rotate children down, the last child becomes the first */
86 rlong rpa_recordtree_size(rarray_t *records, rlong rec);                                        /* Size of the tree */
87 rlong rpa_recordtree_copy(rarray_t *dst, rarray_t *src, rlong rec);
88 rparecord_t *rpa_record_get(rarray_t *records, rlong rec);
89
90 void rpa_record_dumpindented(rarray_t *records, rlong rec, rinteger level);
91 void rpa_record_dump(rarray_t *records, rlong rec);
92 rlong rpa_record_getruleuid(rarray_t *records, rlong rec);
93 void rpa_record_setusertype(rarray_t *records, rlong rec, ruint32 usertype, rvalset_t op);
94 rlong rpa_record_getusertype(rarray_t *records, rlong rec);
95 rinteger rpa_record_optchar(rparecord_t *prec, rinteger defc);
96 rinteger rpa_record_loopchar(rparecord_t *prec, rinteger defc);
97 rarray_t *rpa_records_create();
98 void rpa_records_destroy(rarray_t *records);
99 rlong rpa_records_length(rarray_t *records);
100 rparecord_t *rpa_records_slot(rarray_t *records, rlong index);
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif