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