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 PASS, 00049 REGEX_END, 00050 } state_type; 00051 00052 char *character_class; 00053 int invert, loop_from, loop_to; 00054 00055 struct microregex_nfa_t *next1, *next2; 00056 }; 00057 00058 /****************************************************************************** 00059 * Main regular expression object. 00060 *****************************************************************************/ 00061 struct microregex_t 00062 { 00063 char *regex; 00064 int paren_count; 00065 char *err_string; 00066 microregex_nfa_t nfa; 00067 }; 00068 00069 /****************************************************************************** 00070 * Regular expression state object 00071 *****************************************************************************/ 00072 struct microregex_state_t 00073 { 00074 microregex_nfa_t state; 00075 int *se_stack; 00076 int se_size; 00077 char **ses; 00078 int num_ses; 00079 int match_begin; /* to facilitate split/replace */ 00080 int match_end; 00081 int loop_count; 00082 struct microregex_state_t *prev, *next; 00083 }; 00084 00085 #endif /* __MICROREGEX_INTERNAL */