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