regexJIT.h revision 1.1.1.2 1 1.1 alnsn /*
2 1.1 alnsn * Stack-less Just-In-Time compiler
3 1.1 alnsn *
4 1.1.1.2 alnsn * Copyright Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
5 1.1 alnsn *
6 1.1 alnsn * Redistribution and use in source and binary forms, with or without modification, are
7 1.1 alnsn * permitted provided that the following conditions are met:
8 1.1 alnsn *
9 1.1 alnsn * 1. Redistributions of source code must retain the above copyright notice, this list of
10 1.1 alnsn * conditions and the following disclaimer.
11 1.1 alnsn *
12 1.1 alnsn * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 1.1 alnsn * of conditions and the following disclaimer in the documentation and/or other materials
14 1.1 alnsn * provided with the distribution.
15 1.1 alnsn *
16 1.1 alnsn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 1.1 alnsn * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 alnsn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 1.1 alnsn * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 alnsn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 1.1 alnsn * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 1.1 alnsn * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 alnsn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1 alnsn * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 alnsn */
26 1.1 alnsn
27 1.1 alnsn #ifndef _REGEX_JIT_H_
28 1.1 alnsn #define _REGEX_JIT_H_
29 1.1 alnsn
30 1.1 alnsn /* Character type config. */
31 1.1 alnsn #define REGEX_USE_8BIT_CHARS
32 1.1 alnsn
33 1.1 alnsn #ifdef REGEX_USE_8BIT_CHARS
34 1.1 alnsn typedef char regex_char_t;
35 1.1 alnsn #else
36 1.1 alnsn typedef wchar_t regex_char_t;
37 1.1 alnsn #endif
38 1.1 alnsn
39 1.1 alnsn /* Error codes. */
40 1.1 alnsn #define REGEX_NO_ERROR 0
41 1.1 alnsn #define REGEX_MEMORY_ERROR 1
42 1.1 alnsn #define REGEX_INVALID_REGEX 2
43 1.1 alnsn
44 1.1 alnsn /* Note: large, nested {a,b} iterations can blow up the memory consumption
45 1.1 alnsn a{n,m} is replaced by aa...aaa?a?a?a?a? (n >= 0, m > 0)
46 1.1 alnsn \__n__/\____m___/
47 1.1 alnsn a{n,} is replaced by aa...aaa+ (n > 0)
48 1.1 alnsn \_n-1_/
49 1.1 alnsn */
50 1.1 alnsn
51 1.1 alnsn /* The value returned by regex_compile. Can be used for multiple matching. */
52 1.1 alnsn struct regex_machine;
53 1.1 alnsn
54 1.1 alnsn /* A matching state. */
55 1.1 alnsn struct regex_match;
56 1.1 alnsn
57 1.1 alnsn /* Note: REGEX_MATCH_BEGIN and REGEX_MATCH_END does not change the parsing
58 1.1 alnsn (Hence ^ and $ are parsed normally).
59 1.1 alnsn Force matching to start from begining of the string (same as ^). */
60 1.1 alnsn #define REGEX_MATCH_BEGIN 0x01
61 1.1 alnsn /* Force matching to continue until the last character (same as $). */
62 1.1 alnsn #define REGEX_MATCH_END 0x02
63 1.1 alnsn /* Changes . to [^\r\n]
64 1.1 alnsn Note: [...] and [^...] are NOT affected at all (as other regex engines do). */
65 1.1 alnsn #define REGEX_NEWLINE 0x04
66 1.1 alnsn /* Non greedy matching. In case of Thompson (non-recursive) algorithm,
67 1.1 alnsn it (usually) does not have a significant speed gain. */
68 1.1 alnsn #define REGEX_MATCH_NON_GREEDY 0x08
69 1.1 alnsn /* Verbose. This define can be commented out, which disables all verbose features. */
70 1.1 alnsn #define REGEX_MATCH_VERBOSE 0x10
71 1.1 alnsn
72 1.1 alnsn /* If error occures the function returns NULL, and the error code returned in error variable.
73 1.1 alnsn You can pass NULL to error if you don't care about the error code.
74 1.1 alnsn The re_flags argument contains the default REGEX_MATCH flags. See above. */
75 1.1 alnsn struct regex_machine* regex_compile(const regex_char_t *regex_string, int length, int re_flags, int *error);
76 1.1 alnsn void regex_free_machine(struct regex_machine *machine);
77 1.1 alnsn
78 1.1 alnsn /* Create and init match structure for a given machine. */
79 1.1 alnsn struct regex_match* regex_begin_match(struct regex_machine *machine);
80 1.1 alnsn void regex_reset_match(struct regex_match *match);
81 1.1 alnsn void regex_free_match(struct regex_match *match);
82 1.1 alnsn
83 1.1 alnsn /* Pattern matching.
84 1.1 alnsn regex_continue_match does not support REGEX_MATCH_VERBOSE flag. */
85 1.1 alnsn void regex_continue_match(struct regex_match *match, const regex_char_t *input_string, int length);
86 1.1 alnsn int regex_get_result(struct regex_match *match, int *end, int *id);
87 1.1 alnsn /* Returns true, if the best match has already found. */
88 1.1 alnsn int regex_is_match_finished(struct regex_match *match);
89 1.1 alnsn
90 1.1 alnsn /* Only exists if VERBOSE is defined in regexJIT.c
91 1.1 alnsn Do both sanity check and verbose.
92 1.1 alnsn (The latter only if REGEX_MATCH_VERBOSE was passed to regex_compile) */
93 1.1 alnsn void regex_continue_match_debug(struct regex_match *match, const regex_char_t *input_string, int length);
94 1.1 alnsn
95 1.1 alnsn /* Misc. */
96 1.1 alnsn const char* regex_get_platform_name(void);
97 1.1 alnsn
98 1.1 alnsn #endif
99