Added support for character mapping.
[idzebra-moved-to-github.git] / include / dfa.h
1 /*
2  * Copyright (C) 1994-1996, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dfa.h,v $
7  * Revision 1.6  1996-06-04 10:20:10  adam
8  * Added support for character mapping.
9  *
10  * Revision 1.5  1996/01/08  09:09:48  adam
11  * Function dfa_parse got 'const' string argument.
12  *
13  * Revision 1.4  1995/01/25  11:31:04  adam
14  * Simple error reporting when parsing regular expressions.
15  *
16  * Revision 1.3  1995/01/24  16:01:30  adam
17  * Added -ansi to CFLAGS.
18  * New functions and change of data structures.
19  *
20  * Revision 1.2  1994/09/26  16:31:23  adam
21  * Minor changes. xmalloc declares xcalloc now.
22  *
23  * Revision 1.1  1994/09/26  10:17:43  adam
24  * Dfa-module header files.
25  *
26  */
27
28 #ifndef DFA_H
29 #define DFA_H
30
31 #include <bset.h>
32 #include <set.h>
33
34 struct DFA_tran {
35     unsigned char ch[2];      /* transition on ch[0] <= c <= ch[1] to */
36     unsigned short to;        /* this state */
37 };
38
39 struct DFA_trans {
40     struct DFA_trans *next;   /* next DFA transition block */
41     struct DFA_tran *tran_block; /* pointer to transitions */
42     int  ptr;                 /* index of next transition in tran_block */
43     int  size;                /* allocated size of tran_block */
44 };
45
46 struct DFA_state {
47     struct DFA_state *next;   /* next entry in free/unmarked/marked list */
48     struct DFA_state *link;   /* link to next entry in hash chain */
49     struct DFA_tran *trans;   /* transition list */
50     Set set;                  /* set of positions (important nfa states) */
51     short no;                 /* no of this state */
52     short tran_no;            /* no of transitions to other states */
53     short rule_no;            /* if non-zero, this holds accept rule no */
54     short rule_nno;           /* accept rule no - except start rules */
55 };
56
57 struct DFA {
58     int no_states;
59     struct DFA_state  **states;
60     struct DFA_states *state_info;
61     struct DFA_parse  *parse_info;
62 };
63
64 struct DFA *dfa_init (void);
65 void dfa_set_cmap (struct DFA *dfa,
66                    char **(*cmap)(const char **from, int len));
67 int dfa_parse (struct DFA *, const char **);
68 void dfa_mkstate (struct DFA *);
69 void dfa_delete (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 #endif