tre_ast.hpp
00001 #line 1539 "./lpsrc/tre.pak"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TRE_AST_H
00023 #define TRE_AST_H 1
00024
00025 #include "tre_mem.hpp"
00026 #include "tre_internal.hpp"
00027 #include "tre_compile.hpp"
00028
00029
00030 typedef enum {
00031 LITERAL,
00032 CATENATION,
00033 ITERATION,
00034 UNION
00035 } tre_ast_type_t;
00036
00037
00038 #define EMPTY -1
00039 #define ASSERTION -2
00040 #define TAG -3
00041 #define BACKREF -4
00042 #define PARAMETER -5
00043
00044 #define IS_SPECIAL(x) ((x)->code_min < 0)
00045 #define IS_EMPTY(x) ((x)->code_min == EMPTY)
00046 #define IS_ASSERTION(x) ((x)->code_min == ASSERTION)
00047 #define IS_TAG(x) ((x)->code_min == TAG)
00048 #define IS_BACKREF(x) ((x)->code_min == BACKREF)
00049 #define IS_PARAMETER(x) ((x)->code_min == PARAMETER)
00050
00051
00052
00053
00054 typedef struct {
00055 tre_ast_type_t type;
00056 void *obj;
00057 int nullable;
00058 int submatch_id;
00059 int num_submatches;
00060 int num_tags;
00061 tre_pos_and_tags_t *firstpos;
00062 tre_pos_and_tags_t *lastpos;
00063 } tre_ast_node_t;
00064
00065
00066
00067
00068
00069 typedef struct {
00070 long code_min;
00071 long code_max;
00072 int position;
00073 union {
00074 tre_ctype_t klass;
00075 unsigned int *params;
00076 } u;
00077 tre_ctype_t *neg_klasses;
00078 } tre_literal_t;
00079
00080
00081
00082
00083
00084 typedef struct {
00085 tre_ast_node_t *left;
00086 tre_ast_node_t *right;
00087 } tre_catenation_t;
00088
00089
00090
00091 typedef struct {
00092
00093 tre_ast_node_t *arg;
00094
00095 int min;
00096
00097 int max;
00098
00099
00100
00101 unsigned int minimal:1;
00102
00103 unsigned int *params;
00104 } tre_iteration_t;
00105
00106
00107 typedef struct {
00108 tre_ast_node_t *left;
00109 tre_ast_node_t *right;
00110 } tre_union_t;
00111
00112 tre_ast_node_t *
00113 tre_ast_new_node(tre_mem_t mem, tre_ast_type_t type, size_t size);
00114
00115 tre_ast_node_t *
00116 tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position);
00117
00118 tre_ast_node_t *
00119 tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max,
00120 int minimal);
00121
00122 tre_ast_node_t *
00123 tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right);
00124
00125 tre_ast_node_t *
00126 tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left,
00127 tre_ast_node_t *right);
00128
00129 #ifdef TRE_DEBUG
00130 void
00131 tre_ast_print(tre_ast_node_t *tree);
00132
00133
00134 void
00135 tre_print_params(int *params);
00136 #endif
00137
00138 #endif
00139
00140