#ifndef TRE_AST_H
#define TRE_AST_H 1
#include <limits.h>
#include "tre-mem.h"
#include "tre-internal.h"
#include "tre-compile.h"
#include "tre-last-matched.h"
typedef enum {
LITERAL,
CATENATION,
ITERATION,
UNION
} tre_ast_type_t;
#define EMPTY -1
#define ASSERTION -2
#define TAG -3
#define BACKREF -4
#define PARAMETER -5
#define IS_SPECIAL(x) ((x)->code_min < 0)
#define IS_EMPTY(x) ((x)->code_min == EMPTY)
#define IS_ASSERTION(x) ((x)->code_min == ASSERTION)
#define IS_TAG(x) ((x)->code_min == TAG)
#define IS_BACKREF(x) ((x)->code_min == BACKREF)
#define IS_PARAMETER(x) ((x)->code_min == PARAMETER)
#define SUBMATCH_ID_INVISIBLE_START (INT_MAX / 2 + 1)
typedef struct _tre_ast_node {
void *obj;
tre_last_matched_branch_pre_t *last_matched_branch;
tre_last_matched_pre_t *last_matched_in_progress;
tre_pos_and_tags_t *firstpos;
tre_pos_and_tags_t *lastpos;
struct _tre_ast_node *original;
tre_ast_type_t type;
int submatch_id;
int num_submatches;
int num_tags;
short nullable;
short make_branches;
} tre_ast_node_t;
typedef struct {
tre_cint_t code_min;
tre_cint_t code_max;
int position;
union {
tre_bracket_match_list_t *bracket_match_list;
int *params;
} u;
} tre_literal_t;
typedef struct {
tre_ast_node_t *left;
tre_ast_node_t *right;
} tre_catenation_t;
typedef struct {
tre_ast_node_t *arg;
int min;
int max;
unsigned int minimal:1;
int *params;
} tre_iteration_t;
typedef struct {
tre_ast_node_t *left;
tre_ast_node_t *right;
int left_tag;
int right_tag;
} tre_union_t;
__private_extern__ tre_ast_node_t *
tre_ast_new_node(tre_mem_t mem, tre_ast_type_t type, size_t size);
__private_extern__ tre_ast_node_t *
tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position);
__private_extern__ tre_ast_node_t *
tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max,
int minimal);
__private_extern__ tre_ast_node_t *
tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right);
__private_extern__ tre_ast_node_t *
tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left,
tre_ast_node_t *right);
#ifdef TRE_DEBUG
void
tre_ast_print(tre_ast_node_t *tree);
void
tre_print_params(int *params);
#endif
#endif