Back to index

php5  5.3.10
regsyntax.c
Go to the documentation of this file.
00001 /**********************************************************************
00002   regsyntax.c -  Oniguruma (regular expression library)
00003 **********************************************************************/
00004 /*-
00005  * Copyright (c) 2002-2006  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 #include "regint.h"
00031 
00032 OnigSyntaxType OnigSyntaxASIS = {
00033     0
00034   , ONIG_SYN_OP2_INEFFECTIVE_ESCAPE
00035   , 0
00036   , ONIG_OPTION_NONE
00037 };
00038 
00039 OnigSyntaxType OnigSyntaxPosixBasic = {
00040   ( SYN_POSIX_COMMON_OP | ONIG_SYN_OP_ESC_LPAREN_SUBEXP |
00041     ONIG_SYN_OP_ESC_BRACE_INTERVAL )
00042   , 0
00043   , 0
00044   , ( ONIG_OPTION_SINGLELINE | ONIG_OPTION_MULTILINE )
00045 };
00046 
00047 OnigSyntaxType OnigSyntaxPosixExtended = {
00048   ( SYN_POSIX_COMMON_OP | ONIG_SYN_OP_LPAREN_SUBEXP |
00049     ONIG_SYN_OP_BRACE_INTERVAL |
00050     ONIG_SYN_OP_PLUS_ONE_INF | ONIG_SYN_OP_QMARK_ZERO_ONE | ONIG_SYN_OP_VBAR_ALT )
00051   , 0
00052   , ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | 
00053       ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | 
00054       ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP |
00055       ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
00056   , ( ONIG_OPTION_SINGLELINE | ONIG_OPTION_MULTILINE )
00057 };
00058 
00059 OnigSyntaxType OnigSyntaxEmacs = {
00060   ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC |
00061     ONIG_SYN_OP_ESC_BRACE_INTERVAL |
00062     ONIG_SYN_OP_ESC_LPAREN_SUBEXP | ONIG_SYN_OP_ESC_VBAR_ALT |
00063     ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF |
00064     ONIG_SYN_OP_QMARK_ZERO_ONE | ONIG_SYN_OP_DECIMAL_BACKREF |
00065     ONIG_SYN_OP_LINE_ANCHOR | ONIG_SYN_OP_ESC_CONTROL_CHARS )
00066   , ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR
00067   , ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC
00068   , ONIG_OPTION_NONE
00069 };
00070 
00071 OnigSyntaxType OnigSyntaxGrep = {
00072   ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_POSIX_BRACKET |
00073     ONIG_SYN_OP_ESC_BRACE_INTERVAL | ONIG_SYN_OP_ESC_LPAREN_SUBEXP |
00074     ONIG_SYN_OP_ESC_VBAR_ALT |
00075     ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_ESC_PLUS_ONE_INF |
00076     ONIG_SYN_OP_ESC_QMARK_ZERO_ONE | ONIG_SYN_OP_LINE_ANCHOR |
00077     ONIG_SYN_OP_ESC_W_WORD | ONIG_SYN_OP_ESC_B_WORD_BOUND |
00078     ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | ONIG_SYN_OP_DECIMAL_BACKREF )
00079   , 0
00080   , ( ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC | ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC )
00081   , ONIG_OPTION_NONE
00082 };
00083 
00084 OnigSyntaxType OnigSyntaxGnuRegex = {
00085   SYN_GNU_REGEX_OP
00086   , 0
00087   , SYN_GNU_REGEX_BV
00088   , ONIG_OPTION_NONE
00089 };
00090 
00091 OnigSyntaxType OnigSyntaxJava = {
00092   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
00093      ONIG_SYN_OP_ESC_CONTROL_CHARS | ONIG_SYN_OP_ESC_C_CONTROL |
00094      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 )
00095    & ~ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END )
00096   , ( ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE | ONIG_SYN_OP2_QMARK_GROUP_EFFECT |
00097       ONIG_SYN_OP2_OPTION_PERL | ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT |
00098       ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL | ONIG_SYN_OP2_CCLASS_SET_OP |
00099       ONIG_SYN_OP2_ESC_V_VTAB | ONIG_SYN_OP2_ESC_U_HEX4 |
00100       ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY )
00101   , ( SYN_GNU_REGEX_BV | ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND )
00102   , ONIG_OPTION_SINGLELINE
00103 };
00104 
00105 OnigSyntaxType OnigSyntaxPerl = {
00106   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
00107      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
00108      ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
00109      ONIG_SYN_OP_ESC_C_CONTROL )
00110    & ~ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END )
00111   , ( ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE |
00112       ONIG_SYN_OP2_QMARK_GROUP_EFFECT | ONIG_SYN_OP2_OPTION_PERL |
00113       ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY |
00114       ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT |
00115       ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS )
00116   , SYN_GNU_REGEX_BV
00117   , ONIG_OPTION_SINGLELINE
00118 };
00119 
00120 /* Perl + named group */
00121 OnigSyntaxType OnigSyntaxPerl_NG = {
00122   (( SYN_GNU_REGEX_OP | ONIG_SYN_OP_QMARK_NON_GREEDY |
00123      ONIG_SYN_OP_ESC_OCTAL3 | ONIG_SYN_OP_ESC_X_HEX2 |
00124      ONIG_SYN_OP_ESC_X_BRACE_HEX8 | ONIG_SYN_OP_ESC_CONTROL_CHARS |
00125      ONIG_SYN_OP_ESC_C_CONTROL )
00126    & ~ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END )
00127   , ( ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE |
00128       ONIG_SYN_OP2_QMARK_GROUP_EFFECT | ONIG_SYN_OP2_OPTION_PERL |
00129       ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY  |
00130       ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT |
00131       ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS    |
00132       ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP       |
00133       ONIG_SYN_OP2_ESC_K_NAMED_BACKREF        |
00134       ONIG_SYN_OP2_ESC_G_SUBEXP_CALL )
00135   , ( SYN_GNU_REGEX_BV |
00136       ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP |
00137       ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME )
00138   , ONIG_OPTION_SINGLELINE
00139 };
00140 
00141 
00142 
00143 extern int
00144 onig_set_default_syntax(OnigSyntaxType* syntax)
00145 {
00146   if (IS_NULL(syntax))
00147     syntax = ONIG_SYNTAX_RUBY;
00148 
00149   OnigDefaultSyntax = syntax;
00150   return 0;
00151 }
00152 
00153 extern void
00154 onig_copy_syntax(OnigSyntaxType* to, OnigSyntaxType* from)
00155 {
00156   *to = *from;
00157 }
00158 
00159 extern void
00160 onig_set_syntax_op(OnigSyntaxType* syntax, unsigned int op)
00161 {
00162   syntax->op = op;
00163 }
00164 
00165 extern void
00166 onig_set_syntax_op2(OnigSyntaxType* syntax, unsigned int op2)
00167 {
00168   syntax->op2 = op2;
00169 }
00170 
00171 extern void
00172 onig_set_syntax_behavior(OnigSyntaxType* syntax, unsigned int behavior)
00173 {
00174   syntax->behavior = behavior;
00175 }
00176 
00177 extern void
00178 onig_set_syntax_options(OnigSyntaxType* syntax, OnigOptionType options)
00179 {
00180   syntax->options = options;
00181 }
00182 
00183 extern unsigned int
00184 onig_get_syntax_op(OnigSyntaxType* syntax)
00185 {
00186   return syntax->op;
00187 }
00188 
00189 extern unsigned int
00190 onig_get_syntax_op2(OnigSyntaxType* syntax)
00191 {
00192   return syntax->op2;
00193 }
00194 
00195 extern unsigned int
00196 onig_get_syntax_behavior(OnigSyntaxType* syntax)
00197 {
00198   return syntax->behavior;
00199 }
00200 
00201 extern OnigOptionType
00202 onig_get_syntax_options(OnigSyntaxType* syntax)
00203 {
00204   return syntax->options;
00205 }
00206 
00207 #ifdef USE_VARIABLE_META_CHARS
00208 extern int onig_set_meta_char(OnigEncoding enc,
00209                               unsigned int what, OnigCodePoint code)
00210 {
00211   switch (what) {
00212   case ONIG_META_CHAR_ESCAPE:
00213     enc->meta_char_table.esc = code;
00214     break;
00215   case ONIG_META_CHAR_ANYCHAR:
00216     enc->meta_char_table.anychar = code;
00217     break;
00218   case ONIG_META_CHAR_ANYTIME:
00219     enc->meta_char_table.anytime = code;
00220     break;
00221   case ONIG_META_CHAR_ZERO_OR_ONE_TIME:
00222     enc->meta_char_table.zero_or_one_time = code;
00223     break;
00224   case ONIG_META_CHAR_ONE_OR_MORE_TIME:
00225     enc->meta_char_table.one_or_more_time = code;
00226     break;
00227   case ONIG_META_CHAR_ANYCHAR_ANYTIME:
00228     enc->meta_char_table.anychar_anytime = code;
00229     break;
00230   default:
00231     return ONIGERR_INVALID_ARGUMENT;
00232     break;
00233   }
00234   return 0;
00235 }
00236 #endif /* USE_VARIABLE_META_CHARS */