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