00001 /***************************************************************************** 00002 * Copyright (c) 2008, Mooneer Salem 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Neither the name of the Kite Language organization nor the 00013 * names of its contributors may be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY MOONEER SALEM ``AS IS'' AND ANY 00017 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL MOONEER SALEM BE LIABLE FOR ANY 00020 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00023 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00025 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ****************************************************************************/ 00027 00028 #ifndef __MICROREGEX_INTERNAL 00029 #define __MICROREGEX_INTERNAL 00030 00031 #include "microregex.h" 00032 00033 /****************************************************************************** 00034 * NFA state object 00035 *****************************************************************************/ 00036 struct microregex_nfa_t 00037 { 00038 enum { 00039 PUSH_SUBMATCH, 00040 POP_SUBMATCH, 00041 CHARACTER_CLASS, 00042 ALTERATION, 00043 ASSERT_BEGINNING, 00044 ASSERT_END, 00045 COUNTED_BEGIN, 00046 COUNTED_LOOP, 00047 COUNTED_END, 00048 BACKTRACK_CHECK, 00049 PASS, 00050 WORD_BOUNDARY, 00051 REGEX_END, 00052 } state_type; 00053 00054 char *character_class; 00055 int invert, loop_from, loop_to; 00056 00057 struct microregex_nfa_t *next1, *next2; 00058 }; 00059 00060 /****************************************************************************** 00061 * Main regular expression object. 00062 *****************************************************************************/ 00063 struct microregex_t 00064 { 00065 char *regex; 00066 int paren_count; 00067 char *err_string; 00068 int case_insensitive; 00069 microregex_nfa_t nfa; 00070 }; 00071 00072 /****************************************************************************** 00073 * Regular expression state object 00074 *****************************************************************************/ 00075 struct microregex_state_t 00076 { 00077 microregex_nfa_t state; 00078 int insensitive; 00079 int *se_stack; 00080 int se_size; 00081 char **ses; 00082 int num_ses; 00083 int match_begin; /* to facilitate split/replace */ 00084 int match_end; 00085 int loop_count; 00086 struct microregex_state_t *prev, *next; 00087 }; 00088 00089 #endif /* __MICROREGEX_INTERNAL */