045cd694b8674e2b6ecbf9bc83b042cba83cd4ea
[idzebra-moved-to-github.git] / include / dfa.h
1 /* $Id: dfa.h,v 1.16 2007-01-15 20:08:24 adam Exp $
2    Copyright (C) 1995-2007
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 #ifndef DFA_H
24 #define DFA_H
25
26 #include <bset.h>
27 #include <dfaset.h>
28
29 #include <yaz/yconfig.h>
30
31 YAZ_BEGIN_CDECL
32
33 struct DFA_tran {
34     unsigned char ch[2];      /* transition on ch[0] <= c <= ch[1] to */
35     unsigned short to;        /* this state */
36 };
37
38 struct DFA_trans {
39     struct DFA_trans *next;   /* next DFA transition block */
40     struct DFA_tran *tran_block; /* pointer to transitions */
41     int  ptr;                 /* index of next transition in tran_block */
42     int  size;                /* allocated size of tran_block */
43 };
44
45 struct DFA_state {
46     struct DFA_state *next;   /* next entry in free/unmarked/marked list */
47     struct DFA_state *link;   /* link to next entry in hash chain */
48     struct DFA_tran *trans;   /* transition list */
49     DFASet set;               /* set of positions (important nfa states) */
50     short no;                 /* no of this state */
51     short tran_no;            /* no of transitions to other states */
52     short rule_no;            /* if non-zero, this holds accept rule no */
53     short rule_nno;           /* accept rule no - except start rules */
54 };
55
56 struct DFA {
57     int no_states;
58     struct DFA_state  **states;
59     struct DFA_states *state_info;
60     struct DFA_parse  *parse_info;
61 };
62
63 struct DFA *dfa_init (void);
64 void dfa_set_cmap (struct DFA *dfa, void *vp,
65                    const char **(*cmap)(void *vp, const char **from, int len));
66 int dfa_parse (struct DFA *, const char **);
67 void dfa_mkstate (struct DFA *);
68 void dfa_delete (struct DFA **);
69 int dfa_get_last_rule (struct DFA *);
70
71 void dfa_parse_cmap_clean (struct DFA *d);
72 void dfa_parse_cmap_new (struct DFA *d, const int *cmap);
73 void dfa_parse_cmap_del (struct DFA *d, int from);
74 void dfa_parse_cmap_add (struct DFA *d, int from, int to);
75
76 extern int  debug_dfa_trav;
77 extern int  debug_dfa_tran;
78 extern int  debug_dfa_followpos;
79 extern int  dfa_verbose;
80
81 extern unsigned short
82         dfa_thompson_chars[],
83         dfa_ccl_chars[];
84
85 #define L_LP 1
86 #define L_RP 2
87 #define L_CHAR 3
88 #define L_CHARS 4
89 #define L_ANY 5
90 #define L_ALT 6
91 #define L_ANYZ 7
92 #define L_WILD 8
93 #define L_QUEST 9
94 #define L_CLOS1 10
95 #define L_CLOS0 11
96 #define L_END 12
97 #define L_START 13
98
99 #define DFA_ERR_SYNTAX 1
100 #define DFA_ERR_LP     2
101 #define DFA_ERR_RP     3
102
103 YAZ_END_CDECL
104
105 #endif
106 /*
107  * Local variables:
108  * c-basic-offset: 4
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113