2004-03-05 18:31:51 +03:00
|
|
|
/**********************************************************************
|
2012-02-17 11:42:23 +04:00
|
|
|
regcomp.c - Onigmo (Oniguruma-mod) (regular expression library)
|
2004-03-05 18:31:51 +03:00
|
|
|
**********************************************************************/
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
/*-
|
2010-03-02 00:54:59 +03:00
|
|
|
* Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
2013-03-01 20:36:37 +04:00
|
|
|
* Copyright (c) 2011-2013 K.Takata <kentkt AT csc DOT jp>
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#include "regparse.h"
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigCaseFoldType OnigDefaultCaseFoldFlag = ONIGENC_CASE_FOLD_MIN;
|
2005-02-13 04:54:52 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
extern OnigCaseFoldType
|
|
|
|
onig_get_default_case_fold_flag(void)
|
2005-02-13 04:54:52 +03:00
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
return OnigDefaultCaseFoldFlag;
|
2005-02-13 04:54:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_set_default_case_fold_flag(OnigCaseFoldType case_fold_flag)
|
2005-02-13 04:54:52 +03:00
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigDefaultCaseFoldFlag = case_fold_flag;
|
2005-02-13 04:54:52 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
|
|
|
|
static unsigned char PadBuf[WORD_ALIGNMENT_SIZE];
|
|
|
|
#endif
|
|
|
|
|
2012-02-18 19:41:59 +04:00
|
|
|
#if 0
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
static UChar*
|
2007-05-23 05:32:08 +04:00
|
|
|
str_dup(UChar* s, UChar* end)
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
{
|
2009-06-30 06:08:54 +04:00
|
|
|
ptrdiff_t len = end - s;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
|
|
|
if (len > 0) {
|
|
|
|
UChar* r = (UChar* )xmalloc(len + 1);
|
|
|
|
CHECK_NULL_RETURN(r);
|
|
|
|
xmemcpy(r, s, len);
|
|
|
|
r[len] = (UChar )0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else return NULL;
|
|
|
|
}
|
2012-02-18 19:41:59 +04:00
|
|
|
#endif
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static void
|
|
|
|
swap_node(Node* a, Node* b)
|
|
|
|
{
|
|
|
|
Node c;
|
|
|
|
c = *a; *a = *b; *b = c;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(a) == NT_STR) {
|
|
|
|
StrNode* sn = NSTR(a);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (sn->capa == 0) {
|
2009-06-30 06:08:54 +04:00
|
|
|
size_t len = sn->end - sn->s;
|
2007-05-23 05:32:08 +04:00
|
|
|
sn->s = sn->buf;
|
|
|
|
sn->end = sn->s + len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(b) == NT_STR) {
|
|
|
|
StrNode* sn = NSTR(b);
|
2007-05-23 05:32:08 +04:00
|
|
|
if (sn->capa == 0) {
|
2009-06-30 06:08:54 +04:00
|
|
|
size_t len = sn->end - sn->s;
|
2007-05-23 05:32:08 +04:00
|
|
|
sn->s = sn->buf;
|
|
|
|
sn->end = sn->s + len;
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static OnigDistance
|
|
|
|
distance_add(OnigDistance d1, OnigDistance d2)
|
|
|
|
{
|
|
|
|
if (d1 == ONIG_INFINITE_DISTANCE || d2 == ONIG_INFINITE_DISTANCE)
|
|
|
|
return ONIG_INFINITE_DISTANCE;
|
|
|
|
else {
|
|
|
|
if (d1 <= ONIG_INFINITE_DISTANCE - d2) return d1 + d2;
|
|
|
|
else return ONIG_INFINITE_DISTANCE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static OnigDistance
|
|
|
|
distance_multiply(OnigDistance d, int m)
|
|
|
|
{
|
|
|
|
if (m == 0) return 0;
|
|
|
|
|
|
|
|
if (d < ONIG_INFINITE_DISTANCE / m)
|
|
|
|
return d * m;
|
|
|
|
else
|
|
|
|
return ONIG_INFINITE_DISTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bitset_is_empty(BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i;
|
2013-03-01 20:36:37 +04:00
|
|
|
for (i = 0; i < BITSET_SIZE; i++) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (bs[i] != 0) return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG
|
2010-11-26 03:24:28 +03:00
|
|
|
static int
|
|
|
|
onig_is_prelude(void)
|
|
|
|
{
|
|
|
|
return !rb_const_defined(rb_cThread, rb_intern_const("MUTEX_FOR_THREAD_EXCLUSIVE"));
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
bitset_on_num(BitSetRef bs)
|
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
|
|
|
|
if (BITSET_AT(bs, i)) n++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int
|
2011-01-31 06:44:57 +03:00
|
|
|
onig_bbuf_init(BBuf* buf, OnigDistance size)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
if (size <= 0) {
|
|
|
|
size = 0;
|
|
|
|
buf->p = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf->p = (UChar* )xmalloc(size);
|
|
|
|
if (IS_NULL(buf->p)) return(ONIGERR_MEMORY);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
buf->alloc = (unsigned int )size;
|
2004-03-05 18:31:51 +03:00
|
|
|
buf->used = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
|
|
|
|
static int
|
|
|
|
unset_addr_list_init(UnsetAddrList* uslist, int size)
|
|
|
|
{
|
|
|
|
UnsetAddr* p;
|
|
|
|
|
|
|
|
p = (UnsetAddr* )xmalloc(sizeof(UnsetAddr)* size);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
2004-03-05 18:31:51 +03:00
|
|
|
uslist->num = 0;
|
|
|
|
uslist->alloc = size;
|
|
|
|
uslist->us = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unset_addr_list_end(UnsetAddrList* uslist)
|
|
|
|
{
|
|
|
|
if (IS_NOT_NULL(uslist->us))
|
|
|
|
xfree(uslist->us);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unset_addr_list_add(UnsetAddrList* uslist, int offset, struct _Node* node)
|
|
|
|
{
|
|
|
|
UnsetAddr* p;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (uslist->num >= uslist->alloc) {
|
|
|
|
size = uslist->alloc * 2;
|
|
|
|
p = (UnsetAddr* )xrealloc(uslist->us, sizeof(UnsetAddr) * size);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
2004-03-05 18:31:51 +03:00
|
|
|
uslist->alloc = size;
|
|
|
|
uslist->us = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
uslist->us[uslist->num].offset = offset;
|
|
|
|
uslist->us[uslist->num].target = node;
|
|
|
|
uslist->num++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* USE_SUBEXP_CALL */
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_opcode(regex_t* reg, int opcode)
|
|
|
|
{
|
|
|
|
BBUF_ADD1(reg, opcode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-27 16:58:22 +04:00
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
|
|
|
static int
|
|
|
|
add_state_check_num(regex_t* reg, int num)
|
|
|
|
{
|
|
|
|
StateCheckNumType n = (StateCheckNumType )num;
|
|
|
|
|
|
|
|
BBUF_ADD(reg, &n, SIZE_STATE_CHECK_NUM);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
|
|
|
add_rel_addr(regex_t* reg, int addr)
|
|
|
|
{
|
|
|
|
RelAddrType ra = (RelAddrType )addr;
|
|
|
|
|
|
|
|
BBUF_ADD(reg, &ra, SIZE_RELADDR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_abs_addr(regex_t* reg, int addr)
|
|
|
|
{
|
|
|
|
AbsAddrType ra = (AbsAddrType )addr;
|
|
|
|
|
|
|
|
BBUF_ADD(reg, &ra, SIZE_ABSADDR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-01-31 06:44:57 +03:00
|
|
|
add_length(regex_t* reg, OnigDistance len)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
LengthType l = (LengthType )len;
|
|
|
|
|
|
|
|
BBUF_ADD(reg, &l, SIZE_LENGTH);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_mem_num(regex_t* reg, int num)
|
|
|
|
{
|
|
|
|
MemNumType n = (MemNumType )num;
|
|
|
|
|
|
|
|
BBUF_ADD(reg, &n, SIZE_MEMNUM);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_pointer(regex_t* reg, void* addr)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
PointerType ptr = (PointerType )addr;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
BBUF_ADD(reg, &ptr, SIZE_POINTER);
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_option(regex_t* reg, OnigOptionType option)
|
|
|
|
{
|
|
|
|
BBUF_ADD(reg, &option, SIZE_OPTION);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_opcode_rel_addr(regex_t* reg, int opcode, int addr)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = add_opcode(reg, opcode);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_rel_addr(reg, addr);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-01-31 06:44:57 +03:00
|
|
|
add_bytes(regex_t* reg, UChar* bytes, OnigDistance len)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
BBUF_ADD(reg, bytes, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_bitset(regex_t* reg, BitSetRef bs)
|
|
|
|
{
|
|
|
|
BBUF_ADD(reg, bs, SIZE_BITSET);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_opcode_option(regex_t* reg, int opcode, OnigOptionType option)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = add_opcode(reg, opcode);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_option(reg, option);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compile_length_tree(Node* node, regex_t* reg);
|
|
|
|
static int compile_tree(Node* node, regex_t* reg);
|
|
|
|
|
|
|
|
|
|
|
|
#define IS_NEED_STR_LEN_OP_EXACT(op) \
|
|
|
|
((op) == OP_EXACTN || (op) == OP_EXACTMB2N ||\
|
|
|
|
(op) == OP_EXACTMB3N || (op) == OP_EXACTMBN || (op) == OP_EXACTN_IC)
|
|
|
|
|
|
|
|
static int
|
2011-01-31 06:44:57 +03:00
|
|
|
select_str_opcode(int mb_len, OnigDistance str_len, int ignore_case)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int op;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (ignore_case) {
|
|
|
|
switch (str_len) {
|
|
|
|
case 1: op = OP_EXACT1_IC; break;
|
|
|
|
default: op = OP_EXACTN_IC; break;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (mb_len) {
|
|
|
|
case 1:
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (str_len) {
|
|
|
|
case 1: op = OP_EXACT1; break;
|
|
|
|
case 2: op = OP_EXACT2; break;
|
|
|
|
case 3: op = OP_EXACT3; break;
|
|
|
|
case 4: op = OP_EXACT4; break;
|
|
|
|
case 5: op = OP_EXACT5; break;
|
|
|
|
default: op = OP_EXACTN; break;
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case 2:
|
|
|
|
switch (str_len) {
|
|
|
|
case 1: op = OP_EXACTMB2N1; break;
|
|
|
|
case 2: op = OP_EXACTMB2N2; break;
|
|
|
|
case 3: op = OP_EXACTMB2N3; break;
|
|
|
|
default: op = OP_EXACTMB2N; break;
|
|
|
|
}
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case 3:
|
|
|
|
op = OP_EXACTMB3N;
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
default:
|
|
|
|
op = OP_EXACTMBN;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_tree_empty_check(Node* node, regex_t* reg, int empty_info)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
int saved_num_null_check = reg->num_null_check;
|
|
|
|
|
|
|
|
if (empty_info != 0) {
|
|
|
|
r = add_opcode(reg, OP_NULL_CHECK_START);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, reg->num_null_check); /* NULL CHECK ID */
|
|
|
|
if (r) return r;
|
|
|
|
reg->num_null_check++;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = compile_tree(node, reg);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
if (empty_info != 0) {
|
|
|
|
if (empty_info == NQ_TARGET_IS_EMPTY)
|
|
|
|
r = add_opcode(reg, OP_NULL_CHECK_END);
|
|
|
|
else if (empty_info == NQ_TARGET_IS_EMPTY_MEM)
|
|
|
|
r = add_opcode(reg, OP_NULL_CHECK_END_MEMST);
|
|
|
|
else if (empty_info == NQ_TARGET_IS_EMPTY_REC)
|
|
|
|
r = add_opcode(reg, OP_NULL_CHECK_END_MEMST_PUSH);
|
|
|
|
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, saved_num_null_check); /* NULL CHECK ID */
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
static int
|
|
|
|
compile_call(CallNode* node, regex_t* reg)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = add_opcode(reg, OP_CALL);
|
|
|
|
if (r) return r;
|
|
|
|
r = unset_addr_list_add(node->unset_addr_list, BBUF_GET_OFFSET_POS(reg),
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
node->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;
|
|
|
|
r = add_abs_addr(reg, 0 /*dummy addr.*/);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_tree_n_times(Node* node, int n, regex_t* reg)
|
|
|
|
{
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
r = compile_tree(node, reg);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-30 06:08:54 +04:00
|
|
|
add_compile_string_length(UChar* s ARG_UNUSED, int mb_len, OnigDistance str_len,
|
2008-01-03 18:55:04 +03:00
|
|
|
regex_t* reg ARG_UNUSED, int ignore_case)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int op = select_str_opcode(mb_len, str_len, ignore_case);
|
|
|
|
|
|
|
|
len = SIZE_OPCODE;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (op == OP_EXACTMBN) len += SIZE_LENGTH;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NEED_STR_LEN_OP_EXACT(op))
|
|
|
|
len += SIZE_LENGTH;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
len += mb_len * (int )str_len;
|
2004-03-05 18:31:51 +03:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-01-31 06:44:57 +03:00
|
|
|
add_compile_string(UChar* s, int mb_len, OnigDistance str_len,
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
regex_t* reg, int ignore_case)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int op = select_str_opcode(mb_len, str_len, ignore_case);
|
|
|
|
add_opcode(reg, op);
|
|
|
|
|
|
|
|
if (op == OP_EXACTMBN)
|
|
|
|
add_length(reg, mb_len);
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (IS_NEED_STR_LEN_OP_EXACT(op)) {
|
|
|
|
if (op == OP_EXACTN_IC)
|
|
|
|
add_length(reg, mb_len * str_len);
|
|
|
|
else
|
|
|
|
add_length(reg, str_len);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
add_bytes(reg, s, mb_len * str_len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
compile_length_string_node(Node* node, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int rlen, r, len, prev_len, slen, ambig;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigEncoding enc = reg->enc;
|
|
|
|
UChar *p, *prev;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
StrNode* sn;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
sn = NSTR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (sn->end <= sn->s)
|
|
|
|
return 0;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
ambig = NSTRING_IS_AMBIG(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
p = prev = sn->s;
|
2008-01-03 18:55:04 +03:00
|
|
|
prev_len = enclen(enc, p, sn->end);
|
2004-03-05 18:31:51 +03:00
|
|
|
p += prev_len;
|
|
|
|
slen = 1;
|
|
|
|
rlen = 0;
|
|
|
|
|
|
|
|
for (; p < sn->end; ) {
|
2008-01-03 18:55:04 +03:00
|
|
|
len = enclen(enc, p, sn->end);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (len == prev_len) {
|
|
|
|
slen++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_compile_string_length(prev, prev_len, slen, reg, ambig);
|
|
|
|
rlen += r;
|
|
|
|
prev = p;
|
|
|
|
slen = 1;
|
|
|
|
prev_len = len;
|
|
|
|
}
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
r = add_compile_string_length(prev, prev_len, slen, reg, ambig);
|
|
|
|
rlen += r;
|
|
|
|
return rlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_length_string_raw_node(StrNode* sn, regex_t* reg)
|
|
|
|
{
|
|
|
|
if (sn->end <= sn->s)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return add_compile_string_length(sn->s, 1 /* sb */, sn->end - sn->s, reg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
compile_string_node(Node* node, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int r, len, prev_len, slen, ambig;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigEncoding enc = reg->enc;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
UChar *p, *prev, *end;
|
|
|
|
StrNode* sn;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
sn = NSTR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (sn->end <= sn->s)
|
|
|
|
return 0;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
end = sn->end;
|
|
|
|
ambig = NSTRING_IS_AMBIG(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
p = prev = sn->s;
|
2008-01-03 18:55:04 +03:00
|
|
|
prev_len = enclen(enc, p, end);
|
2004-03-05 18:31:51 +03:00
|
|
|
p += prev_len;
|
|
|
|
slen = 1;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
for (; p < end; ) {
|
2008-01-03 18:55:04 +03:00
|
|
|
len = enclen(enc, p, end);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (len == prev_len) {
|
|
|
|
slen++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_compile_string(prev, prev_len, slen, reg, ambig);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
prev = p;
|
|
|
|
slen = 1;
|
|
|
|
prev_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
return add_compile_string(prev, prev_len, slen, reg, ambig);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_string_raw_node(StrNode* sn, regex_t* reg)
|
|
|
|
{
|
|
|
|
if (sn->end <= sn->s)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return add_compile_string(sn->s, 1 /* sb */, sn->end - sn->s, reg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_multi_byte_cclass(BBuf* mbuf, regex_t* reg)
|
|
|
|
{
|
|
|
|
#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
|
|
|
|
add_length(reg, mbuf->used);
|
|
|
|
return add_bytes(reg, mbuf->p, mbuf->used);
|
|
|
|
#else
|
|
|
|
int r, pad_size;
|
|
|
|
UChar* p = BBUF_GET_ADD_ADDRESS(reg) + SIZE_LENGTH;
|
|
|
|
|
|
|
|
GET_ALIGNMENT_PAD_SIZE(p, pad_size);
|
|
|
|
add_length(reg, mbuf->used + (WORD_ALIGNMENT_SIZE - 1));
|
|
|
|
if (pad_size != 0) add_bytes(reg, PadBuf, pad_size);
|
|
|
|
|
|
|
|
r = add_bytes(reg, mbuf->p, mbuf->used);
|
|
|
|
|
|
|
|
/* padding for return value from compile_length_cclass_node() to be fix. */
|
|
|
|
pad_size = (WORD_ALIGNMENT_SIZE - 1) - pad_size;
|
|
|
|
if (pad_size != 0) add_bytes(reg, PadBuf, pad_size);
|
|
|
|
return r;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_length_cclass_node(CClassNode* cc, regex_t* reg)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NCCLASS_SHARE(cc)) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
len = SIZE_OPCODE + SIZE_POINTER;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NULL(cc->mbuf)) {
|
|
|
|
len = SIZE_OPCODE + SIZE_BITSET;
|
|
|
|
}
|
|
|
|
else {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (ONIGENC_MBC_MINLEN(reg->enc) > 1 || bitset_is_empty(cc->bs)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
len = SIZE_OPCODE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = SIZE_OPCODE + SIZE_BITSET;
|
|
|
|
}
|
|
|
|
#ifdef PLATFORM_UNALIGNED_WORD_ACCESS
|
|
|
|
len += SIZE_LENGTH + cc->mbuf->used;
|
|
|
|
#else
|
|
|
|
len += SIZE_LENGTH + cc->mbuf->used + (WORD_ALIGNMENT_SIZE - 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_cclass_node(CClassNode* cc, regex_t* reg)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NCCLASS_SHARE(cc)) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_opcode(reg, OP_CCLASS_NODE);
|
|
|
|
r = add_pointer(reg, cc);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NULL(cc->mbuf)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NCCLASS_NOT(cc))
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_opcode(reg, OP_CCLASS_NOT);
|
|
|
|
else
|
|
|
|
add_opcode(reg, OP_CCLASS);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
r = add_bitset(reg, cc->bs);
|
|
|
|
}
|
|
|
|
else {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (ONIGENC_MBC_MINLEN(reg->enc) > 1 || bitset_is_empty(cc->bs)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NCCLASS_NOT(cc))
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_opcode(reg, OP_CCLASS_MB_NOT);
|
|
|
|
else
|
|
|
|
add_opcode(reg, OP_CCLASS_MB);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
r = add_multi_byte_cclass(cc->mbuf, reg);
|
|
|
|
}
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NCCLASS_NOT(cc))
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_opcode(reg, OP_CCLASS_MIX_NOT);
|
|
|
|
else
|
|
|
|
add_opcode(reg, OP_CCLASS_MIX);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
r = add_bitset(reg, cc->bs);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_multi_byte_cclass(cc->mbuf, reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
entry_repeat_range(regex_t* reg, int id, int lower, int upper)
|
|
|
|
{
|
|
|
|
#define REPEAT_RANGE_ALLOC 4
|
|
|
|
|
|
|
|
OnigRepeatRange* p;
|
|
|
|
|
|
|
|
if (reg->repeat_range_alloc == 0) {
|
|
|
|
p = (OnigRepeatRange* )xmalloc(sizeof(OnigRepeatRange) * REPEAT_RANGE_ALLOC);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->repeat_range = p;
|
|
|
|
reg->repeat_range_alloc = REPEAT_RANGE_ALLOC;
|
|
|
|
}
|
|
|
|
else if (reg->repeat_range_alloc <= id) {
|
|
|
|
int n;
|
|
|
|
n = reg->repeat_range_alloc + REPEAT_RANGE_ALLOC;
|
|
|
|
p = (OnigRepeatRange* )xrealloc(reg->repeat_range,
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
sizeof(OnigRepeatRange) * n);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(p);
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->repeat_range = p;
|
|
|
|
reg->repeat_range_alloc = n;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = reg->repeat_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
p[id].lower = lower;
|
2006-08-27 16:58:22 +04:00
|
|
|
p[id].upper = (IS_REPEAT_INFINITE(upper) ? 0x7fffffff : upper);
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_range_repeat_node(QtfrNode* qn, int target_len, int empty_info,
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
int num_repeat = reg->num_repeat;
|
|
|
|
|
|
|
|
r = add_opcode(reg, qn->greedy ? OP_REPEAT : OP_REPEAT_NG);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, num_repeat); /* OP_REPEAT ID */
|
|
|
|
reg->num_repeat++;
|
|
|
|
if (r) return r;
|
|
|
|
r = add_rel_addr(reg, target_len + SIZE_OP_REPEAT_INC);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
r = entry_repeat_range(reg, num_repeat, qn->lower, qn->upper);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
|
2004-10-30 10:56:18 +04:00
|
|
|
if (
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2004-10-30 10:56:18 +04:00
|
|
|
reg->num_call > 0 ||
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#endif
|
2007-05-23 05:32:08 +04:00
|
|
|
IS_QUANTIFIER_IN_REPEAT(qn)) {
|
2004-10-30 10:56:18 +04:00
|
|
|
r = add_opcode(reg, qn->greedy ? OP_REPEAT_INC_SG : OP_REPEAT_INC_NG_SG);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode(reg, qn->greedy ? OP_REPEAT_INC : OP_REPEAT_INC_NG);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, num_repeat); /* OP_REPEAT ID */
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-08-27 16:58:22 +04:00
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
is_anychar_star_quantifier(QtfrNode* qn)
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
if (qn->greedy && IS_REPEAT_INFINITE(qn->upper) &&
|
2007-07-23 13:39:30 +04:00
|
|
|
NTYPE(qn->target) == NT_CANY)
|
2006-08-27 16:58:22 +04:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
#define QUANTIFIER_EXPAND_LIMIT_SIZE 50
|
2006-08-27 16:58:22 +04:00
|
|
|
#define CKN_ON (ckn > 0)
|
|
|
|
|
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_length_quantifier_node(QtfrNode* qn, regex_t* reg)
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
int len, mod_tlen, cklen;
|
|
|
|
int ckn;
|
|
|
|
int infinite = IS_REPEAT_INFINITE(qn->upper);
|
|
|
|
int empty_info = qn->target_empty_info;
|
|
|
|
int tlen = compile_length_tree(qn->target, reg);
|
|
|
|
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
|
|
|
|
ckn = ((reg->num_comb_exp_check > 0) ? qn->comb_exp_check_num : 0);
|
|
|
|
|
|
|
|
cklen = (CKN_ON ? SIZE_STATE_CHECK_NUM: 0);
|
|
|
|
|
|
|
|
/* anychar repeat */
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(qn->target) == NT_CANY) {
|
2006-08-27 16:58:22 +04:00
|
|
|
if (qn->greedy && infinite) {
|
|
|
|
if (IS_NOT_NULL(qn->next_head_exact) && !CKN_ON)
|
|
|
|
return SIZE_OP_ANYCHAR_STAR_PEEK_NEXT + tlen * qn->lower + cklen;
|
|
|
|
else
|
|
|
|
return SIZE_OP_ANYCHAR_STAR + tlen * qn->lower + cklen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty_info != 0)
|
|
|
|
mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
|
|
|
|
else
|
|
|
|
mod_tlen = tlen;
|
|
|
|
|
|
|
|
if (infinite && qn->lower <= 1) {
|
|
|
|
if (qn->greedy) {
|
|
|
|
if (qn->lower == 1)
|
|
|
|
len = SIZE_OP_JUMP;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
len += SIZE_OP_PUSH + cklen + mod_tlen + SIZE_OP_JUMP;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (qn->lower == 0)
|
|
|
|
len = SIZE_OP_JUMP;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
len += mod_tlen + SIZE_OP_PUSH + cklen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (qn->upper == 0) {
|
|
|
|
if (qn->is_refered != 0) /* /(?<n>..){0}/ */
|
|
|
|
len = SIZE_OP_JUMP + tlen;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
else if (qn->upper == 1 && qn->greedy) {
|
|
|
|
if (qn->lower == 0) {
|
|
|
|
if (CKN_ON) {
|
|
|
|
len = SIZE_OP_STATE_CHECK_PUSH + tlen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = SIZE_OP_PUSH + tlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = tlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
|
|
|
|
len = SIZE_OP_PUSH + cklen + SIZE_OP_JUMP + tlen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = SIZE_OP_REPEAT_INC
|
|
|
|
+ mod_tlen + SIZE_OPCODE + SIZE_RELADDR + SIZE_MEMNUM;
|
|
|
|
if (CKN_ON)
|
|
|
|
len += SIZE_OP_STATE_CHECK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_quantifier_node(QtfrNode* qn, regex_t* reg)
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
int r, mod_tlen;
|
|
|
|
int ckn;
|
|
|
|
int infinite = IS_REPEAT_INFINITE(qn->upper);
|
|
|
|
int empty_info = qn->target_empty_info;
|
|
|
|
int tlen = compile_length_tree(qn->target, reg);
|
|
|
|
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
|
|
|
|
ckn = ((reg->num_comb_exp_check > 0) ? qn->comb_exp_check_num : 0);
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (is_anychar_star_quantifier(qn)) {
|
2006-08-27 16:58:22 +04:00
|
|
|
r = compile_tree_n_times(qn->target, qn->lower, reg);
|
|
|
|
if (r) return r;
|
|
|
|
if (IS_NOT_NULL(qn->next_head_exact) && !CKN_ON) {
|
|
|
|
if (IS_MULTILINE(reg->options))
|
|
|
|
r = add_opcode(reg, OP_ANYCHAR_ML_STAR_PEEK_NEXT);
|
|
|
|
else
|
|
|
|
r = add_opcode(reg, OP_ANYCHAR_STAR_PEEK_NEXT);
|
|
|
|
if (r) return r;
|
|
|
|
if (CKN_ON) {
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
return add_bytes(reg, NSTR(qn->next_head_exact)->s, 1);
|
2006-08-27 16:58:22 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_MULTILINE(reg->options)) {
|
|
|
|
r = add_opcode(reg, (CKN_ON ?
|
|
|
|
OP_STATE_CHECK_ANYCHAR_ML_STAR
|
|
|
|
: OP_ANYCHAR_ML_STAR));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode(reg, (CKN_ON ?
|
|
|
|
OP_STATE_CHECK_ANYCHAR_STAR
|
|
|
|
: OP_ANYCHAR_STAR));
|
|
|
|
}
|
|
|
|
if (r) return r;
|
|
|
|
if (CKN_ON)
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty_info != 0)
|
|
|
|
mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
|
|
|
|
else
|
|
|
|
mod_tlen = tlen;
|
|
|
|
|
|
|
|
if (infinite && qn->lower <= 1) {
|
|
|
|
if (qn->greedy) {
|
|
|
|
if (qn->lower == 1) {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP,
|
|
|
|
(CKN_ON ? SIZE_OP_STATE_CHECK_PUSH : SIZE_OP_PUSH));
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CKN_ON) {
|
|
|
|
r = add_opcode(reg, OP_STATE_CHECK_PUSH);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_rel_addr(reg, mod_tlen + SIZE_OP_JUMP);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, mod_tlen + SIZE_OP_JUMP);
|
|
|
|
}
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP,
|
|
|
|
-(mod_tlen + (int )SIZE_OP_JUMP
|
|
|
|
+ (int )(CKN_ON ? SIZE_OP_STATE_CHECK_PUSH : SIZE_OP_PUSH)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (qn->lower == 0) {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, mod_tlen);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
if (CKN_ON) {
|
|
|
|
r = add_opcode(reg, OP_STATE_CHECK_PUSH_OR_JUMP);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_rel_addr(reg,
|
|
|
|
-(mod_tlen + (int )SIZE_OP_STATE_CHECK_PUSH_OR_JUMP));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, -(mod_tlen + (int )SIZE_OP_PUSH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (qn->upper == 0) {
|
|
|
|
if (qn->is_refered != 0) { /* /(?<n>..){0}/ */
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = 0;
|
|
|
|
}
|
|
|
|
else if (qn->upper == 1 && qn->greedy) {
|
|
|
|
if (qn->lower == 0) {
|
|
|
|
if (CKN_ON) {
|
|
|
|
r = add_opcode(reg, OP_STATE_CHECK_PUSH);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_rel_addr(reg, tlen);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, tlen);
|
|
|
|
}
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
}
|
|
|
|
else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
|
|
|
|
if (CKN_ON) {
|
|
|
|
r = add_opcode(reg, OP_STATE_CHECK_PUSH);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_rel_addr(reg, SIZE_OP_JUMP);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, SIZE_OP_JUMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = compile_range_repeat_node(qn, mod_tlen, empty_info, reg);
|
|
|
|
if (CKN_ON) {
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_STATE_CHECK);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_state_check_num(reg, ckn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* USE_COMBINATION_EXPLOSION_CHECK */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_length_quantifier_node(QtfrNode* qn, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int len, mod_tlen;
|
|
|
|
int infinite = IS_REPEAT_INFINITE(qn->upper);
|
|
|
|
int empty_info = qn->target_empty_info;
|
|
|
|
int tlen = compile_length_tree(qn->target, reg);
|
|
|
|
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
|
|
|
|
/* anychar repeat */
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(qn->target) == NT_CANY) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->greedy && infinite) {
|
|
|
|
if (IS_NOT_NULL(qn->next_head_exact))
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return SIZE_OP_ANYCHAR_STAR_PEEK_NEXT + tlen * qn->lower;
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return SIZE_OP_ANYCHAR_STAR + tlen * qn->lower;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty_info != 0)
|
|
|
|
mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
|
|
|
|
else
|
|
|
|
mod_tlen = tlen;
|
|
|
|
|
|
|
|
if (infinite &&
|
2007-05-23 05:32:08 +04:00
|
|
|
(qn->lower <= 1 || tlen * qn->lower <= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
|
|
|
|
if (qn->lower == 1 && tlen > QUANTIFIER_EXPAND_LIMIT_SIZE) {
|
2004-03-05 18:31:51 +03:00
|
|
|
len = SIZE_OP_JUMP;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = tlen * qn->lower;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qn->greedy) {
|
|
|
|
if (IS_NOT_NULL(qn->head_exact))
|
|
|
|
len += SIZE_OP_PUSH_OR_JUMP_EXACT1 + mod_tlen + SIZE_OP_JUMP;
|
|
|
|
else if (IS_NOT_NULL(qn->next_head_exact))
|
|
|
|
len += SIZE_OP_PUSH_IF_PEEK_NEXT + mod_tlen + SIZE_OP_JUMP;
|
|
|
|
else
|
|
|
|
len += SIZE_OP_PUSH + mod_tlen + SIZE_OP_JUMP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
len += SIZE_OP_JUMP + mod_tlen + SIZE_OP_PUSH;
|
|
|
|
}
|
|
|
|
else if (qn->upper == 0 && qn->is_refered != 0) { /* /(?<n>..){0}/ */
|
|
|
|
len = SIZE_OP_JUMP + tlen;
|
|
|
|
}
|
|
|
|
else if (!infinite && qn->greedy &&
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
(qn->upper == 1 || (tlen + SIZE_OP_PUSH) * qn->upper
|
2007-05-23 05:32:08 +04:00
|
|
|
<= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
len = tlen * qn->lower;
|
|
|
|
len += (SIZE_OP_PUSH + tlen) * (qn->upper - qn->lower);
|
|
|
|
}
|
|
|
|
else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
|
|
|
|
len = SIZE_OP_PUSH + SIZE_OP_JUMP + tlen;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = SIZE_OP_REPEAT_INC
|
|
|
|
+ mod_tlen + SIZE_OPCODE + SIZE_RELADDR + SIZE_MEMNUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_quantifier_node(QtfrNode* qn, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, r, mod_tlen;
|
|
|
|
int infinite = IS_REPEAT_INFINITE(qn->upper);
|
|
|
|
int empty_info = qn->target_empty_info;
|
|
|
|
int tlen = compile_length_tree(qn->target, reg);
|
|
|
|
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (is_anychar_star_quantifier(qn)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
r = compile_tree_n_times(qn->target, qn->lower, reg);
|
|
|
|
if (r) return r;
|
|
|
|
if (IS_NOT_NULL(qn->next_head_exact)) {
|
|
|
|
if (IS_MULTILINE(reg->options))
|
|
|
|
r = add_opcode(reg, OP_ANYCHAR_ML_STAR_PEEK_NEXT);
|
|
|
|
else
|
|
|
|
r = add_opcode(reg, OP_ANYCHAR_STAR_PEEK_NEXT);
|
|
|
|
if (r) return r;
|
2007-07-23 13:39:30 +04:00
|
|
|
return add_bytes(reg, NSTR(qn->next_head_exact)->s, 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_MULTILINE(reg->options))
|
|
|
|
return add_opcode(reg, OP_ANYCHAR_ML_STAR);
|
|
|
|
else
|
|
|
|
return add_opcode(reg, OP_ANYCHAR_STAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty_info != 0)
|
|
|
|
mod_tlen = tlen + (SIZE_OP_NULL_CHECK_START + SIZE_OP_NULL_CHECK_END);
|
|
|
|
else
|
|
|
|
mod_tlen = tlen;
|
|
|
|
|
|
|
|
if (infinite &&
|
2007-05-23 05:32:08 +04:00
|
|
|
(qn->lower <= 1 || tlen * qn->lower <= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
|
|
|
|
if (qn->lower == 1 && tlen > QUANTIFIER_EXPAND_LIMIT_SIZE) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->greedy) {
|
|
|
|
if (IS_NOT_NULL(qn->head_exact))
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_PUSH_OR_JUMP_EXACT1);
|
|
|
|
else if (IS_NOT_NULL(qn->next_head_exact))
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_PUSH_IF_PEEK_NEXT);
|
|
|
|
else
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_PUSH);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, SIZE_OP_JUMP);
|
|
|
|
}
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = compile_tree_n_times(qn->target, qn->lower, reg);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qn->greedy) {
|
|
|
|
if (IS_NOT_NULL(qn->head_exact)) {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH_OR_JUMP_EXACT1,
|
|
|
|
mod_tlen + SIZE_OP_JUMP);
|
|
|
|
if (r) return r;
|
2007-07-23 13:39:30 +04:00
|
|
|
add_bytes(reg, NSTR(qn->head_exact)->s, 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP,
|
|
|
|
-(mod_tlen + (int )SIZE_OP_JUMP + (int )SIZE_OP_PUSH_OR_JUMP_EXACT1));
|
|
|
|
}
|
|
|
|
else if (IS_NOT_NULL(qn->next_head_exact)) {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH_IF_PEEK_NEXT,
|
|
|
|
mod_tlen + SIZE_OP_JUMP);
|
|
|
|
if (r) return r;
|
2007-07-23 13:39:30 +04:00
|
|
|
add_bytes(reg, NSTR(qn->next_head_exact)->s, 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP,
|
|
|
|
-(mod_tlen + (int )SIZE_OP_JUMP + (int )SIZE_OP_PUSH_IF_PEEK_NEXT));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, mod_tlen + SIZE_OP_JUMP);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP,
|
|
|
|
-(mod_tlen + (int )SIZE_OP_JUMP + (int )SIZE_OP_PUSH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, mod_tlen);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree_empty_check(qn->target, reg, empty_info);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, -(mod_tlen + (int )SIZE_OP_PUSH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (qn->upper == 0 && qn->is_refered != 0) { /* /(?<n>..){0}/ */
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
}
|
|
|
|
else if (!infinite && qn->greedy &&
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
(qn->upper == 1 || (tlen + SIZE_OP_PUSH) * qn->upper
|
2007-05-23 05:32:08 +04:00
|
|
|
<= QUANTIFIER_EXPAND_LIMIT_SIZE)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
int n = qn->upper - qn->lower;
|
|
|
|
|
|
|
|
r = compile_tree_n_times(qn->target, qn->lower, reg);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH,
|
|
|
|
(n - i) * tlen + (n - i - 1) * SIZE_OP_PUSH);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!qn->greedy && qn->upper == 1 && qn->lower == 0) { /* '??' */
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, SIZE_OP_JUMP);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, tlen);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = compile_range_repeat_node(qn, mod_tlen, empty_info, reg);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2006-08-27 16:58:22 +04:00
|
|
|
#endif /* USE_COMBINATION_EXPLOSION_CHECK */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_length_option_node(EncloseNode* node, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int tlen;
|
|
|
|
OnigOptionType prev = reg->options;
|
|
|
|
|
|
|
|
reg->options = node->option;
|
|
|
|
tlen = compile_length_tree(node->target, reg);
|
|
|
|
reg->options = prev;
|
|
|
|
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
|
|
|
|
if (IS_DYNAMIC_OPTION(prev ^ node->option)) {
|
|
|
|
return SIZE_OP_SET_OPTION_PUSH + SIZE_OP_SET_OPTION + SIZE_OP_FAIL
|
|
|
|
+ tlen + SIZE_OP_SET_OPTION;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return tlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_option_node(EncloseNode* node, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
OnigOptionType prev = reg->options;
|
|
|
|
|
|
|
|
if (IS_DYNAMIC_OPTION(prev ^ node->option)) {
|
|
|
|
r = add_opcode_option(reg, OP_SET_OPTION_PUSH, node->option);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_option(reg, OP_SET_OPTION, prev);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_FAIL);
|
|
|
|
if (r) return r;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
reg->options = node->option;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
reg->options = prev;
|
|
|
|
|
|
|
|
if (IS_DYNAMIC_OPTION(prev ^ node->option)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_option(reg, OP_SET_OPTION, prev);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_length_enclose_node(EncloseNode* node, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int tlen;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (node->type == ENCLOSE_OPTION)
|
2004-03-05 18:31:51 +03:00
|
|
|
return compile_length_option_node(node, reg);
|
|
|
|
|
|
|
|
if (node->target) {
|
|
|
|
tlen = compile_length_tree(node->target, reg);
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tlen = 0;
|
|
|
|
|
|
|
|
switch (node->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_CALLED(node)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
len = SIZE_OP_MEMORY_START_PUSH + tlen
|
|
|
|
+ SIZE_OP_CALL + SIZE_OP_JUMP + SIZE_OP_RETURN;
|
|
|
|
if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
|
2007-07-23 13:39:30 +04:00
|
|
|
len += (IS_ENCLOSE_RECURSION(node)
|
2004-03-05 18:31:51 +03:00
|
|
|
? SIZE_OP_MEMORY_END_PUSH_REC : SIZE_OP_MEMORY_END_PUSH);
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
len += (IS_ENCLOSE_RECURSION(node)
|
2004-03-05 18:31:51 +03:00
|
|
|
? SIZE_OP_MEMORY_END_REC : SIZE_OP_MEMORY_END);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (BIT_STATUS_AT(reg->bt_mem_start, node->regnum))
|
|
|
|
len = SIZE_OP_MEMORY_START_PUSH;
|
|
|
|
else
|
|
|
|
len = SIZE_OP_MEMORY_START;
|
|
|
|
|
|
|
|
len += tlen + (BIT_STATUS_AT(reg->bt_mem_end, node->regnum)
|
|
|
|
? SIZE_OP_MEMORY_END_PUSH : SIZE_OP_MEMORY_END);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
|
|
|
if (IS_ENCLOSE_STOP_BT_SIMPLE_REPEAT(node)) {
|
|
|
|
QtfrNode* qn = NQTFR(node->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
tlen = compile_length_tree(qn->target, reg);
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
|
|
|
|
len = tlen * qn->lower
|
|
|
|
+ SIZE_OP_PUSH + tlen + SIZE_OP_POP + SIZE_OP_JUMP;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = SIZE_OP_PUSH_STOP_BT + tlen + SIZE_OP_POP_STOP_BT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
|
|
|
len = SIZE_OP_CONDITION;
|
|
|
|
if (NTYPE(node->target) == NT_ALT) {
|
|
|
|
Node* x = node->target;
|
|
|
|
|
|
|
|
tlen = compile_length_tree(NCAR(x), reg); /* yes-node */
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
len += tlen + SIZE_OP_JUMP;
|
|
|
|
if (NCDR(x) == NULL) return ONIGERR_PARSER_BUG;
|
|
|
|
x = NCDR(x);
|
|
|
|
tlen = compile_length_tree(NCAR(x), reg); /* no-node */
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
len += tlen;
|
|
|
|
if (NCDR(x) != NULL) return ONIGERR_INVALID_CONDITION_PATTERN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
return ONIGERR_TYPE_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_char_length_tree(Node* node, regex_t* reg, int* len);
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
compile_enclose_node(EncloseNode* node, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r, len;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (node->type == ENCLOSE_OPTION)
|
2004-03-05 18:31:51 +03:00
|
|
|
return compile_option_node(node, reg);
|
|
|
|
|
|
|
|
switch (node->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_CALLED(node)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
r = add_opcode(reg, OP_CALL);
|
|
|
|
if (r) return r;
|
|
|
|
node->call_addr = BBUF_GET_OFFSET_POS(reg) + SIZE_ABSADDR + SIZE_OP_JUMP;
|
|
|
|
node->state |= NST_ADDR_FIXED;
|
|
|
|
r = add_abs_addr(reg, (int )node->call_addr);
|
|
|
|
if (r) return r;
|
|
|
|
len = compile_length_tree(node->target, reg);
|
|
|
|
len += (SIZE_OP_MEMORY_START_PUSH + SIZE_OP_RETURN);
|
|
|
|
if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
|
2007-07-23 13:39:30 +04:00
|
|
|
len += (IS_ENCLOSE_RECURSION(node)
|
2004-03-05 18:31:51 +03:00
|
|
|
? SIZE_OP_MEMORY_END_PUSH_REC : SIZE_OP_MEMORY_END_PUSH);
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
len += (IS_ENCLOSE_RECURSION(node)
|
2004-03-05 18:31:51 +03:00
|
|
|
? SIZE_OP_MEMORY_END_REC : SIZE_OP_MEMORY_END);
|
|
|
|
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, len);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (BIT_STATUS_AT(reg->bt_mem_start, node->regnum))
|
|
|
|
r = add_opcode(reg, OP_MEMORY_START_PUSH);
|
|
|
|
else
|
|
|
|
r = add_opcode(reg, OP_MEMORY_START);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, node->regnum);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_CALLED(node)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
|
2007-07-23 13:39:30 +04:00
|
|
|
r = add_opcode(reg, (IS_ENCLOSE_RECURSION(node)
|
2004-03-05 18:31:51 +03:00
|
|
|
? OP_MEMORY_END_PUSH_REC : OP_MEMORY_END_PUSH));
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
r = add_opcode(reg, (IS_ENCLOSE_RECURSION(node)
|
2004-03-05 18:31:51 +03:00
|
|
|
? OP_MEMORY_END_REC : OP_MEMORY_END));
|
|
|
|
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, node->regnum);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_RETURN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (BIT_STATUS_AT(reg->bt_mem_end, node->regnum))
|
|
|
|
r = add_opcode(reg, OP_MEMORY_END_PUSH);
|
|
|
|
else
|
|
|
|
r = add_opcode(reg, OP_MEMORY_END);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, node->regnum);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
|
|
|
if (IS_ENCLOSE_STOP_BT_SIMPLE_REPEAT(node)) {
|
|
|
|
QtfrNode* qn = NQTFR(node->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = compile_tree_n_times(qn->target, qn->lower, reg);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
len = compile_length_tree(qn->target, reg);
|
|
|
|
if (len < 0) return len;
|
|
|
|
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, len + SIZE_OP_POP + SIZE_OP_JUMP);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(qn->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_POP);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP,
|
|
|
|
-((int )SIZE_OP_PUSH + len + (int )SIZE_OP_POP + (int )SIZE_OP_JUMP));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = add_opcode(reg, OP_PUSH_STOP_BT);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_POP_STOP_BT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
|
|
|
r = add_opcode(reg, OP_CONDITION);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, node->regnum);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
if (NTYPE(node->target) == NT_ALT) {
|
|
|
|
Node* x = node->target;
|
|
|
|
int len2;
|
|
|
|
|
|
|
|
len = compile_length_tree(NCAR(x), reg); /* yes-node */
|
|
|
|
if (len < 0) return len;
|
|
|
|
if (NCDR(x) == NULL) return ONIGERR_PARSER_BUG;
|
|
|
|
x = NCDR(x);
|
|
|
|
len2 = compile_length_tree(NCAR(x), reg); /* no-node */
|
|
|
|
if (len2 < 0) return len2;
|
|
|
|
if (NCDR(x) != NULL) return ONIGERR_INVALID_CONDITION_PATTERN;
|
|
|
|
|
|
|
|
x = node->target;
|
|
|
|
r = add_rel_addr(reg, len + SIZE_OP_JUMP);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(NCAR(x), reg); /* yes-node */
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, len2);
|
|
|
|
if (r) return r;
|
|
|
|
x = NCDR(x);
|
|
|
|
r = compile_tree(NCAR(x), reg); /* no-node */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ONIGERR_PARSER_BUG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
return ONIGERR_TYPE_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_length_anchor_node(AnchorNode* node, regex_t* reg)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int tlen = 0;
|
|
|
|
|
|
|
|
if (node->target) {
|
|
|
|
tlen = compile_length_tree(node->target, reg);
|
|
|
|
if (tlen < 0) return tlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (node->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
len = SIZE_OP_PUSH_POS + tlen + SIZE_OP_POP_POS;
|
|
|
|
break;
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
len = SIZE_OP_PUSH_POS_NOT + tlen + SIZE_OP_FAIL_POS;
|
|
|
|
break;
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
len = SIZE_OP_LOOK_BEHIND + tlen;
|
|
|
|
break;
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
len = SIZE_OP_PUSH_LOOK_BEHIND_NOT + tlen + SIZE_OP_FAIL_LOOK_BEHIND_NOT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
len = SIZE_OPCODE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_anchor_node(AnchorNode* node, regex_t* reg)
|
|
|
|
{
|
|
|
|
int r, len;
|
|
|
|
|
|
|
|
switch (node->type) {
|
|
|
|
case ANCHOR_BEGIN_BUF: r = add_opcode(reg, OP_BEGIN_BUF); break;
|
|
|
|
case ANCHOR_END_BUF: r = add_opcode(reg, OP_END_BUF); break;
|
|
|
|
case ANCHOR_BEGIN_LINE: r = add_opcode(reg, OP_BEGIN_LINE); break;
|
|
|
|
case ANCHOR_END_LINE: r = add_opcode(reg, OP_END_LINE); break;
|
|
|
|
case ANCHOR_SEMI_END_BUF: r = add_opcode(reg, OP_SEMI_END_BUF); break;
|
|
|
|
case ANCHOR_BEGIN_POSITION: r = add_opcode(reg, OP_BEGIN_POSITION); break;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
/* used for implicit anchor optimization: /.*a/ ==> /(?:^|\G).*a/ */
|
|
|
|
case ANCHOR_ANYCHAR_STAR: r = add_opcode(reg, OP_BEGIN_POS_OR_LINE); break;
|
|
|
|
|
|
|
|
case ANCHOR_WORD_BOUND:
|
|
|
|
if (node->ascii_range) r = add_opcode(reg, OP_ASCII_WORD_BOUND);
|
|
|
|
else r = add_opcode(reg, OP_WORD_BOUND);
|
|
|
|
break;
|
|
|
|
case ANCHOR_NOT_WORD_BOUND:
|
|
|
|
if (node->ascii_range) r = add_opcode(reg, OP_NOT_ASCII_WORD_BOUND);
|
|
|
|
else r = add_opcode(reg, OP_NOT_WORD_BOUND);
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_WORD_BEGIN_END
|
2012-02-17 11:42:23 +04:00
|
|
|
case ANCHOR_WORD_BEGIN:
|
|
|
|
if (node->ascii_range) r = add_opcode(reg, OP_ASCII_WORD_BEGIN);
|
|
|
|
else r = add_opcode(reg, OP_WORD_BEGIN);
|
|
|
|
break;
|
|
|
|
case ANCHOR_WORD_END:
|
|
|
|
if (node->ascii_range) r = add_opcode(reg, OP_ASCII_WORD_END);
|
|
|
|
else r = add_opcode(reg, OP_WORD_END);
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
2012-02-17 11:42:23 +04:00
|
|
|
case ANCHOR_KEEP: r = add_opcode(reg, OP_KEEP); break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
r = add_opcode(reg, OP_PUSH_POS);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_POP_POS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
len = compile_length_tree(node->target, reg);
|
|
|
|
if (len < 0) return len;
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH_POS_NOT, len + SIZE_OP_FAIL_POS);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_FAIL_POS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
r = add_opcode(reg, OP_LOOK_BEHIND);
|
|
|
|
if (r) return r;
|
|
|
|
if (node->char_len < 0) {
|
|
|
|
r = get_char_length_tree(node->target, reg, &n);
|
|
|
|
if (r) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
n = node->char_len;
|
|
|
|
r = add_length(reg, n);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
len = compile_length_tree(node->target, reg);
|
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH_LOOK_BEHIND_NOT,
|
|
|
|
len + SIZE_OP_FAIL_LOOK_BEHIND_NOT);
|
|
|
|
if (r) return r;
|
|
|
|
if (node->char_len < 0) {
|
|
|
|
r = get_char_length_tree(node->target, reg, &n);
|
|
|
|
if (r) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
n = node->char_len;
|
|
|
|
r = add_length(reg, n);
|
|
|
|
if (r) return r;
|
|
|
|
r = compile_tree(node->target, reg);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_opcode(reg, OP_FAIL_LOOK_BEHIND_NOT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ONIGERR_TYPE_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_length_tree(Node* node, regex_t* reg)
|
|
|
|
{
|
|
|
|
int len, type, r;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
len = 0;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = compile_length_tree(NCAR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
|
|
|
len += r;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
r = len;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = r = 0;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r += compile_length_tree(NCAR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
n++;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
r += (SIZE_OP_PUSH + SIZE_OP_JUMP) * (n - 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (NSTRING_IS_RAW(node))
|
2007-07-23 13:39:30 +04:00
|
|
|
r = compile_length_string_raw_node(NSTR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
r = compile_length_string_node(node, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
|
|
|
r = compile_length_cclass_node(NCCLASS(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = SIZE_OPCODE;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
if (IS_BACKREF_NEST_LEVEL(br)) {
|
|
|
|
r = SIZE_OPCODE + SIZE_OPTION + SIZE_LENGTH +
|
|
|
|
SIZE_LENGTH + (SIZE_MEMNUM * br->back_num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
if (br->back_num == 1) {
|
2006-08-27 16:58:22 +04:00
|
|
|
r = ((!IS_IGNORECASE(reg->options) && br->back_static[0] <= 2)
|
2004-03-05 18:31:51 +03:00
|
|
|
? SIZE_OPCODE : (SIZE_OPCODE + SIZE_MEMNUM));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = SIZE_OPCODE + SIZE_LENGTH + (SIZE_MEMNUM * br->back_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = SIZE_OP_CALL;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = compile_length_quantifier_node(NQTFR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
r = compile_length_enclose_node(NENCLOSE(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
|
|
|
r = compile_length_anchor_node(NANCHOR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ONIGERR_TYPE_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compile_tree(Node* node, regex_t* reg)
|
|
|
|
{
|
|
|
|
int n, type, len, pos, r = 0;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = compile_tree(NCAR(node), reg);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* x = node;
|
|
|
|
len = 0;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
len += compile_length_tree(NCAR(x), reg);
|
|
|
|
if (NCDR(x) != NULL) {
|
2004-03-05 18:31:51 +03:00
|
|
|
len += SIZE_OP_PUSH + SIZE_OP_JUMP;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(x = NCDR(x)));
|
2004-03-05 18:31:51 +03:00
|
|
|
pos = reg->used + len; /* goal position */
|
|
|
|
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
len = compile_length_tree(NCAR(node), reg);
|
|
|
|
if (IS_NOT_NULL(NCDR(node))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
r = add_opcode_rel_addr(reg, OP_PUSH, len + SIZE_OP_JUMP);
|
|
|
|
if (r) break;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
r = compile_tree(NCAR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) break;
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NOT_NULL(NCDR(node))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
len = pos - (reg->used + SIZE_OP_JUMP);
|
|
|
|
r = add_opcode_rel_addr(reg, OP_JUMP, len);
|
|
|
|
if (r) break;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (NSTRING_IS_RAW(node))
|
2007-07-23 13:39:30 +04:00
|
|
|
r = compile_string_raw_node(NSTR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
r = compile_string_node(node, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
|
|
|
r = compile_cclass_node(NCCLASS(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int op;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
switch (NCTYPE(node)->ctype) {
|
2007-05-23 05:32:08 +04:00
|
|
|
case ONIGENC_CTYPE_WORD:
|
2012-02-17 11:42:23 +04:00
|
|
|
if (NCTYPE(node)->ascii_range != 0) {
|
|
|
|
if (NCTYPE(node)->not != 0) op = OP_NOT_ASCII_WORD;
|
|
|
|
else op = OP_ASCII_WORD;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (NCTYPE(node)->not != 0) op = OP_NOT_WORD;
|
|
|
|
else op = OP_WORD;
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
return ONIGERR_TYPE_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
r = add_opcode(reg, op);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_MULTILINE(reg->options))
|
|
|
|
r = add_opcode(reg, OP_ANYCHAR_ML);
|
|
|
|
else
|
|
|
|
r = add_opcode(reg, OP_ANYCHAR);
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
if (IS_BACKREF_NEST_LEVEL(br)) {
|
2008-01-03 18:55:04 +03:00
|
|
|
r = add_opcode(reg, OP_BACKREF_WITH_LEVEL);
|
2006-08-05 17:54:40 +04:00
|
|
|
if (r) return r;
|
|
|
|
r = add_option(reg, (reg->options & ONIG_OPTION_IGNORECASE));
|
|
|
|
if (r) return r;
|
|
|
|
r = add_length(reg, br->nest_level);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
goto add_bacref_mems;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
if (br->back_num == 1) {
|
|
|
|
n = br->back_static[0];
|
|
|
|
if (IS_IGNORECASE(reg->options)) {
|
|
|
|
r = add_opcode(reg, OP_BACKREFN_IC);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, n);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (n) {
|
|
|
|
case 1: r = add_opcode(reg, OP_BACKREF1); break;
|
|
|
|
case 2: r = add_opcode(reg, OP_BACKREF2); break;
|
|
|
|
default:
|
|
|
|
r = add_opcode(reg, OP_BACKREFN);
|
|
|
|
if (r) return r;
|
|
|
|
r = add_mem_num(reg, n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2006-08-05 17:54:40 +04:00
|
|
|
int i;
|
2004-03-05 18:31:51 +03:00
|
|
|
int* p;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
if (IS_IGNORECASE(reg->options)) {
|
2006-08-05 17:54:40 +04:00
|
|
|
r = add_opcode(reg, OP_BACKREF_MULTI_IC);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
else {
|
2006-08-05 17:54:40 +04:00
|
|
|
r = add_opcode(reg, OP_BACKREF_MULTI);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;
|
2006-08-05 17:54:40 +04:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
add_bacref_mems:
|
2006-08-27 16:58:22 +04:00
|
|
|
#endif
|
2006-08-05 17:54:40 +04:00
|
|
|
r = add_length(reg, br->back_num);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;
|
|
|
|
p = BACKREFS_P(br);
|
|
|
|
for (i = br->back_num - 1; i >= 0; i--) {
|
|
|
|
r = add_mem_num(reg, p[i]);
|
|
|
|
if (r) return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
r = compile_call(NCALL(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = compile_quantifier_node(NQTFR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
r = compile_enclose_node(NENCLOSE(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
|
|
|
r = compile_anchor_node(NANCHOR(node), reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#ifdef ONIG_DEBUG
|
|
|
|
fprintf(stderr, "compile_tree: undefined node type %d\n", NTYPE(node));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
noname_disable_map(Node** plink, GroupNumRemap* map, int* counter)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
Node* node = *plink;
|
|
|
|
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = noname_disable_map(&(NCAR(node)), map, counter);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
Node** ptarget = &(NQTFR(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
Node* old = *ptarget;
|
|
|
|
r = noname_disable_map(ptarget, map, counter);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (*ptarget != old && NTYPE(*ptarget) == NT_QTFR) {
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_reduce_nested_quantifier(node, *ptarget);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
|
|
|
if (en->type == ENCLOSE_MEMORY) {
|
|
|
|
if (IS_ENCLOSE_NAMED_GROUP(en)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
(*counter)++;
|
|
|
|
map[en->regnum].new_val = *counter;
|
|
|
|
en->regnum = *counter;
|
|
|
|
r = noname_disable_map(&(en->target), map, counter);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*plink = en->target;
|
|
|
|
en->target = NULL_NODE;
|
|
|
|
onig_node_free(node);
|
|
|
|
r = noname_disable_map(plink, map, counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = noname_disable_map(&(en->target), map, counter);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-03-02 12:40:27 +03:00
|
|
|
case NT_ANCHOR:
|
|
|
|
{
|
|
|
|
AnchorNode* an = NANCHOR(node);
|
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = noname_disable_map(&(an->target), map, counter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
renumber_node_backref(Node* node, GroupNumRemap* map)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, pos, n, old_num;
|
|
|
|
int *backs;
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* bn = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (! IS_BACKREF_NAME_REF(bn))
|
|
|
|
return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
|
|
|
|
|
|
|
|
old_num = bn->back_num;
|
|
|
|
if (IS_NULL(bn->back_dynamic))
|
|
|
|
backs = bn->back_static;
|
|
|
|
else
|
|
|
|
backs = bn->back_dynamic;
|
|
|
|
|
|
|
|
for (i = 0, pos = 0; i < old_num; i++) {
|
|
|
|
n = map[backs[i]].new_val;
|
|
|
|
if (n > 0) {
|
|
|
|
backs[pos] = n;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bn->back_num = pos;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
renumber_by_map(Node* node, GroupNumRemap* map)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = renumber_by_map(NCAR(node), map);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = renumber_by_map(NQTFR(node)->target, map);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
r = renumber_by_map(NENCLOSE(node)->target, map);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = renumber_node_backref(node, map);
|
|
|
|
break;
|
|
|
|
|
2010-03-02 12:40:27 +03:00
|
|
|
case NT_ANCHOR:
|
|
|
|
{
|
|
|
|
AnchorNode* an = NANCHOR(node);
|
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = renumber_by_map(an->target, map);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
numbered_ref_check(Node* node)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = numbered_ref_check(NCAR(node));
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = numbered_ref_check(NQTFR(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
r = numbered_ref_check(NENCLOSE(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
|
|
|
if (! IS_BACKREF_NAME_REF(NBREF(node)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
disable_noname_group_capture(Node** root, regex_t* reg, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r, i, pos, counter;
|
|
|
|
BitStatusType loc;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
GroupNumRemap* map;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
map = (GroupNumRemap* )xalloca(sizeof(GroupNumRemap) * (env->num_mem + 1));
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(map);
|
2004-03-05 18:31:51 +03:00
|
|
|
for (i = 1; i <= env->num_mem; i++) {
|
|
|
|
map[i].new_val = 0;
|
|
|
|
}
|
|
|
|
counter = 0;
|
|
|
|
r = noname_disable_map(root, map, &counter);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
r = renumber_by_map(*root, map);
|
|
|
|
if (r != 0) return r;
|
|
|
|
|
|
|
|
for (i = 1, pos = 1; i <= env->num_mem; i++) {
|
|
|
|
if (map[i].new_val > 0) {
|
|
|
|
SCANENV_MEM_NODES(env)[pos] = SCANENV_MEM_NODES(env)[i];
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loc = env->capture_history;
|
|
|
|
BIT_STATUS_CLEAR(env->capture_history);
|
|
|
|
for (i = 1; i <= ONIG_MAX_CAPTURE_HISTORY_GROUP; i++) {
|
|
|
|
if (BIT_STATUS_AT(loc, i)) {
|
|
|
|
BIT_STATUS_ON_AT_SIMPLE(env->capture_history, map[i].new_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
env->num_mem = env->num_named;
|
|
|
|
reg->num_mem = env->num_named;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
|
|
|
return onig_renumber_name_table(reg, map);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
#endif /* USE_NAMED_GROUP */
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
static int
|
|
|
|
unset_addr_list_fix(UnsetAddrList* uslist, regex_t* reg)
|
|
|
|
{
|
|
|
|
int i, offset;
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en;
|
2004-03-05 18:31:51 +03:00
|
|
|
AbsAddrType addr;
|
|
|
|
|
|
|
|
for (i = 0; i < uslist->num; i++) {
|
2007-07-23 13:39:30 +04:00
|
|
|
en = NENCLOSE(uslist->us[i].target);
|
|
|
|
if (! IS_ENCLOSE_ADDR_FIXED(en)) return ONIGERR_PARSER_BUG;
|
2004-03-05 18:31:51 +03:00
|
|
|
addr = en->call_addr;
|
|
|
|
offset = uslist->us[i].offset;
|
|
|
|
|
|
|
|
BBUF_WRITE(reg, offset, &addr, SIZE_ABSADDR);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
quantifiers_memory_node_info(Node* node)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
v = quantifiers_memory_node_info(NCAR(node));
|
2004-03-05 18:31:51 +03:00
|
|
|
if (v > r) r = v;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (v >= 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
if (IS_CALL_RECURSION(NCALL(node))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
return NQ_TARGET_IS_EMPTY_REC; /* tiny version */
|
|
|
|
}
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
r = quantifiers_memory_node_info(NCALL(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->upper != 0) {
|
2007-05-23 05:32:08 +04:00
|
|
|
r = quantifiers_memory_node_info(qn->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
return NQ_TARGET_IS_EMPTY_MEM;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
2007-05-23 05:32:08 +04:00
|
|
|
r = quantifiers_memory_node_info(en->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
|
|
|
case NT_STR:
|
|
|
|
case NT_CTYPE:
|
|
|
|
case NT_CCLASS:
|
|
|
|
case NT_CANY:
|
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
#endif /* USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
get_min_match_length(Node* node, OnigDistance *min, ScanEnv* env)
|
|
|
|
{
|
|
|
|
OnigDistance tmin;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
*min = 0;
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int* backs;
|
|
|
|
Node** nodes = SCANENV_MEM_NODES(env);
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (br->state & NST_RECURSION) break;
|
|
|
|
|
|
|
|
backs = BACKREFS_P(br);
|
|
|
|
if (backs[0] > env->num_mem) return ONIGERR_INVALID_BACKREF;
|
|
|
|
r = get_min_match_length(nodes[backs[0]], min, env);
|
|
|
|
if (r != 0) break;
|
|
|
|
for (i = 1; i < br->back_num; i++) {
|
|
|
|
if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
|
|
|
|
r = get_min_match_length(nodes[backs[i]], &tmin, env);
|
|
|
|
if (r != 0) break;
|
|
|
|
if (*min > tmin) *min = tmin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
if (IS_CALL_RECURSION(NCALL(node))) {
|
|
|
|
EncloseNode* en = NENCLOSE(NCALL(node)->target);
|
|
|
|
if (IS_ENCLOSE_MIN_FIXED(en))
|
2004-03-05 18:31:51 +03:00
|
|
|
*min = en->min_len;
|
|
|
|
}
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
r = get_min_match_length(NCALL(node)->target, min, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = get_min_match_length(NCAR(node), &tmin, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0) *min += tmin;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node *x, *y;
|
|
|
|
y = node;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
x = NCAR(y);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = get_min_match_length(x, &tmin, env);
|
|
|
|
if (r != 0) break;
|
|
|
|
if (y == node) *min = tmin;
|
|
|
|
else if (*min > tmin) *min = tmin;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(y = NCDR(y)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
*min = sn->end - sn->s;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2007-05-23 05:32:08 +04:00
|
|
|
*min = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
*min = 1;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (qn->lower > 0) {
|
|
|
|
r = get_min_match_length(qn->target, min, env);
|
|
|
|
if (r == 0)
|
|
|
|
*min = distance_multiply(*min, qn->lower);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_MIN_FIXED(en))
|
2004-03-05 18:31:51 +03:00
|
|
|
*min = en->min_len;
|
|
|
|
else {
|
|
|
|
r = get_min_match_length(en->target, min, env);
|
|
|
|
if (r == 0) {
|
|
|
|
en->min_len = *min;
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_MIN_FIXED);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = get_min_match_length(en->target, min, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_max_match_length(Node* node, OnigDistance *max, ScanEnv* env)
|
|
|
|
{
|
|
|
|
OnigDistance tmax;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
*max = 0;
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = get_max_match_length(NCAR(node), &tmax, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0)
|
|
|
|
*max = distance_add(*max, tmax);
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = get_max_match_length(NCAR(node), &tmax, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0 && *max < tmax) *max = tmax;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
*max = sn->end - sn->s;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2007-05-23 05:32:08 +04:00
|
|
|
*max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
*max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int* backs;
|
|
|
|
Node** nodes = SCANENV_MEM_NODES(env);
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (br->state & NST_RECURSION) {
|
|
|
|
*max = ONIG_INFINITE_DISTANCE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
backs = BACKREFS_P(br);
|
|
|
|
for (i = 0; i < br->back_num; i++) {
|
|
|
|
if (backs[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
|
|
|
|
r = get_max_match_length(nodes[backs[i]], &tmax, env);
|
|
|
|
if (r != 0) break;
|
|
|
|
if (*max < tmax) *max = tmax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
if (! IS_CALL_RECURSION(NCALL(node)))
|
|
|
|
r = get_max_match_length(NCALL(node)->target, max, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
|
|
|
*max = ONIG_INFINITE_DISTANCE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (qn->upper != 0) {
|
|
|
|
r = get_max_match_length(qn->target, max, env);
|
|
|
|
if (r == 0 && *max != 0) {
|
|
|
|
if (! IS_REPEAT_INFINITE(qn->upper))
|
|
|
|
*max = distance_multiply(*max, qn->upper);
|
|
|
|
else
|
|
|
|
*max = ONIG_INFINITE_DISTANCE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_MAX_FIXED(en))
|
2004-03-05 18:31:51 +03:00
|
|
|
*max = en->max_len;
|
|
|
|
else {
|
|
|
|
r = get_max_match_length(en->target, max, env);
|
|
|
|
if (r == 0) {
|
|
|
|
en->max_len = *max;
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_MAX_FIXED);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = get_max_match_length(en->target, max, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_CHAR_LEN_VARLEN -1
|
|
|
|
#define GET_CHAR_LEN_TOP_ALT_VARLEN -2
|
|
|
|
|
|
|
|
/* fixed size pattern node only */
|
|
|
|
static int
|
|
|
|
get_char_length_tree1(Node* node, regex_t* reg, int* len, int level)
|
|
|
|
{
|
|
|
|
int tlen;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
level++;
|
|
|
|
*len = 0;
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = get_char_length_tree1(NCAR(node), reg, &tlen, level);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0)
|
2012-02-17 11:42:23 +04:00
|
|
|
*len = (int )distance_add(*len, tlen);
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int tlen2;
|
|
|
|
int varlen = 0;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
r = get_char_length_tree1(NCAR(node), reg, &tlen, level);
|
|
|
|
while (r == 0 && IS_NOT_NULL(node = NCDR(node))) {
|
|
|
|
r = get_char_length_tree1(NCAR(node), reg, &tlen2, level);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0) {
|
|
|
|
if (tlen != tlen2)
|
|
|
|
varlen = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r == 0) {
|
|
|
|
if (varlen != 0) {
|
|
|
|
if (level == 1)
|
|
|
|
r = GET_CHAR_LEN_TOP_ALT_VARLEN;
|
|
|
|
else
|
|
|
|
r = GET_CHAR_LEN_VARLEN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*len = tlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
UChar *s = sn->s;
|
|
|
|
while (s < sn->end) {
|
2008-01-03 18:55:04 +03:00
|
|
|
s += enclen(reg->enc, s, sn->end);
|
2004-03-05 18:31:51 +03:00
|
|
|
(*len)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->lower == qn->upper) {
|
|
|
|
r = get_char_length_tree1(qn->target, reg, &tlen, level);
|
|
|
|
if (r == 0)
|
2012-02-17 11:42:23 +04:00
|
|
|
*len = (int )distance_multiply(tlen, qn->lower);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
r = GET_CHAR_LEN_VARLEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
if (! IS_CALL_RECURSION(NCALL(node)))
|
|
|
|
r = get_char_length_tree1(NCALL(node)->target, reg, len, level);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
|
|
|
r = GET_CHAR_LEN_VARLEN;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2007-05-23 05:32:08 +04:00
|
|
|
*len = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
*len = 1;
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_CLEN_FIXED(en))
|
2004-03-05 18:31:51 +03:00
|
|
|
*len = en->char_len;
|
|
|
|
else {
|
|
|
|
r = get_char_length_tree1(en->target, reg, len, level);
|
|
|
|
if (r == 0) {
|
|
|
|
en->char_len = *len;
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_CLEN_FIXED);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = get_char_length_tree1(en->target, reg, len, level);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
r = GET_CHAR_LEN_VARLEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_char_length_tree(Node* node, regex_t* reg, int* len)
|
|
|
|
{
|
|
|
|
return get_char_length_tree1(node, reg, len, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* x is not included y ==> 1 : 0 */
|
|
|
|
static int
|
|
|
|
is_not_included(Node* x, Node* y, regex_t* reg)
|
|
|
|
{
|
2011-01-31 06:44:57 +03:00
|
|
|
int i;
|
|
|
|
OnigDistance len;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigCodePoint code;
|
2012-03-05 11:40:51 +04:00
|
|
|
UChar *p;
|
2004-03-05 18:31:51 +03:00
|
|
|
int ytype;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
ytype = NTYPE(y);
|
|
|
|
switch (NTYPE(x)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
switch (ytype) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
|
|
|
if (NCTYPE(y)->ctype == NCTYPE(x)->ctype &&
|
2012-02-17 11:42:23 +04:00
|
|
|
NCTYPE(y)->not != NCTYPE(x)->not &&
|
|
|
|
NCTYPE(y)->ascii_range == NCTYPE(x)->ascii_range)
|
2007-05-23 05:32:08 +04:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
swap:
|
|
|
|
{
|
|
|
|
Node* tmp;
|
|
|
|
tmp = x; x = y; y = tmp;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
goto swap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
CClassNode* xc = NCCLASS(x);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (ytype) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
|
|
|
switch (NCTYPE(y)->ctype) {
|
2007-05-23 05:32:08 +04:00
|
|
|
case ONIGENC_CTYPE_WORD:
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NCTYPE(y)->not == 0) {
|
|
|
|
if (IS_NULL(xc->mbuf) && !IS_NCCLASS_NOT(xc)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
|
|
|
|
if (BITSET_AT(xc->bs, i)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
if (NCTYPE(y)->ascii_range) {
|
|
|
|
if (IS_CODE_SB_WORD(reg->enc, i)) return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ONIGENC_IS_CODE_WORD(reg->enc, i)) return 0;
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
return 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
return 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
else {
|
|
|
|
for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
|
2012-02-17 11:42:23 +04:00
|
|
|
int is_word;
|
|
|
|
if (NCTYPE(y)->ascii_range)
|
|
|
|
is_word = IS_CODE_SB_WORD(reg->enc, i);
|
|
|
|
else
|
|
|
|
is_word = ONIGENC_IS_CODE_WORD(reg->enc, i);
|
|
|
|
if (! is_word) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (!IS_NCCLASS_NOT(xc)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (BITSET_AT(xc->bs, i))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (! BITSET_AT(xc->bs, i))
|
|
|
|
return 0;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
return 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int v;
|
2007-07-23 13:39:30 +04:00
|
|
|
CClassNode* yc = NCCLASS(y);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
|
|
|
|
v = BITSET_AT(xc->bs, i);
|
2007-07-23 13:39:30 +04:00
|
|
|
if ((v != 0 && !IS_NCCLASS_NOT(xc)) ||
|
|
|
|
(v == 0 && IS_NCCLASS_NOT(xc))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
v = BITSET_AT(yc->bs, i);
|
2007-07-23 13:39:30 +04:00
|
|
|
if ((v != 0 && !IS_NCCLASS_NOT(yc)) ||
|
|
|
|
(v == 0 && IS_NCCLASS_NOT(yc)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
if ((IS_NULL(xc->mbuf) && !IS_NCCLASS_NOT(xc)) ||
|
|
|
|
(IS_NULL(yc->mbuf) && !IS_NCCLASS_NOT(yc)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
goto swap;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* xs = NSTR(x);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (NSTRING_LEN(x) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (ytype) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
|
|
|
switch (NCTYPE(y)->ctype) {
|
2007-05-23 05:32:08 +04:00
|
|
|
case ONIGENC_CTYPE_WORD:
|
2012-02-17 11:42:23 +04:00
|
|
|
if (NCTYPE(y)->ascii_range) {
|
|
|
|
if (ONIGENC_IS_MBC_ASCII_WORD(reg->enc, xs->s, xs->end))
|
|
|
|
return NCTYPE(y)->not;
|
|
|
|
else
|
|
|
|
return !(NCTYPE(y)->not);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ONIGENC_IS_MBC_WORD(reg->enc, xs->s, xs->end))
|
|
|
|
return NCTYPE(y)->not;
|
|
|
|
else
|
|
|
|
return !(NCTYPE(y)->not);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
CClassNode* cc = NCCLASS(y);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
code = ONIGENC_MBC_TO_CODE(reg->enc, xs->s,
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
xs->s + ONIGENC_MBC_MAXLEN(reg->enc));
|
2004-03-05 18:31:51 +03:00
|
|
|
return (onig_is_code_in_cc(reg->enc, code, cc) != 0 ? 0 : 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
UChar *q;
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* ys = NSTR(y);
|
2004-03-05 18:31:51 +03:00
|
|
|
len = NSTRING_LEN(x);
|
|
|
|
if (len > NSTRING_LEN(y)) len = NSTRING_LEN(y);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (NSTRING_IS_AMBIG(x) || NSTRING_IS_AMBIG(y)) {
|
|
|
|
/* tiny version */
|
|
|
|
return 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
for (i = 0, p = ys->s, q = xs->s; (OnigDistance )i < len; i++, p++, q++) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (*p != *q) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Node*
|
|
|
|
get_head_value_node(Node* node, int exact, regex_t* reg)
|
|
|
|
{
|
|
|
|
Node* n = NULL_NODE;
|
|
|
|
|
|
|
|
switch (NTYPE(node)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
|
|
|
case NT_ALT:
|
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (exact == 0) {
|
|
|
|
n = node;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
n = get_head_value_node(NCAR(node), exact, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (sn->end <= sn->s)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (exact != 0 &&
|
|
|
|
!NSTRING_IS_RAW(node) && IS_IGNORECASE(reg->options)) {
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
n = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->lower > 0) {
|
|
|
|
if (IS_NOT_NULL(qn->head_exact))
|
|
|
|
n = qn->head_exact;
|
|
|
|
else
|
|
|
|
n = get_head_value_node(qn->target, exact, reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
OnigOptionType options = reg->options;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
reg->options = NENCLOSE(node)->option;
|
|
|
|
n = get_head_value_node(NENCLOSE(node)->target, exact, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->options = options;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
2004-03-05 18:31:51 +03:00
|
|
|
n = get_head_value_node(en->target, exact, reg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
|
|
|
if (NANCHOR(node)->type == ANCHOR_PREC_READ)
|
|
|
|
n = get_head_value_node(NANCHOR(node)->target, exact, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-23 13:39:30 +04:00
|
|
|
check_type_tree(Node* node, int type_mask, int enclose_mask, int anchor_mask)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int type, r = 0;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
if ((NTYPE2BIT(type) & type_mask) == 0)
|
2004-03-05 18:31:51 +03:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = check_type_tree(NCAR(node), type_mask, enclose_mask,
|
|
|
|
anchor_mask);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = check_type_tree(NQTFR(node)->target, type_mask, enclose_mask,
|
2004-03-05 18:31:51 +03:00
|
|
|
anchor_mask);
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
|
|
|
if ((en->type & enclose_mask) == 0)
|
2004-03-05 18:31:51 +03:00
|
|
|
return 1;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
r = check_type_tree(en->target, type_mask, enclose_mask, anchor_mask);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
|
|
|
type = NANCHOR(node)->type;
|
2004-03-05 18:31:51 +03:00
|
|
|
if ((type & anchor_mask) == 0)
|
|
|
|
return 1;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NANCHOR(node)->target)
|
|
|
|
r = check_type_tree(NANCHOR(node)->target,
|
|
|
|
type_mask, enclose_mask, anchor_mask);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
|
|
|
|
#define RECURSION_EXIST 1
|
|
|
|
#define RECURSION_INFINITE 2
|
|
|
|
|
|
|
|
static int
|
|
|
|
subexp_inf_recursive_check(Node* node, ScanEnv* env, int head)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node *x;
|
|
|
|
OnigDistance min;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
x = node;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
ret = subexp_inf_recursive_check(NCAR(x), env, head);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ret < 0 || ret == RECURSION_INFINITE) return ret;
|
|
|
|
r |= ret;
|
|
|
|
if (head) {
|
2007-07-23 13:39:30 +04:00
|
|
|
ret = get_min_match_length(NCAR(x), &min, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ret != 0) return ret;
|
|
|
|
if (min != 0) head = 0;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(x = NCDR(x)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
r = RECURSION_EXIST;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
ret = subexp_inf_recursive_check(NCAR(node), env, head);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ret < 0 || ret == RECURSION_INFINITE) return ret;
|
|
|
|
r &= ret;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = subexp_inf_recursive_check(NQTFR(node)->target, env, head);
|
2006-02-04 15:31:19 +03:00
|
|
|
if (r == RECURSION_EXIST) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NQTFR(node)->lower == 0) r = 0;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = subexp_inf_recursive_check(an->target, env, head);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
r = subexp_inf_recursive_check(NCALL(node)->target, env, head);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
if (IS_ENCLOSE_MARK2(NENCLOSE(node)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
2007-07-23 13:39:30 +04:00
|
|
|
else if (IS_ENCLOSE_MARK1(NENCLOSE(node)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return (head == 0 ? RECURSION_EXIST : RECURSION_INFINITE);
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_MARK2);
|
|
|
|
r = subexp_inf_recursive_check(NENCLOSE(node)->target, env, head);
|
|
|
|
CLEAR_ENCLOSE_STATUS(node, NST_MARK2);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
subexp_inf_recursive_check_trav(Node* node, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = subexp_inf_recursive_check_trav(NCAR(node), env);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = subexp_inf_recursive_check_trav(NQTFR(node)->target, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = subexp_inf_recursive_check_trav(an->target, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_RECURSION(en)) {
|
|
|
|
SET_ENCLOSE_STATUS(node, NST_MARK1);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = subexp_inf_recursive_check(en->target, env, 1);
|
|
|
|
if (r > 0) return ONIGERR_NEVER_ENDING_RECURSION;
|
2007-07-23 13:39:30 +04:00
|
|
|
CLEAR_ENCLOSE_STATUS(node, NST_MARK1);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
r = subexp_inf_recursive_check_trav(en->target, env);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
subexp_recursive_check(Node* node)
|
|
|
|
{
|
|
|
|
int r = 0;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
switch (NTYPE(node)) {
|
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r |= subexp_recursive_check(NCAR(node));
|
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = subexp_recursive_check(NQTFR(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = subexp_recursive_check(an->target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
r = subexp_recursive_check(NCALL(node)->target);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) SET_CALL_RECURSION(node);
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
if (IS_ENCLOSE_MARK2(NENCLOSE(node)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
2007-07-23 13:39:30 +04:00
|
|
|
else if (IS_ENCLOSE_MARK1(NENCLOSE(node)))
|
2004-03-05 18:31:51 +03:00
|
|
|
return 1; /* recursion */
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_MARK2);
|
|
|
|
r = subexp_recursive_check(NENCLOSE(node)->target);
|
|
|
|
CLEAR_ENCLOSE_STATUS(node, NST_MARK2);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
subexp_recursive_check_trav(Node* node, ScanEnv* env)
|
|
|
|
{
|
|
|
|
#define FOUND_CALLED_NODE 1
|
|
|
|
|
|
|
|
int type;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
ret = subexp_recursive_check_trav(NCAR(node), env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ret == FOUND_CALLED_NODE) r = FOUND_CALLED_NODE;
|
|
|
|
else if (ret < 0) return ret;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = subexp_recursive_check_trav(NQTFR(node)->target, env);
|
|
|
|
if (NQTFR(node)->upper == 0) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == FOUND_CALLED_NODE)
|
2007-07-23 13:39:30 +04:00
|
|
|
NQTFR(node)->is_refered = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = subexp_recursive_check_trav(an->target, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (! IS_ENCLOSE_RECURSION(en)) {
|
|
|
|
if (IS_ENCLOSE_CALLED(en)) {
|
|
|
|
SET_ENCLOSE_STATUS(node, NST_MARK1);
|
2004-03-05 18:31:51 +03:00
|
|
|
r = subexp_recursive_check(en->target);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (r != 0) SET_ENCLOSE_STATUS(node, NST_RECURSION);
|
|
|
|
CLEAR_ENCLOSE_STATUS(node, NST_MARK1);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r = subexp_recursive_check_trav(en->target, env);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_CALLED(en))
|
2004-03-05 18:31:51 +03:00
|
|
|
r |= FOUND_CALLED_NODE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
setup_subexp_call(Node* node, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = setup_subexp_call(NCAR(node), env);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = setup_subexp_call(NCAR(node), env);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
|
|
|
r = setup_subexp_call(NQTFR(node)->target, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
|
|
|
r = setup_subexp_call(NENCLOSE(node)->target, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
CallNode* cn = NCALL(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
Node** nodes = SCANENV_MEM_NODES(env);
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (cn->group_num != 0) {
|
|
|
|
int gnum = cn->group_num;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
if (env->num_named > 0 &&
|
|
|
|
IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
|
|
|
|
!ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) {
|
|
|
|
return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-03 18:55:04 +03:00
|
|
|
if (gnum > env->num_mem) {
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_scan_env_set_error_string(env,
|
|
|
|
ONIGERR_UNDEFINED_GROUP_REFERENCE, cn->name, cn->name_end);
|
|
|
|
return ONIGERR_UNDEFINED_GROUP_REFERENCE;
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
2004-03-05 18:31:51 +03:00
|
|
|
set_call_attr:
|
2008-01-03 18:55:04 +03:00
|
|
|
#endif
|
|
|
|
cn->target = nodes[cn->group_num];
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NULL(cn->target)) {
|
|
|
|
onig_scan_env_set_error_string(env,
|
2008-01-03 18:55:04 +03:00
|
|
|
ONIGERR_UNDEFINED_NAME_REFERENCE, cn->name, cn->name_end);
|
2004-03-05 18:31:51 +03:00
|
|
|
return ONIGERR_UNDEFINED_NAME_REFERENCE;
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(cn->target, NST_CALLED);
|
2008-01-03 18:55:04 +03:00
|
|
|
BIT_STATUS_ON_AT(env->bt_mem_start, cn->group_num);
|
2004-03-05 18:31:51 +03:00
|
|
|
cn->unset_addr_list = env->unset_addr_list;
|
|
|
|
}
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
2012-02-17 11:42:23 +04:00
|
|
|
#ifdef USE_PERL_SUBEXP_CALL
|
|
|
|
else if (cn->name == cn->name_end) {
|
|
|
|
goto set_call_attr;
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-03 18:55:04 +03:00
|
|
|
else {
|
|
|
|
int *refs;
|
|
|
|
|
|
|
|
int n = onig_name_to_group_numbers(env->reg, cn->name, cn->name_end,
|
|
|
|
&refs);
|
|
|
|
if (n <= 0) {
|
|
|
|
onig_scan_env_set_error_string(env,
|
|
|
|
ONIGERR_UNDEFINED_NAME_REFERENCE, cn->name, cn->name_end);
|
|
|
|
return ONIGERR_UNDEFINED_NAME_REFERENCE;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
else if (n > 1 &&
|
|
|
|
! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME_CALL)) {
|
2008-01-03 18:55:04 +03:00
|
|
|
onig_scan_env_set_error_string(env,
|
|
|
|
ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL, cn->name, cn->name_end);
|
|
|
|
return ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cn->group_num = refs[0];
|
|
|
|
goto set_call_attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
r = setup_subexp_call(an->target, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* divide different length alternatives in look-behind.
|
|
|
|
(?<=A|B) ==> (?<=A)|(?<=B)
|
|
|
|
(?<!A|B) ==> (?<!A)(?<!B)
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
divide_look_behind_alternatives(Node* node)
|
|
|
|
{
|
|
|
|
Node *head, *np, *insert_node;
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
int anc_type = an->type;
|
|
|
|
|
|
|
|
head = an->target;
|
2007-07-23 13:39:30 +04:00
|
|
|
np = NCAR(head);
|
|
|
|
swap_node(node, head);
|
|
|
|
NCAR(node) = head;
|
|
|
|
NANCHOR(head)->target = np;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
np = node;
|
2007-07-23 13:39:30 +04:00
|
|
|
while ((np = NCDR(np)) != NULL_NODE) {
|
2004-03-05 18:31:51 +03:00
|
|
|
insert_node = onig_node_new_anchor(anc_type);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(insert_node);
|
|
|
|
NANCHOR(insert_node)->target = NCAR(np);
|
|
|
|
NCAR(np) = insert_node;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (anc_type == ANCHOR_LOOK_BEHIND_NOT) {
|
|
|
|
np = node;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_NTYPE(np, NT_LIST); /* alt -> list */
|
|
|
|
} while ((np = NCDR(np)) != NULL_NODE);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
setup_look_behind(Node* node, regex_t* reg, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int r, len;
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
r = get_char_length_tree(an->target, reg, &len);
|
|
|
|
if (r == 0)
|
|
|
|
an->char_len = len;
|
|
|
|
else if (r == GET_CHAR_LEN_VARLEN)
|
|
|
|
r = ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
|
|
|
|
else if (r == GET_CHAR_LEN_TOP_ALT_VARLEN) {
|
|
|
|
if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND))
|
|
|
|
r = divide_look_behind_alternatives(node);
|
|
|
|
else
|
|
|
|
r = ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-02-17 11:42:23 +04:00
|
|
|
next_setup(Node* node, Node* next_node, int in_root, regex_t* reg)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
type = NTYPE(node);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (type == NT_QTFR) {
|
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->greedy && IS_REPEAT_INFINITE(qn->upper)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
#ifdef USE_QTFR_PEEK_NEXT
|
|
|
|
Node* n = get_head_value_node(next_node, 1, reg);
|
|
|
|
/* '\0': for UTF-16BE etc... */
|
|
|
|
if (IS_NOT_NULL(n) && NSTR(n)->s[0] != '\0') {
|
|
|
|
qn->next_head_exact = n;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
2012-02-17 11:42:23 +04:00
|
|
|
/* automatic possessivation a*b ==> (?>a*)b */
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->lower <= 1) {
|
|
|
|
int ttype = NTYPE(qn->target);
|
|
|
|
if (IS_NODE_TYPE_SIMPLE(ttype)) {
|
|
|
|
Node *x, *y;
|
|
|
|
x = get_head_value_node(qn->target, 0, reg);
|
|
|
|
if (IS_NOT_NULL(x)) {
|
|
|
|
y = get_head_value_node(next_node, 0, reg);
|
|
|
|
if (IS_NOT_NULL(y) && is_not_included(x, y, reg)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
Node* en = onig_node_new_enclose(ENCLOSE_STOP_BACKTRACK);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(en);
|
|
|
|
SET_ENCLOSE_STATUS(en, NST_STOP_BT_SIMPLE_REPEAT);
|
2004-03-05 18:31:51 +03:00
|
|
|
swap_node(node, en);
|
2007-07-23 13:39:30 +04:00
|
|
|
NENCLOSE(node)->target = en;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
#ifndef ONIG_DONT_OPTIMIZE
|
|
|
|
if (NTYPE(node) == NT_QTFR && /* the type may be changed by above block */
|
|
|
|
in_root && /* qn->lower == 0 && */
|
|
|
|
NTYPE(qn->target) == NT_CANY &&
|
|
|
|
! IS_MULTILINE(reg->options)) {
|
|
|
|
/* implicit anchor: /.*a/ ==> /(?:^|\G).*a/ */
|
|
|
|
Node *np;
|
|
|
|
np = onig_node_new_list(NULL_NODE, NULL_NODE);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(np);
|
|
|
|
swap_node(node, np);
|
|
|
|
NCDR(node) = onig_node_new_list(np, NULL_NODE);
|
|
|
|
if (IS_NULL(NCDR(node))) {
|
|
|
|
onig_node_free(np);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
np = onig_node_new_anchor(ANCHOR_ANYCHAR_STAR); /* (?:^|\G) */
|
|
|
|
CHECK_NULL_RETURN_MEMERR(np);
|
|
|
|
NCAR(node) = np;
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
else if (type == NT_ENCLOSE) {
|
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2012-02-17 11:42:23 +04:00
|
|
|
in_root = 0;
|
2007-07-23 13:39:30 +04:00
|
|
|
if (en->type == ENCLOSE_MEMORY) {
|
2004-03-05 18:31:51 +03:00
|
|
|
node = en->target;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-04 15:31:19 +03:00
|
|
|
|
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
update_string_node_case_fold(regex_t* reg, Node *node)
|
2006-02-04 15:31:19 +03:00
|
|
|
{
|
2012-03-05 11:40:51 +04:00
|
|
|
UChar *p, *end, buf[ONIGENC_MBC_CASE_FOLD_MAXLEN];
|
2007-05-23 05:32:08 +04:00
|
|
|
UChar *sbuf, *ebuf, *sp;
|
2011-01-31 06:44:57 +03:00
|
|
|
int r, i, len;
|
|
|
|
OnigDistance sbuf_size;
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
end = sn->end;
|
|
|
|
sbuf_size = (end - sn->s) * 2;
|
|
|
|
sbuf = (UChar* )xmalloc(sbuf_size);
|
2007-07-23 13:39:30 +04:00
|
|
|
CHECK_NULL_RETURN_MEMERR(sbuf);
|
2007-05-23 05:32:08 +04:00
|
|
|
ebuf = sbuf + sbuf_size;
|
2006-02-04 15:31:19 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
sp = sbuf;
|
|
|
|
p = sn->s;
|
|
|
|
while (p < end) {
|
|
|
|
len = ONIGENC_MBC_CASE_FOLD(reg->enc, reg->case_fold_flag, &p, end, buf);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (sp >= ebuf) {
|
2012-02-17 11:42:23 +04:00
|
|
|
UChar* p = (UChar* )xrealloc(sbuf, sbuf_size * 2);
|
|
|
|
if (IS_NULL(p)) {
|
|
|
|
xfree(sbuf);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
sbuf = p;
|
2007-05-23 05:32:08 +04:00
|
|
|
sp = sbuf + sbuf_size;
|
|
|
|
sbuf_size *= 2;
|
|
|
|
ebuf = sbuf + sbuf_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sp++ = buf[i];
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
r = onig_node_str_set(node, sbuf, sp);
|
|
|
|
if (r != 0) {
|
|
|
|
xfree(sbuf);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
xfree(sbuf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
expand_case_fold_make_rem_string(Node** rnode, UChar *s, UChar *end,
|
|
|
|
regex_t* reg)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
Node *node;
|
|
|
|
|
|
|
|
node = onig_node_new_str(s, end);
|
|
|
|
if (IS_NULL(node)) return ONIGERR_MEMORY;
|
|
|
|
|
|
|
|
r = update_string_node_case_fold(reg, node);
|
|
|
|
if (r != 0) {
|
|
|
|
onig_node_free(node);
|
|
|
|
return r;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
NSTRING_SET_AMBIG(node);
|
|
|
|
NSTRING_SET_DONT_GET_OPT_INFO(node);
|
|
|
|
*rnode = node;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
expand_case_fold_string_alt(int item_num, OnigCaseFoldCodeItem items[],
|
|
|
|
UChar *p, int slen, UChar *end,
|
|
|
|
regex_t* reg, Node **rnode)
|
|
|
|
{
|
2012-02-17 11:42:23 +04:00
|
|
|
int r, i, j, len, varlen, varclen;
|
2007-05-23 05:32:08 +04:00
|
|
|
Node *anode, *var_anode, *snode, *xnode, *an;
|
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
|
|
|
|
|
|
|
|
*rnode = var_anode = NULL_NODE;
|
|
|
|
|
|
|
|
varlen = 0;
|
2012-02-17 11:42:23 +04:00
|
|
|
varclen = 0;
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < item_num; i++) {
|
|
|
|
if (items[i].byte_len != slen) {
|
|
|
|
varlen = 1;
|
|
|
|
break;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
if (items[i].code_len != 1) {
|
|
|
|
varclen = 1;
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (varlen != 0) {
|
|
|
|
*rnode = var_anode = onig_node_new_alt(NULL_NODE, NULL_NODE);
|
|
|
|
if (IS_NULL(var_anode)) return ONIGERR_MEMORY;
|
|
|
|
|
|
|
|
xnode = onig_node_new_list(NULL, NULL);
|
|
|
|
if (IS_NULL(xnode)) goto mem_err;
|
2007-07-23 13:39:30 +04:00
|
|
|
NCAR(var_anode) = xnode;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
anode = onig_node_new_alt(NULL_NODE, NULL_NODE);
|
|
|
|
if (IS_NULL(anode)) goto mem_err;
|
2007-07-23 13:39:30 +04:00
|
|
|
NCAR(xnode) = anode;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-05-23 05:32:08 +04:00
|
|
|
*rnode = anode = onig_node_new_alt(NULL_NODE, NULL_NODE);
|
|
|
|
if (IS_NULL(anode)) return ONIGERR_MEMORY;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
snode = onig_node_new_str(p, p + slen);
|
|
|
|
if (IS_NULL(snode)) goto mem_err;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
NCAR(anode) = snode;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
for (i = 0; i < item_num; i++) {
|
|
|
|
snode = onig_node_new_str(NULL, NULL);
|
|
|
|
if (IS_NULL(snode)) goto mem_err;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
for (j = 0; j < items[i].code_len; j++) {
|
|
|
|
len = ONIGENC_CODE_TO_MBC(reg->enc, items[i].code[j], buf);
|
|
|
|
if (len < 0) {
|
|
|
|
r = len;
|
|
|
|
goto mem_err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = onig_node_str_cat(snode, buf, buf + len);
|
|
|
|
if (r != 0) goto mem_err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
an = onig_node_new_alt(NULL_NODE, NULL_NODE);
|
|
|
|
if (IS_NULL(an)) {
|
|
|
|
goto mem_err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items[i].byte_len != slen) {
|
|
|
|
Node *rem;
|
|
|
|
UChar *q = p + items[i].byte_len;
|
|
|
|
|
|
|
|
if (q < end) {
|
|
|
|
r = expand_case_fold_make_rem_string(&rem, q, end, reg);
|
|
|
|
if (r != 0) {
|
|
|
|
onig_node_free(an);
|
|
|
|
goto mem_err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
xnode = onig_node_list_add(NULL_NODE, snode);
|
|
|
|
if (IS_NULL(xnode)) {
|
|
|
|
onig_node_free(an);
|
|
|
|
onig_node_free(rem);
|
|
|
|
goto mem_err2;
|
|
|
|
}
|
|
|
|
if (IS_NULL(onig_node_list_add(xnode, rem))) {
|
|
|
|
onig_node_free(an);
|
|
|
|
onig_node_free(xnode);
|
|
|
|
onig_node_free(rem);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
NCAR(an) = xnode;
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
NCAR(an) = snode;
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
NCDR(var_anode) = an;
|
2007-05-23 05:32:08 +04:00
|
|
|
var_anode = an;
|
|
|
|
}
|
|
|
|
else {
|
2007-07-23 13:39:30 +04:00
|
|
|
NCAR(an) = snode;
|
|
|
|
NCDR(anode) = an;
|
2007-05-23 05:32:08 +04:00
|
|
|
anode = an;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if (varclen && !varlen)
|
|
|
|
return 2;
|
2007-05-23 05:32:08 +04:00
|
|
|
return varlen;
|
|
|
|
|
|
|
|
mem_err2:
|
|
|
|
onig_node_free(snode);
|
|
|
|
|
|
|
|
mem_err:
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_node_free(*rnode);
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
return ONIGERR_MEMORY;
|
2006-02-04 15:31:19 +03:00
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
static int
|
2007-05-23 05:32:08 +04:00
|
|
|
expand_case_fold_string(Node* node, regex_t* reg)
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
#define THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION 8
|
|
|
|
|
|
|
|
int r, n, len, alt_num;
|
2012-02-17 11:42:23 +04:00
|
|
|
int varlen = 0;
|
2007-05-23 05:32:08 +04:00
|
|
|
UChar *start, *end, *p;
|
|
|
|
Node *top_root, *root, *snode, *prev_node;
|
|
|
|
OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (NSTRING_IS_AMBIG(node)) return 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
start = sn->s;
|
|
|
|
end = sn->end;
|
|
|
|
if (start >= end) return 0;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
r = 0;
|
|
|
|
top_root = root = prev_node = snode = NULL_NODE;
|
|
|
|
alt_num = 1;
|
|
|
|
p = start;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
while (p < end) {
|
2007-05-23 05:32:08 +04:00
|
|
|
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(reg->enc, reg->case_fold_flag,
|
|
|
|
p, end, items);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (n < 0) {
|
|
|
|
r = n;
|
|
|
|
goto err;
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
len = enclen(reg->enc, p, end);
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
if (IS_NULL(snode)) {
|
|
|
|
if (IS_NULL(root) && IS_NOT_NULL(prev_node)) {
|
|
|
|
top_root = root = onig_node_list_add(NULL_NODE, prev_node);
|
|
|
|
if (IS_NULL(root)) {
|
|
|
|
onig_node_free(prev_node);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
prev_node = snode = onig_node_new_str(NULL, NULL);
|
|
|
|
if (IS_NULL(snode)) goto mem_err;
|
|
|
|
if (IS_NOT_NULL(root)) {
|
|
|
|
if (IS_NULL(onig_node_list_add(root, snode))) {
|
|
|
|
onig_node_free(snode);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
r = onig_node_str_cat(snode, p, p + len);
|
|
|
|
if (r != 0) goto err;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
else {
|
|
|
|
alt_num *= (n + 1);
|
|
|
|
if (alt_num > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) break;
|
|
|
|
|
|
|
|
if (IS_NULL(root) && IS_NOT_NULL(prev_node)) {
|
|
|
|
top_root = root = onig_node_list_add(NULL_NODE, prev_node);
|
|
|
|
if (IS_NULL(root)) {
|
|
|
|
onig_node_free(prev_node);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = expand_case_fold_string_alt(n, items, p, len, end, reg, &prev_node);
|
|
|
|
if (r < 0) goto mem_err;
|
2012-02-17 11:42:23 +04:00
|
|
|
if (r > 0) varlen = 1;
|
2007-05-23 05:32:08 +04:00
|
|
|
if (r == 1) {
|
|
|
|
if (IS_NULL(root)) {
|
|
|
|
top_root = prev_node;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_NULL(onig_node_list_add(root, prev_node))) {
|
|
|
|
onig_node_free(prev_node);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
root = NCAR(prev_node);
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
else { /* r == 0 || r == 2 */
|
2007-05-23 05:32:08 +04:00
|
|
|
if (IS_NOT_NULL(root)) {
|
|
|
|
if (IS_NULL(onig_node_list_add(root, prev_node))) {
|
|
|
|
onig_node_free(prev_node);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
snode = NULL_NODE;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
p += len;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (p < end) {
|
|
|
|
Node *srem;
|
|
|
|
|
|
|
|
r = expand_case_fold_make_rem_string(&srem, p, end, reg);
|
|
|
|
if (r != 0) goto mem_err;
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(prev_node) && IS_NULL(root)) {
|
|
|
|
top_root = root = onig_node_list_add(NULL_NODE, prev_node);
|
|
|
|
if (IS_NULL(root)) {
|
|
|
|
onig_node_free(srem);
|
|
|
|
onig_node_free(prev_node);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_NULL(root)) {
|
|
|
|
prev_node = srem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_NULL(onig_node_list_add(root, srem))) {
|
|
|
|
onig_node_free(srem);
|
|
|
|
goto mem_err;
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
/* ending */
|
|
|
|
top_root = (IS_NOT_NULL(top_root) ? top_root : prev_node);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (!varlen) {
|
|
|
|
/* When all expanded strings are same length, case-insensitive
|
|
|
|
BM search will be used. */
|
|
|
|
r = update_string_node_case_fold(reg, node);
|
|
|
|
if (r == 0) {
|
|
|
|
NSTRING_SET_AMBIG(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
swap_node(node, top_root);
|
|
|
|
r = 0;
|
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_node_free(top_root);
|
2012-02-17 11:42:23 +04:00
|
|
|
return r;
|
2007-05-23 05:32:08 +04:00
|
|
|
|
|
|
|
mem_err:
|
|
|
|
r = ONIGERR_MEMORY;
|
|
|
|
|
|
|
|
err:
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_node_free(top_root);
|
2007-05-23 05:32:08 +04:00
|
|
|
return r;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
|
2006-08-27 16:58:22 +04:00
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
|
|
|
|
|
|
|
#define CEC_THRES_NUM_BIG_REPEAT 512
|
|
|
|
#define CEC_INFINITE_NUM 0x7fffffff
|
|
|
|
|
|
|
|
#define CEC_IN_INFINITE_REPEAT (1<<0)
|
|
|
|
#define CEC_IN_FINITE_REPEAT (1<<1)
|
|
|
|
#define CEC_CONT_BIG_REPEAT (1<<2)
|
|
|
|
|
|
|
|
static int
|
|
|
|
setup_comb_exp_check(Node* node, int state, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int r = state;
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
Node* prev = NULL_NODE;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = setup_comb_exp_check(NCAR(node), r, env);
|
|
|
|
prev = NCAR(node);
|
|
|
|
} while (r >= 0 && IS_NOT_NULL(node = NCDR(node)));
|
2006-08-27 16:58:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
ret = setup_comb_exp_check(NCAR(node), state, env);
|
2006-08-27 16:58:22 +04:00
|
|
|
r |= ret;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (ret >= 0 && IS_NOT_NULL(node = NCDR(node)));
|
2006-08-27 16:58:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
int child_state = state;
|
|
|
|
int add_state = 0;
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2006-08-27 16:58:22 +04:00
|
|
|
Node* target = qn->target;
|
|
|
|
int var_num;
|
|
|
|
|
|
|
|
if (! IS_REPEAT_INFINITE(qn->upper)) {
|
|
|
|
if (qn->upper > 1) {
|
|
|
|
/* {0,1}, {1,1} are allowed */
|
|
|
|
child_state |= CEC_IN_FINITE_REPEAT;
|
|
|
|
|
|
|
|
/* check (a*){n,m}, (a+){n,m} => (a*){n,n}, (a+){n,n} */
|
|
|
|
if (env->backrefed_mem == 0) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(qn->target) == NT_ENCLOSE) {
|
|
|
|
EncloseNode* en = NENCLOSE(qn->target);
|
|
|
|
if (en->type == ENCLOSE_MEMORY) {
|
|
|
|
if (NTYPE(en->target) == NT_QTFR) {
|
|
|
|
QtfrNode* q = NQTFR(en->target);
|
2006-08-27 16:58:22 +04:00
|
|
|
if (IS_REPEAT_INFINITE(q->upper)
|
|
|
|
&& q->greedy == qn->greedy) {
|
|
|
|
qn->upper = (qn->lower == 0 ? 1 : qn->lower);
|
|
|
|
if (qn->upper == 1)
|
|
|
|
child_state = state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state & CEC_IN_FINITE_REPEAT) {
|
|
|
|
qn->comb_exp_check_num = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_REPEAT_INFINITE(qn->upper)) {
|
|
|
|
var_num = CEC_INFINITE_NUM;
|
|
|
|
child_state |= CEC_IN_INFINITE_REPEAT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var_num = qn->upper - qn->lower;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var_num >= CEC_THRES_NUM_BIG_REPEAT)
|
|
|
|
add_state |= CEC_CONT_BIG_REPEAT;
|
|
|
|
|
|
|
|
if (((state & CEC_IN_INFINITE_REPEAT) != 0 && var_num != 0) ||
|
|
|
|
((state & CEC_CONT_BIG_REPEAT) != 0 &&
|
|
|
|
var_num >= CEC_THRES_NUM_BIG_REPEAT)) {
|
|
|
|
if (qn->comb_exp_check_num == 0) {
|
|
|
|
env->num_comb_exp_check++;
|
|
|
|
qn->comb_exp_check_num = env->num_comb_exp_check;
|
|
|
|
if (env->curr_max_regnum > env->comb_exp_max_regnum)
|
|
|
|
env->comb_exp_max_regnum = env->curr_max_regnum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = setup_comb_exp_check(target, child_state, env);
|
|
|
|
r |= add_state;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2006-08-27 16:58:22 +04:00
|
|
|
|
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2006-08-27 16:58:22 +04:00
|
|
|
{
|
|
|
|
if (env->curr_max_regnum < en->regnum)
|
|
|
|
env->curr_max_regnum = en->regnum;
|
|
|
|
|
|
|
|
r = setup_comb_exp_check(en->target, state, env);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
r = setup_comb_exp_check(en->target, state, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
if (IS_CALL_RECURSION(NCALL(node)))
|
2006-08-27 16:58:22 +04:00
|
|
|
env->has_recursion = 1;
|
|
|
|
else
|
2007-07-23 13:39:30 +04:00
|
|
|
r = setup_comb_exp_check(NCALL(node)->target, state, env);
|
2006-08-27 16:58:22 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#define IN_ALT (1<<0)
|
|
|
|
#define IN_NOT (1<<1)
|
|
|
|
#define IN_REPEAT (1<<2)
|
|
|
|
#define IN_VAR_REPEAT (1<<3)
|
2012-02-17 11:42:23 +04:00
|
|
|
#define IN_ROOT (1<<4)
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
/* setup_tree does the following work.
|
|
|
|
1. check empty loop. (set qn->target_empty_info)
|
|
|
|
2. expand ignore-case in char class.
|
|
|
|
3. set memory status bit flags. (reg->mem_stats)
|
|
|
|
4. set qn->head_exact for [push, exact] -> [push_or_jump_exact1, exact].
|
|
|
|
5. find invalid patterns in look-behind.
|
|
|
|
6. expand repeated string.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int r = 0;
|
2012-02-17 11:42:23 +04:00
|
|
|
int in_root = state & IN_ROOT;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
state &= ~IN_ROOT;
|
2010-11-26 06:28:48 +03:00
|
|
|
restart:
|
2004-03-05 18:31:51 +03:00
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* prev = NULL_NODE;
|
2012-02-17 11:42:23 +04:00
|
|
|
int prev_in_root = 0;
|
|
|
|
state |= in_root;
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2010-08-17 20:53:25 +04:00
|
|
|
r = setup_tree(NCAR(node), reg, state, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NOT_NULL(prev) && r == 0) {
|
2012-02-17 11:42:23 +04:00
|
|
|
r = next_setup(prev, NCAR(node), prev_in_root, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
prev = NCAR(node);
|
2012-02-17 11:42:23 +04:00
|
|
|
prev_in_root = state & IN_ROOT;
|
|
|
|
state &= ~IN_ROOT;
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = setup_tree(NCAR(node), reg, (state | IN_ALT), env);
|
|
|
|
} while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_IGNORECASE(reg->options) && !NSTRING_IS_RAW(node)) {
|
2007-05-23 05:32:08 +04:00
|
|
|
r = expand_case_fold_string(node, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int* p;
|
|
|
|
Node** nodes = SCANENV_MEM_NODES(env);
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
p = BACKREFS_P(br);
|
|
|
|
for (i = 0; i < br->back_num; i++) {
|
|
|
|
if (p[i] > env->num_mem) return ONIGERR_INVALID_BACKREF;
|
|
|
|
BIT_STATUS_ON_AT(env->backrefed_mem, p[i]);
|
|
|
|
BIT_STATUS_ON_AT(env->bt_mem_start, p[i]);
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_BACKREF_WITH_LEVEL
|
2006-08-05 17:54:40 +04:00
|
|
|
if (IS_BACKREF_NEST_LEVEL(br)) {
|
|
|
|
BIT_STATUS_ON_AT(env->bt_mem_end, p[i]);
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(nodes[p[i]], NST_MEM_BACKREFED);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
OnigDistance d;
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
Node* target = qn->target;
|
|
|
|
|
2004-10-30 10:56:18 +04:00
|
|
|
if ((state & IN_REPEAT) != 0) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
qn->state |= NST_IN_REPEAT;
|
2004-10-30 10:56:18 +04:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_REPEAT_INFINITE(qn->upper) || qn->upper >= 1) {
|
|
|
|
r = get_min_match_length(target, &d, env);
|
|
|
|
if (r) break;
|
|
|
|
if (d == 0) {
|
|
|
|
qn->target_empty_info = NQ_TARGET_IS_EMPTY;
|
2008-01-03 18:55:04 +03:00
|
|
|
#ifdef USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT
|
2007-05-23 05:32:08 +04:00
|
|
|
r = quantifiers_memory_node_info(target);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) break;
|
|
|
|
if (r > 0) {
|
|
|
|
qn->target_empty_info = r;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
r = get_max_match_length(target, &d, env);
|
|
|
|
if (r == 0 && d == 0) {
|
|
|
|
/* ()* ==> ()?, ()+ ==> () */
|
|
|
|
qn->upper = 1;
|
|
|
|
if (qn->lower > 1) qn->lower = 1;
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(target) == NT_STR) {
|
2004-03-05 18:31:51 +03:00
|
|
|
qn->upper = qn->lower = 0; /* /(?:)+/ ==> // */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
state |= IN_REPEAT;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (qn->lower != qn->upper)
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
state |= IN_VAR_REPEAT;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = setup_tree(target, reg, state, env);
|
|
|
|
if (r) break;
|
|
|
|
|
|
|
|
/* expand string */
|
|
|
|
#define EXPAND_STRING_MAX_LENGTH 100
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(target) == NT_STR) {
|
2012-02-17 11:42:23 +04:00
|
|
|
if (qn->lower > 1) {
|
|
|
|
int i, n = qn->lower;
|
2011-01-31 06:44:57 +03:00
|
|
|
OnigDistance len = NSTRING_LEN(target);
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(target);
|
2012-02-17 11:42:23 +04:00
|
|
|
Node* np;
|
|
|
|
|
|
|
|
np = onig_node_new_str(sn->s, sn->end);
|
|
|
|
if (IS_NULL(np)) return ONIGERR_MEMORY;
|
|
|
|
NSTR(np)->flag = sn->flag;
|
|
|
|
|
|
|
|
for (i = 1; i < n && (i+1) * len <= EXPAND_STRING_MAX_LENGTH; i++) {
|
|
|
|
r = onig_node_str_cat(np, sn->s, sn->end);
|
|
|
|
if (r) {
|
|
|
|
onig_node_free(np);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i < qn->upper || IS_REPEAT_INFINITE(qn->upper)) {
|
|
|
|
Node *np1, *np2;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
qn->lower -= i;
|
|
|
|
if (! IS_REPEAT_INFINITE(qn->upper))
|
|
|
|
qn->upper -= i;
|
|
|
|
|
|
|
|
np1 = onig_node_new_list(np, NULL);
|
|
|
|
if (IS_NULL(np1)) {
|
|
|
|
onig_node_free(np);
|
|
|
|
return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
swap_node(np1, node);
|
|
|
|
np2 = onig_node_list_add(node, np1);
|
|
|
|
if (IS_NULL(np2)) {
|
|
|
|
onig_node_free(np1);
|
|
|
|
return ONIGERR_MEMORY;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
else {
|
|
|
|
swap_node(np, node);
|
|
|
|
onig_node_free(np);
|
|
|
|
}
|
|
|
|
break; /* break case NT_QTFR: */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_OP_PUSH_OR_JUMP_EXACT
|
|
|
|
if (qn->greedy && (qn->target_empty_info != 0)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(target) == NT_QTFR) {
|
|
|
|
QtfrNode* tqn = NQTFR(target);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NOT_NULL(tqn->head_exact)) {
|
|
|
|
qn->head_exact = tqn->head_exact;
|
|
|
|
tqn->head_exact = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qn->head_exact = get_head_value_node(qn->target, 1, reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
OnigOptionType options = reg->options;
|
2012-02-17 11:42:23 +04:00
|
|
|
state |= in_root;
|
2007-07-23 13:39:30 +04:00
|
|
|
reg->options = NENCLOSE(node)->option;
|
|
|
|
r = setup_tree(NENCLOSE(node)->target, reg, state, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->options = options;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if ((state & (IN_ALT | IN_NOT | IN_VAR_REPEAT)) != 0) {
|
2004-03-05 18:31:51 +03:00
|
|
|
BIT_STATUS_ON_AT(env->bt_mem_start, en->regnum);
|
2007-07-23 13:39:30 +04:00
|
|
|
/* SET_ENCLOSE_STATUS(node, NST_MEM_IN_ALT_NOT); */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
r = setup_tree(en->target, reg, state, env);
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
Node* target = en->target;
|
|
|
|
r = setup_tree(target, reg, state, env);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NTYPE(target) == NT_QTFR) {
|
|
|
|
QtfrNode* tqn = NQTFR(target);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_REPEAT_INFINITE(tqn->upper) && tqn->lower <= 1 &&
|
|
|
|
tqn->greedy != 0) { /* (?>a*), a*+ etc... */
|
|
|
|
int qtype = NTYPE(tqn->target);
|
|
|
|
if (IS_NODE_TYPE_SIMPLE(qtype))
|
2007-07-23 13:39:30 +04:00
|
|
|
SET_ENCLOSE_STATUS(node, NST_STOP_BT_SIMPLE_REPEAT);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-02-17 11:42:23 +04:00
|
|
|
|
|
|
|
case ENCLOSE_CONDITION:
|
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
if (! IS_ENCLOSE_NAME_REF(NENCLOSE(node)) &&
|
|
|
|
env->num_named > 0 &&
|
|
|
|
IS_SYNTAX_BV(env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
|
|
|
|
!ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_CAPTURE_GROUP)) {
|
|
|
|
return ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
r = setup_tree(NENCLOSE(node)->target, reg, state, env);
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
AnchorNode* an = NANCHOR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
switch (an->type) {
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
r = setup_tree(an->target, reg, state, env);
|
|
|
|
break;
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
r = setup_tree(an->target, reg, (state | IN_NOT), env);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* allowed node types in look-behind */
|
|
|
|
#define ALLOWED_TYPE_IN_LB \
|
2007-07-23 13:39:30 +04:00
|
|
|
( BIT_NT_LIST | BIT_NT_ALT | BIT_NT_STR | BIT_NT_CCLASS | BIT_NT_CTYPE | \
|
|
|
|
BIT_NT_CANY | BIT_NT_ANCHOR | BIT_NT_ENCLOSE | BIT_NT_QTFR | BIT_NT_CALL )
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
#define ALLOWED_ENCLOSE_IN_LB ( ENCLOSE_MEMORY )
|
|
|
|
#define ALLOWED_ENCLOSE_IN_LB_NOT 0
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#define ALLOWED_ANCHOR_IN_LB \
|
2012-02-17 11:42:23 +04:00
|
|
|
( ANCHOR_LOOK_BEHIND | ANCHOR_LOOK_BEHIND_NOT | ANCHOR_BEGIN_LINE | \
|
|
|
|
ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION | ANCHOR_KEEP | \
|
|
|
|
ANCHOR_WORD_BOUND | ANCHOR_NOT_WORD_BOUND | \
|
|
|
|
ANCHOR_WORD_BEGIN | ANCHOR_WORD_END )
|
2004-03-05 18:31:51 +03:00
|
|
|
#define ALLOWED_ANCHOR_IN_LB_NOT \
|
2012-02-17 11:42:23 +04:00
|
|
|
( ANCHOR_LOOK_BEHIND | ANCHOR_LOOK_BEHIND_NOT | ANCHOR_BEGIN_LINE | \
|
|
|
|
ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION | ANCHOR_KEEP | \
|
|
|
|
ANCHOR_WORD_BOUND | ANCHOR_NOT_WORD_BOUND | \
|
|
|
|
ANCHOR_WORD_BEGIN | ANCHOR_WORD_END )
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
case ANCHOR_LOOK_BEHIND:
|
|
|
|
{
|
|
|
|
r = check_type_tree(an->target, ALLOWED_TYPE_IN_LB,
|
2007-07-23 13:39:30 +04:00
|
|
|
ALLOWED_ENCLOSE_IN_LB, ALLOWED_ANCHOR_IN_LB);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
|
|
|
if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
|
|
|
|
r = setup_look_behind(node, reg, env);
|
|
|
|
if (r != 0) return r;
|
2010-11-26 06:28:48 +03:00
|
|
|
if (NTYPE(node) != NT_ANCHOR) goto restart;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = setup_tree(an->target, reg, state, env);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
{
|
|
|
|
r = check_type_tree(an->target, ALLOWED_TYPE_IN_LB,
|
2007-07-23 13:39:30 +04:00
|
|
|
ALLOWED_ENCLOSE_IN_LB_NOT, ALLOWED_ANCHOR_IN_LB_NOT);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r < 0) return r;
|
|
|
|
if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
|
|
|
|
r = setup_look_behind(node, reg, env);
|
|
|
|
if (r != 0) return r;
|
2010-11-26 06:28:48 +03:00
|
|
|
if (NTYPE(node) != NT_ANCHOR) goto restart;
|
2004-03-05 18:31:51 +03:00
|
|
|
r = setup_tree(an->target, reg, (state | IN_NOT), env);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
#ifndef USE_SUNDAY_QUICK_SEARCH
|
|
|
|
/* set skip map for Boyer-Moore search */
|
2004-03-05 18:31:51 +03:00
|
|
|
static int
|
2012-02-17 11:42:23 +04:00
|
|
|
set_bm_skip(UChar* s, UChar* end, regex_t* reg,
|
|
|
|
UChar skip[], int** int_skip, int ignore_case)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2011-01-31 06:44:57 +03:00
|
|
|
OnigDistance i, len;
|
2012-02-17 11:42:23 +04:00
|
|
|
int clen, flen, n, j, k;
|
|
|
|
UChar *p, buf[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM][ONIGENC_MBC_CASE_FOLD_MAXLEN];
|
|
|
|
OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
|
|
|
|
OnigEncoding enc = reg->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
len = end - s;
|
|
|
|
if (len < ONIG_CHAR_TABLE_SIZE) {
|
2012-02-17 11:42:23 +04:00
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = (UChar )len;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (i = 0; i < len - 1; i += clen) {
|
|
|
|
p = s + i;
|
|
|
|
if (ignore_case)
|
|
|
|
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
|
|
|
|
p, end, items);
|
|
|
|
clen = enclen(enc, p, end);
|
|
|
|
|
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
if ((items[j].code_len != 1) || (items[j].byte_len != clen))
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
|
|
|
|
if (flen != clen)
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
}
|
|
|
|
for (j = 0; j < clen; j++) {
|
|
|
|
skip[s[i + j]] = (UChar )(len - 1 - i - j);
|
|
|
|
for (k = 0; k < n; k++) {
|
|
|
|
skip[buf[k][j]] = (UChar )(len - 1 - i - j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_NULL(*int_skip)) {
|
|
|
|
*int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
|
|
|
|
if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = (int )len;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (i = 0; i < len - 1; i += clen) {
|
|
|
|
p = s + i;
|
|
|
|
if (ignore_case)
|
|
|
|
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
|
|
|
|
p, end, items);
|
|
|
|
clen = enclen(enc, p, end);
|
|
|
|
|
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
if ((items[j].code_len != 1) || (items[j].byte_len != clen))
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
|
|
|
|
if (flen != clen)
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
}
|
|
|
|
for (j = 0; j < clen; j++) {
|
|
|
|
(*int_skip)[s[i + j]] = (int )(len - 1 - i - j);
|
|
|
|
for (k = 0; k < n; k++) {
|
|
|
|
(*int_skip)[buf[k][j]] = (int )(len - 1 - i - j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* USE_SUNDAY_QUICK_SEARCH */
|
|
|
|
|
|
|
|
/* set skip map for Sunday's quick search */
|
|
|
|
static int
|
|
|
|
set_bm_skip(UChar* s, UChar* end, regex_t* reg,
|
|
|
|
UChar skip[], int** int_skip, int ignore_case)
|
|
|
|
{
|
|
|
|
OnigDistance i, len;
|
|
|
|
int clen, flen, n, j, k;
|
|
|
|
UChar *p, buf[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM][ONIGENC_MBC_CASE_FOLD_MAXLEN];
|
|
|
|
OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
|
|
|
|
OnigEncoding enc = reg->enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
len = end - s;
|
|
|
|
if (len < ONIG_CHAR_TABLE_SIZE) {
|
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = (UChar )(len + 1);
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (i = 0; i < len; i += clen) {
|
|
|
|
p = s + i;
|
|
|
|
if (ignore_case)
|
|
|
|
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
|
|
|
|
p, end, items);
|
|
|
|
clen = enclen(enc, p, end);
|
|
|
|
|
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
if ((items[j].code_len != 1) || (items[j].byte_len != clen))
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
|
|
|
|
if (flen != clen)
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
}
|
|
|
|
for (j = 0; j < clen; j++) {
|
|
|
|
skip[s[i + j]] = (UChar )(len - i - j);
|
|
|
|
for (k = 0; k < n; k++) {
|
|
|
|
skip[buf[k][j]] = (UChar )(len - i - j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (IS_NULL(*int_skip)) {
|
|
|
|
*int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
|
|
|
|
if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = (int )(len + 1);
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (i = 0; i < len; i += clen) {
|
|
|
|
p = s + i;
|
|
|
|
if (ignore_case)
|
|
|
|
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, reg->case_fold_flag,
|
|
|
|
p, end, items);
|
|
|
|
clen = enclen(enc, p, end);
|
|
|
|
|
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
if ((items[j].code_len != 1) || (items[j].byte_len != clen))
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
|
|
|
|
if (flen != clen)
|
|
|
|
return 1; /* different length isn't supported. */
|
|
|
|
}
|
|
|
|
for (j = 0; j < clen; j++) {
|
|
|
|
(*int_skip)[s[i + j]] = (int )(len - i - j);
|
|
|
|
for (k = 0; k < n; k++) {
|
|
|
|
(*int_skip)[buf[k][j]] = (int )(len - i - j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-17 11:42:23 +04:00
|
|
|
#endif /* USE_SUNDAY_QUICK_SEARCH */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#define OPT_EXACT_MAXLEN 24
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
OnigDistance min; /* min byte length */
|
|
|
|
OnigDistance max; /* max byte length */
|
|
|
|
} MinMaxLen;
|
|
|
|
|
|
|
|
typedef struct {
|
2007-05-23 05:32:08 +04:00
|
|
|
MinMaxLen mmd;
|
|
|
|
OnigEncoding enc;
|
|
|
|
OnigOptionType options;
|
|
|
|
OnigCaseFoldType case_fold_flag;
|
|
|
|
ScanEnv* scan_env;
|
2004-03-05 18:31:51 +03:00
|
|
|
} OptEnv;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int left_anchor;
|
|
|
|
int right_anchor;
|
|
|
|
} OptAncInfo;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MinMaxLen mmd; /* info position */
|
|
|
|
OptAncInfo anc;
|
|
|
|
|
|
|
|
int reach_end;
|
2013-03-01 20:36:37 +04:00
|
|
|
int ignore_case; /* -1: unset, 0: case sensitive, 1: ignore case */
|
2004-03-05 18:31:51 +03:00
|
|
|
int len;
|
|
|
|
UChar s[OPT_EXACT_MAXLEN];
|
|
|
|
} OptExactInfo;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MinMaxLen mmd; /* info position */
|
|
|
|
OptAncInfo anc;
|
|
|
|
|
|
|
|
int value; /* weighted value */
|
|
|
|
UChar map[ONIG_CHAR_TABLE_SIZE];
|
|
|
|
} OptMapInfo;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MinMaxLen len;
|
|
|
|
|
|
|
|
OptAncInfo anc;
|
|
|
|
OptExactInfo exb; /* boundary */
|
|
|
|
OptExactInfo exm; /* middle */
|
|
|
|
OptExactInfo expr; /* prec read (?=...) */
|
|
|
|
|
|
|
|
OptMapInfo map; /* boundary */
|
|
|
|
} NodeOptInfo;
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
map_position_value(OnigEncoding enc, int i)
|
|
|
|
{
|
2006-02-04 15:31:19 +03:00
|
|
|
static const short int ByteValTable[] = {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
5, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 10, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
12, 4, 7, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5,
|
|
|
|
5, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 5, 5, 5,
|
|
|
|
5, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 1
|
|
|
|
};
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (i < (int )(sizeof(ByteValTable)/sizeof(ByteValTable[0]))) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
if (i == 0 && ONIGENC_MBC_MINLEN(enc) > 1)
|
|
|
|
return 20;
|
|
|
|
else
|
|
|
|
return (int )ByteValTable[i];
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
else
|
|
|
|
return 4; /* Take it easy. */
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
distance_value(MinMaxLen* mm)
|
|
|
|
{
|
|
|
|
/* 1000 / (min-max-dist + 1) */
|
2006-02-04 15:31:19 +03:00
|
|
|
static const short int dist_vals[] = {
|
2009-02-22 17:23:33 +03:00
|
|
|
1000, 500, 333, 250, 200, 167, 143, 125, 111, 100,
|
|
|
|
91, 83, 77, 71, 67, 63, 59, 56, 53, 50,
|
|
|
|
48, 45, 43, 42, 40, 38, 37, 36, 34, 33,
|
|
|
|
32, 31, 30, 29, 29, 28, 27, 26, 26, 25,
|
|
|
|
24, 24, 23, 23, 22, 22, 21, 21, 20, 20,
|
|
|
|
20, 19, 19, 19, 18, 18, 18, 17, 17, 17,
|
|
|
|
16, 16, 16, 16, 15, 15, 15, 15, 14, 14,
|
|
|
|
14, 14, 14, 14, 13, 13, 13, 13, 13, 13,
|
|
|
|
12, 12, 12, 12, 12, 12, 11, 11, 11, 11,
|
2004-03-05 18:31:51 +03:00
|
|
|
11, 11, 11, 11, 11, 10, 10, 10, 10, 10
|
|
|
|
};
|
|
|
|
|
2011-01-31 06:44:57 +03:00
|
|
|
OnigDistance d;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (mm->max == ONIG_INFINITE_DISTANCE) return 0;
|
|
|
|
|
|
|
|
d = mm->max - mm->min;
|
2011-01-31 06:44:57 +03:00
|
|
|
if (d < sizeof(dist_vals)/sizeof(dist_vals[0]))
|
2004-03-05 18:31:51 +03:00
|
|
|
/* return dist_vals[d] * 16 / (mm->min + 12); */
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return (int )dist_vals[d];
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
comp_distance_value(MinMaxLen* d1, MinMaxLen* d2, int v1, int v2)
|
|
|
|
{
|
|
|
|
if (v2 <= 0) return -1;
|
|
|
|
if (v1 <= 0) return 1;
|
|
|
|
|
|
|
|
v1 *= distance_value(d1);
|
|
|
|
v2 *= distance_value(d2);
|
|
|
|
|
|
|
|
if (v2 > v1) return 1;
|
|
|
|
if (v2 < v1) return -1;
|
|
|
|
|
|
|
|
if (d2->min < d1->min) return 1;
|
|
|
|
if (d2->min > d1->min) return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_equal_mml(MinMaxLen* a, MinMaxLen* b)
|
|
|
|
{
|
|
|
|
return (a->min == b->min && a->max == b->max) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_mml(MinMaxLen* mml, OnigDistance min, OnigDistance max)
|
|
|
|
{
|
|
|
|
mml->min = min;
|
|
|
|
mml->max = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_mml(MinMaxLen* mml)
|
|
|
|
{
|
|
|
|
mml->min = mml->max = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_mml(MinMaxLen* to, MinMaxLen* from)
|
|
|
|
{
|
|
|
|
to->min = from->min;
|
|
|
|
to->max = from->max;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_mml(MinMaxLen* to, MinMaxLen* from)
|
|
|
|
{
|
|
|
|
to->min = distance_add(to->min, from->min);
|
|
|
|
to->max = distance_add(to->max, from->max);
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#if 0
|
2004-03-05 18:31:51 +03:00
|
|
|
static void
|
|
|
|
add_len_mml(MinMaxLen* to, OnigDistance len)
|
|
|
|
{
|
|
|
|
to->min = distance_add(to->min, len);
|
|
|
|
to->max = distance_add(to->max, len);
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
alt_merge_mml(MinMaxLen* to, MinMaxLen* from)
|
|
|
|
{
|
|
|
|
if (to->min > from->min) to->min = from->min;
|
|
|
|
if (to->max < from->max) to->max = from->max;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_opt_env(OptEnv* to, OptEnv* from)
|
|
|
|
{
|
|
|
|
*to = *from;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_opt_anc_info(OptAncInfo* anc)
|
|
|
|
{
|
|
|
|
anc->left_anchor = 0;
|
|
|
|
anc->right_anchor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_opt_anc_info(OptAncInfo* to, OptAncInfo* from)
|
|
|
|
{
|
|
|
|
*to = *from;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
concat_opt_anc_info(OptAncInfo* to, OptAncInfo* left, OptAncInfo* right,
|
|
|
|
OnigDistance left_len, OnigDistance right_len)
|
|
|
|
{
|
|
|
|
clear_opt_anc_info(to);
|
|
|
|
|
|
|
|
to->left_anchor = left->left_anchor;
|
|
|
|
if (left_len == 0) {
|
|
|
|
to->left_anchor |= right->left_anchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
to->right_anchor = right->right_anchor;
|
|
|
|
if (right_len == 0) {
|
|
|
|
to->right_anchor |= left->right_anchor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_left_anchor(int anc)
|
|
|
|
{
|
|
|
|
if (anc == ANCHOR_END_BUF || anc == ANCHOR_SEMI_END_BUF ||
|
|
|
|
anc == ANCHOR_END_LINE || anc == ANCHOR_PREC_READ ||
|
|
|
|
anc == ANCHOR_PREC_READ_NOT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_set_opt_anc_info(OptAncInfo* to, int anc)
|
|
|
|
{
|
|
|
|
if ((to->left_anchor & anc) != 0) return 1;
|
|
|
|
|
|
|
|
return ((to->right_anchor & anc) != 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_opt_anc_info(OptAncInfo* to, int anc)
|
|
|
|
{
|
|
|
|
if (is_left_anchor(anc))
|
|
|
|
to->left_anchor |= anc;
|
|
|
|
else
|
|
|
|
to->right_anchor |= anc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_opt_anc_info(OptAncInfo* to, int anc)
|
|
|
|
{
|
|
|
|
if (is_left_anchor(anc))
|
|
|
|
to->left_anchor &= ~anc;
|
|
|
|
else
|
|
|
|
to->right_anchor &= ~anc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
alt_merge_opt_anc_info(OptAncInfo* to, OptAncInfo* add)
|
|
|
|
{
|
|
|
|
to->left_anchor &= add->left_anchor;
|
|
|
|
to->right_anchor &= add->right_anchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_full_opt_exact_info(OptExactInfo* ex)
|
|
|
|
{
|
|
|
|
return (ex->len >= OPT_EXACT_MAXLEN ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_opt_exact_info(OptExactInfo* ex)
|
|
|
|
{
|
|
|
|
clear_mml(&ex->mmd);
|
|
|
|
clear_opt_anc_info(&ex->anc);
|
|
|
|
ex->reach_end = 0;
|
2013-03-01 20:36:37 +04:00
|
|
|
ex->ignore_case = -1; /* unset */
|
2004-03-05 18:31:51 +03:00
|
|
|
ex->len = 0;
|
|
|
|
ex->s[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_opt_exact_info(OptExactInfo* to, OptExactInfo* from)
|
|
|
|
{
|
|
|
|
*to = *from;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-08-05 17:54:40 +04:00
|
|
|
concat_opt_exact_info(OptExactInfo* to, OptExactInfo* add, OnigEncoding enc)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2006-08-05 17:54:40 +04:00
|
|
|
int i, j, len;
|
|
|
|
UChar *p, *end;
|
2004-03-05 18:31:51 +03:00
|
|
|
OptAncInfo tanc;
|
|
|
|
|
2013-03-01 20:36:37 +04:00
|
|
|
if (to->ignore_case < 0)
|
|
|
|
to->ignore_case = add->ignore_case;
|
|
|
|
else if (to->ignore_case != add->ignore_case)
|
|
|
|
return ; /* avoid */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2006-08-05 17:54:40 +04:00
|
|
|
p = add->s;
|
|
|
|
end = p + add->len;
|
|
|
|
for (i = to->len; p < end; ) {
|
2008-01-03 18:55:04 +03:00
|
|
|
len = enclen(enc, p, end);
|
2006-08-05 17:54:40 +04:00
|
|
|
if (i + len > OPT_EXACT_MAXLEN) break;
|
|
|
|
for (j = 0; j < len && p < end; j++)
|
|
|
|
to->s[i++] = *p++;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
to->len = i;
|
2006-08-05 17:54:40 +04:00
|
|
|
to->reach_end = (p == end ? add->reach_end : 0);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
concat_opt_anc_info(&tanc, &to->anc, &add->anc, 1, 1);
|
|
|
|
if (! to->reach_end) tanc.right_anchor = 0;
|
|
|
|
copy_opt_anc_info(&to->anc, &tanc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-03 18:55:04 +03:00
|
|
|
concat_opt_exact_info_str(OptExactInfo* to, UChar* s, UChar* end,
|
|
|
|
int raw ARG_UNUSED, OnigEncoding enc)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, j, len;
|
|
|
|
UChar *p;
|
|
|
|
|
|
|
|
for (i = to->len, p = s; p < end && i < OPT_EXACT_MAXLEN; ) {
|
2008-01-03 18:55:04 +03:00
|
|
|
len = enclen(enc, p, end);
|
2006-08-05 17:54:40 +04:00
|
|
|
if (i + len > OPT_EXACT_MAXLEN) break;
|
|
|
|
for (j = 0; j < len && p < end; j++)
|
2004-03-05 18:31:51 +03:00
|
|
|
to->s[i++] = *p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
to->len = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
alt_merge_opt_exact_info(OptExactInfo* to, OptExactInfo* add, OptEnv* env)
|
|
|
|
{
|
|
|
|
int i, j, len;
|
|
|
|
|
|
|
|
if (add->len == 0 || to->len == 0) {
|
|
|
|
clear_opt_exact_info(to);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! is_equal_mml(&to->mmd, &add->mmd)) {
|
|
|
|
clear_opt_exact_info(to);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < to->len && i < add->len; ) {
|
|
|
|
if (to->s[i] != add->s[i]) break;
|
2008-01-03 18:55:04 +03:00
|
|
|
len = enclen(env->enc, to->s + i, to->s + to->len);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
for (j = 1; j < len; j++) {
|
|
|
|
if (to->s[i+j] != add->s[i+j]) break;
|
|
|
|
}
|
|
|
|
if (j < len) break;
|
|
|
|
i += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! add->reach_end || i < add->len || i < to->len) {
|
|
|
|
to->reach_end = 0;
|
|
|
|
}
|
|
|
|
to->len = i;
|
2013-03-01 20:36:37 +04:00
|
|
|
if (to->ignore_case < 0)
|
|
|
|
to->ignore_case = add->ignore_case;
|
|
|
|
else if (add->ignore_case >= 0)
|
|
|
|
to->ignore_case |= add->ignore_case;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
alt_merge_opt_anc_info(&to->anc, &add->anc);
|
|
|
|
if (! to->reach_end) to->anc.right_anchor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
select_opt_exact_info(OnigEncoding enc, OptExactInfo* now, OptExactInfo* alt)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int v1, v2;
|
|
|
|
|
|
|
|
v1 = now->len;
|
|
|
|
v2 = alt->len;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (v2 == 0) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
else if (v1 == 0) {
|
|
|
|
copy_opt_exact_info(now, alt);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
else if (v1 <= 2 && v2 <= 2) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
/* ByteValTable[x] is big value --> low price */
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
v2 = map_position_value(enc, now->s[0]);
|
|
|
|
v1 = map_position_value(enc, alt->s[0]);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (now->len > 1) v1 += 5;
|
|
|
|
if (alt->len > 1) v2 += 5;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:36:37 +04:00
|
|
|
if (now->ignore_case <= 0) v1 *= 2;
|
|
|
|
if (alt->ignore_case <= 0) v2 *= 2;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
if (comp_distance_value(&now->mmd, &alt->mmd, v1, v2) > 0)
|
2004-03-05 18:31:51 +03:00
|
|
|
copy_opt_exact_info(now, alt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_opt_map_info(OptMapInfo* map)
|
|
|
|
{
|
2006-02-04 15:31:19 +03:00
|
|
|
static const OptMapInfo clean_info = {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
{0, 0}, {0, 0}, 0,
|
|
|
|
{
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
}
|
|
|
|
};
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
xmemcpy(map, &clean_info, sizeof(OptMapInfo));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_opt_map_info(OptMapInfo* to, OptMapInfo* from)
|
|
|
|
{
|
|
|
|
*to = *from;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_char_opt_map_info(OptMapInfo* map, UChar c, OnigEncoding enc)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (map->map[c] == 0) {
|
|
|
|
map->map[c] = 1;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
map->value += map_position_value(enc, c);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
static int
|
|
|
|
add_char_amb_opt_map_info(OptMapInfo* map, UChar* p, UChar* end,
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigEncoding enc, OnigCaseFoldType case_fold_flag)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-05-23 05:32:08 +04:00
|
|
|
OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
|
|
|
|
UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
|
|
|
|
int i, n;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_char_opt_map_info(map, p[0], enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
case_fold_flag = DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag);
|
|
|
|
n = ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc, case_fold_flag, p, end, items);
|
|
|
|
if (n < 0) return n;
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
ONIGENC_CODE_TO_MBC(enc, items[i].code[0], buf);
|
|
|
|
add_char_opt_map_info(map, buf[0], enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-05-23 05:32:08 +04:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
return 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_opt_map_info(OptMapInfo* now, OptMapInfo* alt)
|
|
|
|
{
|
2008-07-01 12:21:44 +04:00
|
|
|
const int z = 1<<15; /* 32768: something big value */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
int v1, v2;
|
|
|
|
|
|
|
|
if (alt->value == 0) return ;
|
|
|
|
if (now->value == 0) {
|
|
|
|
copy_opt_map_info(now, alt);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
v1 = z / now->value;
|
|
|
|
v2 = z / alt->value;
|
|
|
|
if (comp_distance_value(&now->mmd, &alt->mmd, v1, v2) > 0)
|
|
|
|
copy_opt_map_info(now, alt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
comp_opt_exact_or_map_info(OptExactInfo* e, OptMapInfo* m)
|
|
|
|
{
|
|
|
|
#define COMP_EM_BASE 20
|
|
|
|
int ve, vm;
|
|
|
|
|
|
|
|
if (m->value <= 0) return -1;
|
|
|
|
|
2013-03-01 20:36:37 +04:00
|
|
|
ve = COMP_EM_BASE * e->len * (e->ignore_case > 0 ? 1 : 2);
|
2004-03-05 18:31:51 +03:00
|
|
|
vm = COMP_EM_BASE * 5 * 2 / m->value;
|
|
|
|
return comp_distance_value(&e->mmd, &m->mmd, ve, vm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
alt_merge_opt_map_info(OnigEncoding enc, OptMapInfo* to, OptMapInfo* add)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, val;
|
|
|
|
|
|
|
|
/* if (! is_equal_mml(&to->mmd, &add->mmd)) return ; */
|
|
|
|
if (to->value == 0) return ;
|
|
|
|
if (add->value == 0 || to->mmd.max < add->mmd.min) {
|
|
|
|
clear_opt_map_info(to);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
alt_merge_mml(&to->mmd, &add->mmd);
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) {
|
|
|
|
if (add->map[i])
|
|
|
|
to->map[i] = 1;
|
|
|
|
|
|
|
|
if (to->map[i])
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
val += map_position_value(enc, i);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
to->value = val;
|
|
|
|
|
|
|
|
alt_merge_opt_anc_info(&to->anc, &add->anc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_bound_node_opt_info(NodeOptInfo* opt, MinMaxLen* mmd)
|
|
|
|
{
|
|
|
|
copy_mml(&(opt->exb.mmd), mmd);
|
|
|
|
copy_mml(&(opt->expr.mmd), mmd);
|
|
|
|
copy_mml(&(opt->map.mmd), mmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_node_opt_info(NodeOptInfo* opt)
|
|
|
|
{
|
|
|
|
clear_mml(&opt->len);
|
|
|
|
clear_opt_anc_info(&opt->anc);
|
|
|
|
clear_opt_exact_info(&opt->exb);
|
|
|
|
clear_opt_exact_info(&opt->exm);
|
|
|
|
clear_opt_exact_info(&opt->expr);
|
|
|
|
clear_opt_map_info(&opt->map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_node_opt_info(NodeOptInfo* to, NodeOptInfo* from)
|
|
|
|
{
|
|
|
|
*to = *from;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
concat_left_node_opt_info(OnigEncoding enc, NodeOptInfo* to, NodeOptInfo* add)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int exb_reach, exm_reach;
|
|
|
|
OptAncInfo tanc;
|
|
|
|
|
|
|
|
concat_opt_anc_info(&tanc, &to->anc, &add->anc, to->len.max, add->len.max);
|
|
|
|
copy_opt_anc_info(&to->anc, &tanc);
|
|
|
|
|
|
|
|
if (add->exb.len > 0 && to->len.max == 0) {
|
|
|
|
concat_opt_anc_info(&tanc, &to->anc, &add->exb.anc,
|
|
|
|
to->len.max, add->len.max);
|
|
|
|
copy_opt_anc_info(&add->exb.anc, &tanc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add->map.value > 0 && to->len.max == 0) {
|
|
|
|
if (add->map.mmd.max == 0)
|
|
|
|
add->map.anc.left_anchor |= to->anc.left_anchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
exb_reach = to->exb.reach_end;
|
|
|
|
exm_reach = to->exm.reach_end;
|
|
|
|
|
|
|
|
if (add->len.max != 0)
|
|
|
|
to->exb.reach_end = to->exm.reach_end = 0;
|
|
|
|
|
|
|
|
if (add->exb.len > 0) {
|
|
|
|
if (exb_reach) {
|
2006-08-05 17:54:40 +04:00
|
|
|
concat_opt_exact_info(&to->exb, &add->exb, enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
clear_opt_exact_info(&add->exb);
|
|
|
|
}
|
|
|
|
else if (exm_reach) {
|
2006-08-05 17:54:40 +04:00
|
|
|
concat_opt_exact_info(&to->exm, &add->exb, enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
clear_opt_exact_info(&add->exb);
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
select_opt_exact_info(enc, &to->exm, &add->exb);
|
|
|
|
select_opt_exact_info(enc, &to->exm, &add->exm);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (to->expr.len > 0) {
|
|
|
|
if (add->len.max > 0) {
|
|
|
|
if (to->expr.len > (int )add->len.max)
|
2012-02-17 11:42:23 +04:00
|
|
|
to->expr.len = (int )add->len.max;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (to->expr.mmd.max == 0)
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
select_opt_exact_info(enc, &to->exb, &to->expr);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
select_opt_exact_info(enc, &to->exm, &to->expr);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (add->expr.len > 0) {
|
|
|
|
copy_opt_exact_info(&to->expr, &add->expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
select_opt_map_info(&to->map, &add->map);
|
|
|
|
|
|
|
|
add_mml(&to->len, &add->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
alt_merge_node_opt_info(NodeOptInfo* to, NodeOptInfo* add, OptEnv* env)
|
|
|
|
{
|
|
|
|
alt_merge_opt_anc_info (&to->anc, &add->anc);
|
|
|
|
alt_merge_opt_exact_info(&to->exb, &add->exb, env);
|
|
|
|
alt_merge_opt_exact_info(&to->exm, &add->exm, env);
|
|
|
|
alt_merge_opt_exact_info(&to->expr, &add->expr, env);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
alt_merge_opt_map_info(env->enc, &to->map, &add->map);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
alt_merge_mml(&to->len, &add->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_NODE_OPT_INFO_REF_COUNT 5
|
|
|
|
|
|
|
|
static int
|
|
|
|
optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
clear_node_opt_info(opt);
|
|
|
|
set_bound_node_opt_info(opt, &env->mmd);
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
OptEnv nenv;
|
|
|
|
NodeOptInfo nopt;
|
|
|
|
Node* nd = node;
|
|
|
|
|
|
|
|
copy_opt_env(&nenv, env);
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = optimize_node_left(NCAR(nd), &nopt, &nenv);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0) {
|
|
|
|
add_mml(&nenv.mmd, &nopt.len);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
concat_left_node_opt_info(env->enc, opt, &nopt);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
} while (r == 0 && IS_NOT_NULL(nd = NCDR(nd)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ALT:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
NodeOptInfo nopt;
|
|
|
|
Node* nd = node;
|
|
|
|
|
|
|
|
do {
|
2007-07-23 13:39:30 +04:00
|
|
|
r = optimize_node_left(NCAR(nd), &nopt, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0) {
|
|
|
|
if (nd == node) copy_node_opt_info(opt, &nopt);
|
|
|
|
else alt_merge_node_opt_info(opt, &nopt, env);
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
} while ((r == 0) && IS_NOT_NULL(nd = NCDR(nd)));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
StrNode* sn = NSTR(node);
|
2011-01-31 06:44:57 +03:00
|
|
|
OnigDistance slen = sn->end - sn->s;
|
2004-03-05 18:31:51 +03:00
|
|
|
int is_raw = NSTRING_IS_RAW(node);
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (! NSTRING_IS_AMBIG(node)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
concat_opt_exact_info_str(&opt->exb, sn->s, sn->end,
|
2013-03-01 20:36:37 +04:00
|
|
|
is_raw, env->enc);
|
|
|
|
opt->exb.ignore_case = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
if (slen > 0) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_char_opt_map_info(&opt->map, *(sn->s), env->enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
set_mml(&opt->len, slen, slen);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2011-01-31 06:44:57 +03:00
|
|
|
OnigDistance max;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
if (NSTRING_IS_DONT_GET_OPT_INFO(node)) {
|
|
|
|
int n = onigenc_strlen(env->enc, sn->s, sn->end);
|
|
|
|
max = ONIGENC_MBC_MAXLEN_DIST(env->enc) * n;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
concat_opt_exact_info_str(&opt->exb, sn->s, sn->end,
|
|
|
|
is_raw, env->enc);
|
|
|
|
opt->exb.ignore_case = 1;
|
|
|
|
|
|
|
|
if (slen > 0) {
|
|
|
|
r = add_char_amb_opt_map_info(&opt->map, sn->s, sn->end,
|
|
|
|
env->enc, env->case_fold_flag);
|
|
|
|
if (r != 0) break;
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
max = slen;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
|
|
|
|
set_mml(&opt->len, slen, max);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if ((OnigDistance )opt->exb.len == slen)
|
2004-03-05 18:31:51 +03:00
|
|
|
opt->exb.reach_end = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int i, z;
|
2007-07-23 13:39:30 +04:00
|
|
|
CClassNode* cc = NCCLASS(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2013-04-13 15:30:35 +04:00
|
|
|
/* no need to check ignore case. (set in setup_tree()) */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NOT_NULL(cc->mbuf) || IS_NCCLASS_NOT(cc)) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigDistance min = ONIGENC_MBC_MINLEN(env->enc);
|
|
|
|
OnigDistance max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
set_mml(&opt->len, min, max);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
else {
|
|
|
|
for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
|
|
|
|
z = BITSET_AT(cc->bs, i);
|
2007-07-23 13:39:30 +04:00
|
|
|
if ((z && !IS_NCCLASS_NOT(cc)) || (!z && IS_NCCLASS_NOT(cc))) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
add_char_opt_map_info(&opt->map, (UChar )i, env->enc);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set_mml(&opt->len, 1, 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int i, min, max;
|
2012-02-17 11:42:23 +04:00
|
|
|
int maxcode;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
if (max == 1) {
|
|
|
|
min = 1;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
maxcode = NCTYPE(node)->ascii_range ? 0x80 : SINGLE_BYTE_SIZE;
|
2007-07-23 13:39:30 +04:00
|
|
|
switch (NCTYPE(node)->ctype) {
|
2007-05-23 05:32:08 +04:00
|
|
|
case ONIGENC_CTYPE_WORD:
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NCTYPE(node)->not != 0) {
|
2007-05-23 05:32:08 +04:00
|
|
|
for (i = 0; i < SINGLE_BYTE_SIZE; i++) {
|
2012-02-17 11:42:23 +04:00
|
|
|
if (! ONIGENC_IS_CODE_WORD(env->enc, i) || i >= maxcode) {
|
2007-05-23 05:32:08 +04:00
|
|
|
add_char_opt_map_info(&opt->map, (UChar )i, env->enc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-02-17 11:42:23 +04:00
|
|
|
for (i = 0; i < maxcode; i++) {
|
2007-05-23 05:32:08 +04:00
|
|
|
if (ONIGENC_IS_CODE_WORD(env->enc, i)) {
|
|
|
|
add_char_opt_map_info(&opt->map, (UChar )i, env->enc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
else {
|
|
|
|
min = ONIGENC_MBC_MINLEN(env->enc);
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
set_mml(&opt->len, min, max);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CANY:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigDistance min = ONIGENC_MBC_MINLEN(env->enc);
|
|
|
|
OnigDistance max = ONIGENC_MBC_MAXLEN_DIST(env->enc);
|
|
|
|
set_mml(&opt->len, min, max);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
|
|
|
switch (NANCHOR(node)->type) {
|
2004-03-05 18:31:51 +03:00
|
|
|
case ANCHOR_BEGIN_BUF:
|
|
|
|
case ANCHOR_BEGIN_POSITION:
|
|
|
|
case ANCHOR_BEGIN_LINE:
|
|
|
|
case ANCHOR_END_BUF:
|
|
|
|
case ANCHOR_SEMI_END_BUF:
|
|
|
|
case ANCHOR_END_LINE:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ANCHOR_LOOK_BEHIND: /* just for (?<=x).* */
|
2007-07-23 13:39:30 +04:00
|
|
|
add_opt_anc_info(&opt->anc, NANCHOR(node)->type);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ANCHOR_PREC_READ:
|
|
|
|
{
|
|
|
|
NodeOptInfo nopt;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
r = optimize_node_left(NANCHOR(node)->target, &nopt, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r == 0) {
|
|
|
|
if (nopt.exb.len > 0)
|
|
|
|
copy_opt_exact_info(&opt->expr, &nopt.exb);
|
|
|
|
else if (nopt.exm.len > 0)
|
|
|
|
copy_opt_exact_info(&opt->expr, &nopt.exm);
|
|
|
|
|
|
|
|
opt->expr.reach_end = 0;
|
|
|
|
|
|
|
|
if (nopt.map.value > 0)
|
|
|
|
copy_opt_map_info(&opt->map, &nopt.map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANCHOR_PREC_READ_NOT:
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int* backs;
|
|
|
|
OnigDistance min, max, tmin, tmax;
|
|
|
|
Node** nodes = SCANENV_MEM_NODES(env->scan_env);
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (br->state & NST_RECURSION) {
|
|
|
|
set_mml(&opt->len, 0, ONIG_INFINITE_DISTANCE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
backs = BACKREFS_P(br);
|
|
|
|
r = get_min_match_length(nodes[backs[0]], &min, env->scan_env);
|
|
|
|
if (r != 0) break;
|
|
|
|
r = get_max_match_length(nodes[backs[0]], &max, env->scan_env);
|
|
|
|
if (r != 0) break;
|
|
|
|
for (i = 1; i < br->back_num; i++) {
|
|
|
|
r = get_min_match_length(nodes[backs[i]], &tmin, env->scan_env);
|
|
|
|
if (r != 0) break;
|
|
|
|
r = get_max_match_length(nodes[backs[i]], &tmax, env->scan_env);
|
|
|
|
if (r != 0) break;
|
|
|
|
if (min > tmin) min = tmin;
|
|
|
|
if (max < tmax) max = tmax;
|
|
|
|
}
|
|
|
|
if (r == 0) set_mml(&opt->len, min, max);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
|
|
|
if (IS_CALL_RECURSION(NCALL(node)))
|
2004-03-05 18:31:51 +03:00
|
|
|
set_mml(&opt->len, 0, ONIG_INFINITE_DISTANCE);
|
|
|
|
else {
|
|
|
|
OnigOptionType save = env->options;
|
2007-07-23 13:39:30 +04:00
|
|
|
env->options = NENCLOSE(NCALL(node)->target)->option;
|
|
|
|
r = optimize_node_left(NCALL(node)->target, opt, env);
|
2004-03-05 18:31:51 +03:00
|
|
|
env->options = save;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
OnigDistance min, max;
|
|
|
|
NodeOptInfo nopt;
|
2007-07-23 13:39:30 +04:00
|
|
|
QtfrNode* qn = NQTFR(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
r = optimize_node_left(qn->target, &nopt, env);
|
|
|
|
if (r) break;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
if (/*qn->lower == 0 &&*/ IS_REPEAT_INFINITE(qn->upper)) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (env->mmd.max == 0 &&
|
2007-07-23 13:39:30 +04:00
|
|
|
NTYPE(qn->target) == NT_CANY && qn->greedy) {
|
2006-02-12 18:05:19 +03:00
|
|
|
if (IS_MULTILINE(env->options))
|
2012-02-17 11:42:23 +04:00
|
|
|
/* implicit anchor: /.*a/ ==> /\A.*a/ */
|
2006-02-12 18:05:19 +03:00
|
|
|
add_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR_ML);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
|
|
|
add_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (qn->lower > 0) {
|
|
|
|
copy_node_opt_info(opt, &nopt);
|
|
|
|
if (nopt.exb.len > 0) {
|
|
|
|
if (nopt.exb.reach_end) {
|
2009-12-21 12:13:28 +03:00
|
|
|
for (i = 2; i <= qn->lower &&
|
2004-03-05 18:31:51 +03:00
|
|
|
! is_full_opt_exact_info(&opt->exb); i++) {
|
2006-08-05 17:54:40 +04:00
|
|
|
concat_opt_exact_info(&opt->exb, &nopt.exb, env->enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
if (i < qn->lower) {
|
|
|
|
opt->exb.reach_end = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qn->lower != qn->upper) {
|
|
|
|
opt->exb.reach_end = 0;
|
|
|
|
opt->exm.reach_end = 0;
|
|
|
|
}
|
|
|
|
if (qn->lower > 1)
|
|
|
|
opt->exm.reach_end = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
min = distance_multiply(nopt.len.min, qn->lower);
|
|
|
|
if (IS_REPEAT_INFINITE(qn->upper))
|
|
|
|
max = (nopt.len.max > 0 ? ONIG_INFINITE_DISTANCE : 0);
|
|
|
|
else
|
|
|
|
max = distance_multiply(nopt.len.max, qn->upper);
|
|
|
|
|
|
|
|
set_mml(&opt->len, min, max);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
EncloseNode* en = NENCLOSE(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
switch (en->type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_OPTION:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
OnigOptionType save = env->options;
|
|
|
|
|
|
|
|
env->options = en->option;
|
|
|
|
r = optimize_node_left(en->target, opt, env);
|
|
|
|
env->options = save;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
en->opt_count++;
|
|
|
|
if (en->opt_count > MAX_NODE_OPT_INFO_REF_COUNT) {
|
|
|
|
OnigDistance min, max;
|
|
|
|
|
|
|
|
min = 0;
|
|
|
|
max = ONIG_INFINITE_DISTANCE;
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_ENCLOSE_MIN_FIXED(en)) min = en->min_len;
|
|
|
|
if (IS_ENCLOSE_MAX_FIXED(en)) max = en->max_len;
|
2004-03-05 18:31:51 +03:00
|
|
|
set_mml(&opt->len, min, max);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
r = optimize_node_left(en->target, opt, env);
|
|
|
|
|
|
|
|
if (is_set_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR_MASK)) {
|
2005-03-01 15:23:17 +03:00
|
|
|
if (BIT_STATUS_AT(env->scan_env->backrefed_mem, en->regnum))
|
2004-03-05 18:31:51 +03:00
|
|
|
remove_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_STAR_MASK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
2004-03-05 18:31:51 +03:00
|
|
|
r = optimize_node_left(en->target, opt, env);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#ifdef ONIG_DEBUG
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) fprintf(stderr, "optimize_node_left: undefined node type %d\n",
|
2004-03-05 18:31:51 +03:00
|
|
|
NTYPE(node));
|
|
|
|
#endif
|
|
|
|
r = ONIGERR_TYPE_BUG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_optimize_exact_info(regex_t* reg, OptExactInfo* e)
|
|
|
|
{
|
|
|
|
int r;
|
2012-02-17 11:42:23 +04:00
|
|
|
int allow_reverse;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if (e->len == 0) return 0;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
reg->exact = (UChar* )xmalloc(e->len);
|
|
|
|
CHECK_NULL_RETURN_MEMERR(reg->exact);
|
|
|
|
xmemcpy(reg->exact, e->s, e->len);
|
|
|
|
reg->exact_end = reg->exact + e->len;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
allow_reverse =
|
2004-03-05 18:31:51 +03:00
|
|
|
ONIGENC_IS_ALLOWED_REVERSE_MATCH(reg->enc, reg->exact, reg->exact_end);
|
|
|
|
|
2013-03-01 20:36:37 +04:00
|
|
|
if (e->ignore_case > 0) {
|
2012-02-17 11:42:23 +04:00
|
|
|
if (e->len >= 3 || (e->len >= 2 && allow_reverse)) {
|
|
|
|
r = set_bm_skip(reg->exact, reg->exact_end, reg,
|
|
|
|
reg->map, &(reg->int_map), 1);
|
|
|
|
if (r == 0) {
|
|
|
|
reg->optimize = (allow_reverse != 0
|
|
|
|
? ONIG_OPTIMIZE_EXACT_BM_IC : ONIG_OPTIMIZE_EXACT_BM_NOT_REV_IC);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reg->optimize = ONIG_OPTIMIZE_EXACT_IC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reg->optimize = ONIG_OPTIMIZE_EXACT_IC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (e->len >= 3 || (e->len >= 2 && allow_reverse)) {
|
2012-02-17 11:42:23 +04:00
|
|
|
r = set_bm_skip(reg->exact, reg->exact_end, reg,
|
|
|
|
reg->map, &(reg->int_map), 0);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
reg->optimize = (allow_reverse != 0
|
|
|
|
? ONIG_OPTIMIZE_EXACT_BM : ONIG_OPTIMIZE_EXACT_BM_NOT_REV);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reg->optimize = ONIG_OPTIMIZE_EXACT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reg->dmin = e->mmd.min;
|
|
|
|
reg->dmax = e->mmd.max;
|
|
|
|
|
|
|
|
if (reg->dmin != ONIG_INFINITE_DISTANCE) {
|
2012-02-17 11:42:23 +04:00
|
|
|
reg->threshold_len = (int )(reg->dmin + (reg->exact_end - reg->exact));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_optimize_map_info(regex_t* reg, OptMapInfo* m)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
|
|
|
|
reg->map[i] = m->map[i];
|
|
|
|
|
|
|
|
reg->optimize = ONIG_OPTIMIZE_MAP;
|
|
|
|
reg->dmin = m->mmd.min;
|
|
|
|
reg->dmax = m->mmd.max;
|
|
|
|
|
|
|
|
if (reg->dmin != ONIG_INFINITE_DISTANCE) {
|
2012-02-17 11:42:23 +04:00
|
|
|
reg->threshold_len = (int )(reg->dmin + 1);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_sub_anchor(regex_t* reg, OptAncInfo* anc)
|
|
|
|
{
|
|
|
|
reg->sub_anchor |= anc->left_anchor & ANCHOR_BEGIN_LINE;
|
|
|
|
reg->sub_anchor |= anc->right_anchor & ANCHOR_END_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG
|
|
|
|
static void print_optimize_info(FILE* f, regex_t* reg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
set_optimize_info_from_tree(Node* node, regex_t* reg, ScanEnv* scan_env)
|
|
|
|
{
|
|
|
|
|
|
|
|
int r;
|
|
|
|
NodeOptInfo opt;
|
|
|
|
OptEnv env;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
env.enc = reg->enc;
|
|
|
|
env.options = reg->options;
|
|
|
|
env.case_fold_flag = reg->case_fold_flag;
|
2004-03-05 18:31:51 +03:00
|
|
|
env.scan_env = scan_env;
|
|
|
|
clear_mml(&env.mmd);
|
|
|
|
|
|
|
|
r = optimize_node_left(node, &opt, &env);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
reg->anchor = opt.anc.left_anchor & (ANCHOR_BEGIN_BUF |
|
2012-02-17 11:42:23 +04:00
|
|
|
ANCHOR_BEGIN_POSITION | ANCHOR_ANYCHAR_STAR | ANCHOR_ANYCHAR_STAR_ML |
|
|
|
|
ANCHOR_LOOK_BEHIND);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
reg->anchor |= opt.anc.right_anchor & (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF);
|
|
|
|
|
|
|
|
if (reg->anchor & (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF)) {
|
|
|
|
reg->anchor_dmin = opt.len.min;
|
|
|
|
reg->anchor_dmax = opt.len.max;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt.exb.len > 0 || opt.exm.len > 0) {
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
select_opt_exact_info(reg->enc, &opt.exb, &opt.exm);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (opt.map.value > 0 &&
|
|
|
|
comp_opt_exact_or_map_info(&opt.exb, &opt.map) > 0) {
|
|
|
|
goto set_map;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r = set_optimize_exact_info(reg, &opt.exb);
|
|
|
|
set_sub_anchor(reg, &opt.exb.anc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (opt.map.value > 0) {
|
|
|
|
set_map:
|
|
|
|
set_optimize_map_info(reg, &opt.map);
|
|
|
|
set_sub_anchor(reg, &opt.map.anc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reg->sub_anchor |= opt.anc.left_anchor & ANCHOR_BEGIN_LINE;
|
|
|
|
if (opt.len.max == 0)
|
|
|
|
reg->sub_anchor |= opt.anc.right_anchor & ANCHOR_END_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH)
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) print_optimize_info(stderr, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_optimize_info(regex_t* reg)
|
|
|
|
{
|
|
|
|
reg->optimize = ONIG_OPTIMIZE_NONE;
|
|
|
|
reg->anchor = 0;
|
|
|
|
reg->anchor_dmin = 0;
|
|
|
|
reg->anchor_dmax = 0;
|
|
|
|
reg->sub_anchor = 0;
|
|
|
|
reg->exact_end = (UChar* )NULL;
|
|
|
|
reg->threshold_len = 0;
|
|
|
|
if (IS_NOT_NULL(reg->exact)) {
|
|
|
|
xfree(reg->exact);
|
|
|
|
reg->exact = (UChar* )NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
static void print_enc_string(FILE* fp, OnigEncoding enc,
|
|
|
|
const UChar *s, const UChar *end)
|
|
|
|
{
|
|
|
|
fprintf(fp, "\nPATTERN: /");
|
|
|
|
|
|
|
|
if (ONIGENC_MBC_MINLEN(enc) > 1) {
|
|
|
|
const UChar *p;
|
|
|
|
OnigCodePoint code;
|
|
|
|
|
|
|
|
p = s;
|
|
|
|
while (p < end) {
|
|
|
|
code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
|
|
|
if (code >= 0x80) {
|
|
|
|
fprintf(fp, " 0x%04x ", (int )code);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputc((int )code, fp);
|
|
|
|
}
|
|
|
|
|
2009-12-21 04:11:15 +03:00
|
|
|
p += enclen(enc, p, end);
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (s < end) {
|
|
|
|
fputc((int )*s, fp);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:04:51 +03:00
|
|
|
fprintf(fp, "/ (%s)\n", enc->name);
|
2007-05-23 05:32:08 +04:00
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
static void
|
|
|
|
print_distance_range(FILE* f, OnigDistance a, OnigDistance b)
|
|
|
|
{
|
|
|
|
if (a == ONIG_INFINITE_DISTANCE)
|
|
|
|
fputs("inf", f);
|
|
|
|
else
|
2010-11-25 17:14:44 +03:00
|
|
|
fprintf(f, "(%"PRIuSIZE")", a);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
fputs("-", f);
|
|
|
|
|
|
|
|
if (b == ONIG_INFINITE_DISTANCE)
|
|
|
|
fputs("inf", f);
|
|
|
|
else
|
2010-11-25 17:14:44 +03:00
|
|
|
fprintf(f, "(%"PRIuSIZE")", b);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_anchor(FILE* f, int anchor)
|
|
|
|
{
|
|
|
|
int q = 0;
|
|
|
|
|
|
|
|
fprintf(f, "[");
|
|
|
|
|
|
|
|
if (anchor & ANCHOR_BEGIN_BUF) {
|
|
|
|
fprintf(f, "begin-buf");
|
|
|
|
q = 1;
|
|
|
|
}
|
|
|
|
if (anchor & ANCHOR_BEGIN_LINE) {
|
|
|
|
if (q) fprintf(f, ", ");
|
|
|
|
q = 1;
|
|
|
|
fprintf(f, "begin-line");
|
|
|
|
}
|
|
|
|
if (anchor & ANCHOR_BEGIN_POSITION) {
|
|
|
|
if (q) fprintf(f, ", ");
|
|
|
|
q = 1;
|
|
|
|
fprintf(f, "begin-pos");
|
|
|
|
}
|
|
|
|
if (anchor & ANCHOR_END_BUF) {
|
|
|
|
if (q) fprintf(f, ", ");
|
|
|
|
q = 1;
|
|
|
|
fprintf(f, "end-buf");
|
|
|
|
}
|
|
|
|
if (anchor & ANCHOR_SEMI_END_BUF) {
|
|
|
|
if (q) fprintf(f, ", ");
|
|
|
|
q = 1;
|
|
|
|
fprintf(f, "semi-end-buf");
|
|
|
|
}
|
|
|
|
if (anchor & ANCHOR_END_LINE) {
|
|
|
|
if (q) fprintf(f, ", ");
|
|
|
|
q = 1;
|
|
|
|
fprintf(f, "end-line");
|
|
|
|
}
|
|
|
|
if (anchor & ANCHOR_ANYCHAR_STAR) {
|
|
|
|
if (q) fprintf(f, ", ");
|
|
|
|
q = 1;
|
|
|
|
fprintf(f, "anychar-star");
|
|
|
|
}
|
2006-02-12 18:05:19 +03:00
|
|
|
if (anchor & ANCHOR_ANYCHAR_STAR_ML) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (q) fprintf(f, ", ");
|
2012-02-17 11:42:23 +04:00
|
|
|
fprintf(f, "anychar-star-ml");
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(f, "]");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_optimize_info(FILE* f, regex_t* reg)
|
|
|
|
{
|
2006-02-04 15:31:19 +03:00
|
|
|
static const char* on[] = { "NONE", "EXACT", "EXACT_BM", "EXACT_BM_NOT_REV",
|
2012-02-17 11:42:23 +04:00
|
|
|
"EXACT_IC", "MAP",
|
|
|
|
"EXACT_BM_IC", "EXACT_BM_NOT_REV_IC" };
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
fprintf(f, "optimize: %s\n", on[reg->optimize]);
|
|
|
|
fprintf(f, " anchor: "); print_anchor(f, reg->anchor);
|
|
|
|
if ((reg->anchor & ANCHOR_END_BUF_MASK) != 0)
|
|
|
|
print_distance_range(f, reg->anchor_dmin, reg->anchor_dmax);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
|
|
|
|
if (reg->optimize) {
|
|
|
|
fprintf(f, " sub anchor: "); print_anchor(f, reg->sub_anchor);
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
fprintf(f, "\n");
|
|
|
|
|
|
|
|
if (reg->exact) {
|
|
|
|
UChar *p;
|
|
|
|
fprintf(f, "exact: [");
|
|
|
|
for (p = reg->exact; p < reg->exact_end; p++) {
|
|
|
|
fputc(*p, f);
|
|
|
|
}
|
2010-11-25 17:14:44 +03:00
|
|
|
fprintf(f, "]: length: %ld\n", (reg->exact_end - reg->exact));
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
else if (reg->optimize & ONIG_OPTIMIZE_MAP) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
int c, i, n = 0;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
|
|
|
|
if (reg->map[i]) n++;
|
|
|
|
|
|
|
|
fprintf(f, "map: n=%d\n", n);
|
|
|
|
if (n > 0) {
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
c = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
fputc('[', f);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) {
|
|
|
|
if (reg->map[i] != 0) {
|
|
|
|
if (c > 0) fputs(", ", f);
|
|
|
|
c++;
|
|
|
|
if (ONIGENC_MBC_MAXLEN(reg->enc) == 1 &&
|
|
|
|
ONIGENC_IS_CODE_PRINT(reg->enc, (OnigCodePoint )i))
|
|
|
|
fputc(i, f);
|
|
|
|
else
|
|
|
|
fprintf(f, "%d", i);
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
fprintf(f, "]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* ONIG_DEBUG */
|
|
|
|
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
extern void
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_free_body(regex_t* reg)
|
|
|
|
{
|
2010-03-02 00:54:59 +03:00
|
|
|
if (IS_NOT_NULL(reg)) {
|
|
|
|
if (IS_NOT_NULL(reg->p)) xfree(reg->p);
|
|
|
|
if (IS_NOT_NULL(reg->exact)) xfree(reg->exact);
|
|
|
|
if (IS_NOT_NULL(reg->int_map)) xfree(reg->int_map);
|
|
|
|
if (IS_NOT_NULL(reg->int_map_backward)) xfree(reg->int_map_backward);
|
|
|
|
if (IS_NOT_NULL(reg->repeat_range)) xfree(reg->repeat_range);
|
|
|
|
if (IS_NOT_NULL(reg->chain)) onig_free(reg->chain);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#ifdef USE_NAMED_GROUP
|
2010-03-02 00:54:59 +03:00
|
|
|
onig_names_free(reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
2010-03-02 00:54:59 +03:00
|
|
|
}
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
|
|
|
onig_free(regex_t* reg)
|
|
|
|
{
|
|
|
|
if (IS_NOT_NULL(reg)) {
|
|
|
|
onig_free_body(reg);
|
|
|
|
xfree(reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-17 02:36:27 +04:00
|
|
|
size_t
|
2010-08-14 10:17:38 +04:00
|
|
|
onig_memsize(const regex_t *reg)
|
2009-06-17 02:36:27 +04:00
|
|
|
{
|
|
|
|
size_t size = sizeof(regex_t);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_NULL(reg)) return 0;
|
2009-06-17 02:36:27 +04:00
|
|
|
if (IS_NOT_NULL(reg->p)) size += reg->alloc;
|
|
|
|
if (IS_NOT_NULL(reg->exact)) size += reg->exact_end - reg->exact;
|
|
|
|
if (IS_NOT_NULL(reg->int_map)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE;
|
|
|
|
if (IS_NOT_NULL(reg->int_map_backward)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE;
|
|
|
|
if (IS_NOT_NULL(reg->repeat_range)) size += reg->repeat_range_alloc * sizeof(OnigRepeatRange);
|
|
|
|
if (IS_NOT_NULL(reg->chain)) size += onig_memsize(reg->chain);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-12-15 08:15:54 +04:00
|
|
|
size_t
|
|
|
|
onig_region_memsize(const OnigRegion *regs)
|
|
|
|
{
|
|
|
|
size_t size = sizeof(*regs);
|
2012-02-17 11:42:23 +04:00
|
|
|
if (IS_NULL(regs)) return 0;
|
2011-12-15 08:15:54 +04:00
|
|
|
size += regs->allocated * (sizeof(*regs->beg) + sizeof(*regs->end));
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#define REGEX_TRANSFER(to,from) do {\
|
|
|
|
(to)->state = ONIG_STATE_MODIFY;\
|
|
|
|
onig_free_body(to);\
|
|
|
|
xmemcpy(to, from, sizeof(regex_t));\
|
|
|
|
xfree(from);\
|
|
|
|
} while (0)
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
extern void
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_transfer(regex_t* to, regex_t* from)
|
|
|
|
{
|
|
|
|
THREAD_ATOMIC_START;
|
|
|
|
REGEX_TRANSFER(to, from);
|
|
|
|
THREAD_ATOMIC_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define REGEX_CHAIN_HEAD(reg) do {\
|
|
|
|
while (IS_NOT_NULL((reg)->chain)) {\
|
|
|
|
(reg) = (reg)->chain;\
|
|
|
|
}\
|
|
|
|
} while (0)
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
extern void
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_chain_link_add(regex_t* to, regex_t* add)
|
|
|
|
{
|
|
|
|
THREAD_ATOMIC_START;
|
|
|
|
REGEX_CHAIN_HEAD(to);
|
|
|
|
to->chain = add;
|
|
|
|
THREAD_ATOMIC_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
|
|
|
onig_chain_reduce(regex_t* reg)
|
|
|
|
{
|
|
|
|
regex_t *head, *prev;
|
|
|
|
|
|
|
|
prev = reg;
|
|
|
|
head = prev->chain;
|
|
|
|
if (IS_NOT_NULL(head)) {
|
|
|
|
reg->state = ONIG_STATE_MODIFY;
|
|
|
|
while (IS_NOT_NULL(head->chain)) {
|
|
|
|
prev = head;
|
|
|
|
head = head->chain;
|
|
|
|
}
|
|
|
|
prev->chain = (regex_t* )NULL;
|
|
|
|
REGEX_TRANSFER(reg, head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG
|
|
|
|
static void print_compiled_byte_code_list P_((FILE* f, regex_t* reg));
|
|
|
|
#endif
|
|
|
|
#ifdef ONIG_DEBUG_PARSE_TREE
|
|
|
|
static void print_tree P_((FILE* f, Node* node));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_compile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
|
2009-08-30 12:00:31 +04:00
|
|
|
OnigErrorInfo* einfo, const char *sourcefile, int sourceline)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
#define COMPILE_INIT_SIZE 20
|
|
|
|
|
2011-01-31 06:44:57 +03:00
|
|
|
int r;
|
|
|
|
OnigDistance init_size;
|
2004-03-05 18:31:51 +03:00
|
|
|
Node* root;
|
2010-01-28 03:50:17 +03:00
|
|
|
ScanEnv scan_env = {0};
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
UnsetAddrList uslist;
|
|
|
|
#endif
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
if (IS_NOT_NULL(einfo)) einfo->par = (UChar* )NULL;
|
|
|
|
|
2009-08-30 12:00:31 +04:00
|
|
|
scan_env.sourcefile = sourcefile;
|
|
|
|
scan_env.sourceline = sourceline;
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->state = ONIG_STATE_COMPILING;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
#ifdef ONIG_DEBUG
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) print_enc_string(stderr, reg->enc, pattern, pattern_end);
|
2007-05-23 05:32:08 +04:00
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (reg->alloc == 0) {
|
|
|
|
init_size = (pattern_end - pattern) * 2;
|
|
|
|
if (init_size <= 0) init_size = COMPILE_INIT_SIZE;
|
|
|
|
r = BBUF_INIT(reg, init_size);
|
|
|
|
if (r != 0) goto end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reg->used = 0;
|
|
|
|
|
|
|
|
reg->num_mem = 0;
|
|
|
|
reg->num_repeat = 0;
|
|
|
|
reg->num_null_check = 0;
|
|
|
|
reg->repeat_range_alloc = 0;
|
|
|
|
reg->repeat_range = (OnigRepeatRange* )NULL;
|
2006-08-27 16:58:22 +04:00
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
|
|
|
reg->num_comb_exp_check = 0;
|
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
r = onig_parse_make_tree(&root, pattern, pattern_end, reg, &scan_env);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
|
2010-11-26 06:28:48 +03:00
|
|
|
#ifdef ONIG_DEBUG_PARSE_TREE
|
|
|
|
# if 0
|
|
|
|
fprintf(stderr, "ORIGINAL PARSE TREE:\n");
|
|
|
|
if (!onig_is_prelude()) {
|
|
|
|
print_tree(stderr, root);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef USE_NAMED_GROUP
|
|
|
|
/* mixed use named group and no-named group */
|
|
|
|
if (scan_env.num_named > 0 &&
|
|
|
|
IS_SYNTAX_BV(scan_env.syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
|
|
|
|
!ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_CAPTURE_GROUP)) {
|
|
|
|
if (scan_env.num_named != scan_env.num_mem)
|
|
|
|
r = disable_noname_group_capture(&root, reg, &scan_env);
|
|
|
|
else
|
|
|
|
r = numbered_ref_check(root);
|
|
|
|
|
|
|
|
if (r != 0) goto err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
if (scan_env.num_call > 0) {
|
|
|
|
r = unset_addr_list_init(&uslist, scan_env.num_call);
|
|
|
|
if (r != 0) goto err;
|
|
|
|
scan_env.unset_addr_list = &uslist;
|
|
|
|
r = setup_subexp_call(root, &scan_env);
|
|
|
|
if (r != 0) goto err_unset;
|
|
|
|
r = subexp_recursive_check_trav(root, &scan_env);
|
|
|
|
if (r < 0) goto err_unset;
|
|
|
|
r = subexp_inf_recursive_check_trav(root, &scan_env);
|
|
|
|
if (r != 0) goto err_unset;
|
|
|
|
|
|
|
|
reg->num_call = scan_env.num_call;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reg->num_call = 0;
|
|
|
|
#endif
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
r = setup_tree(root, reg, IN_ROOT, &scan_env);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r != 0) goto err_unset;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
#ifdef ONIG_DEBUG_PARSE_TREE
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) print_tree(stderr, root);
|
2007-05-23 05:32:08 +04:00
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
reg->capture_history = scan_env.capture_history;
|
|
|
|
reg->bt_mem_start = scan_env.bt_mem_start;
|
|
|
|
reg->bt_mem_start |= reg->capture_history;
|
|
|
|
if (IS_FIND_CONDITION(reg->options))
|
|
|
|
BIT_STATUS_ON_ALL(reg->bt_mem_end);
|
|
|
|
else {
|
|
|
|
reg->bt_mem_end = scan_env.bt_mem_end;
|
|
|
|
reg->bt_mem_end |= reg->capture_history;
|
|
|
|
}
|
|
|
|
|
2006-08-27 16:58:22 +04:00
|
|
|
#ifdef USE_COMBINATION_EXPLOSION_CHECK
|
|
|
|
if (scan_env.backrefed_mem == 0
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
|| scan_env.num_call == 0
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
setup_comb_exp_check(root, 0, &scan_env);
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
if (scan_env.has_recursion != 0) {
|
|
|
|
scan_env.num_comb_exp_check = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (scan_env.comb_exp_max_regnum > 0) {
|
|
|
|
int i;
|
|
|
|
for (i = 1; i <= scan_env.comb_exp_max_regnum; i++) {
|
|
|
|
if (BIT_STATUS_AT(scan_env.backrefed_mem, i) != 0) {
|
|
|
|
scan_env.num_comb_exp_check = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reg->num_comb_exp_check = scan_env.num_comb_exp_check;
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
clear_optimize_info(reg);
|
|
|
|
#ifndef ONIG_DONT_OPTIMIZE
|
|
|
|
r = set_optimize_info_from_tree(root, reg, &scan_env);
|
|
|
|
if (r != 0) goto err_unset;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (IS_NOT_NULL(scan_env.mem_nodes_dynamic)) {
|
|
|
|
xfree(scan_env.mem_nodes_dynamic);
|
|
|
|
scan_env.mem_nodes_dynamic = (Node** )NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = compile_tree(root, reg);
|
|
|
|
if (r == 0) {
|
|
|
|
r = add_opcode(reg, OP_END);
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
if (scan_env.num_call > 0) {
|
|
|
|
r = unset_addr_list_fix(&uslist, reg);
|
|
|
|
unset_addr_list_end(&uslist);
|
|
|
|
if (r) goto err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((reg->num_repeat != 0) || (reg->bt_mem_end != 0))
|
|
|
|
reg->stack_pop_level = STACK_POP_LEVEL_ALL;
|
|
|
|
else {
|
|
|
|
if (reg->bt_mem_start != 0)
|
|
|
|
reg->stack_pop_level = STACK_POP_LEVEL_MEM_START;
|
|
|
|
else
|
|
|
|
reg->stack_pop_level = STACK_POP_LEVEL_FREE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
else if (scan_env.num_call > 0) {
|
|
|
|
unset_addr_list_end(&uslist);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
onig_node_free(root);
|
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG_COMPILE
|
|
|
|
#ifdef USE_NAMED_GROUP
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) onig_print_names(stderr, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) print_compiled_byte_code_list(stderr, reg);
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
end:
|
|
|
|
reg->state = ONIG_STATE_NORMAL;
|
|
|
|
return r;
|
|
|
|
|
|
|
|
err_unset:
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
|
|
|
if (scan_env.num_call > 0) {
|
|
|
|
unset_addr_list_end(&uslist);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
err:
|
|
|
|
if (IS_NOT_NULL(scan_env.error)) {
|
|
|
|
if (IS_NOT_NULL(einfo)) {
|
2006-10-28 15:15:41 +04:00
|
|
|
einfo->enc = scan_env.enc;
|
2004-03-05 18:31:51 +03:00
|
|
|
einfo->par = scan_env.error;
|
|
|
|
einfo->par_end = scan_env.error_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_node_free(root);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (IS_NOT_NULL(scan_env.mem_nodes_dynamic))
|
|
|
|
xfree(scan_env.mem_nodes_dynamic);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-08-05 17:54:40 +04:00
|
|
|
#ifdef USE_RECOMPILE_API
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_recompile(regex_t* reg, const UChar* pattern, const UChar* pattern_end,
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax,
|
|
|
|
OnigErrorInfo* einfo)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
regex_t *new_reg;
|
|
|
|
|
|
|
|
r = onig_new(&new_reg, pattern, pattern_end, option, enc, syntax, einfo);
|
|
|
|
if (r) return r;
|
|
|
|
if (ONIG_STATE(reg) == ONIG_STATE_NORMAL) {
|
|
|
|
onig_transfer(reg, new_reg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
onig_chain_link_add(reg, new_reg);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-08-05 17:54:40 +04:00
|
|
|
#endif
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
static int onig_inited = 0;
|
|
|
|
|
|
|
|
extern int
|
2010-03-02 00:54:59 +03:00
|
|
|
onig_reg_init(regex_t* reg, OnigOptionType option,
|
|
|
|
OnigCaseFoldType case_fold_flag,
|
|
|
|
OnigEncoding enc, const OnigSyntaxType* syntax)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (! onig_inited)
|
|
|
|
onig_init();
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
if (IS_NULL(reg))
|
|
|
|
return ONIGERR_INVALID_ARGUMENT;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
if (ONIGENC_IS_UNDEF(enc))
|
2012-02-17 11:42:23 +04:00
|
|
|
return ONIGERR_DEFAULT_ENCODING_IS_NOT_SET;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2006-03-23 15:08:08 +03:00
|
|
|
if ((option & (ONIG_OPTION_DONT_CAPTURE_GROUP|ONIG_OPTION_CAPTURE_GROUP))
|
|
|
|
== (ONIG_OPTION_DONT_CAPTURE_GROUP|ONIG_OPTION_CAPTURE_GROUP)) {
|
|
|
|
return ONIGERR_INVALID_COMBINATION_OF_OPTIONS;
|
|
|
|
}
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
(reg)->state = ONIG_STATE_MODIFY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
if ((option & ONIG_OPTION_NEGATE_SINGLELINE) != 0) {
|
|
|
|
option |= syntax->options;
|
|
|
|
option &= ~ONIG_OPTION_SINGLELINE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
option |= syntax->options;
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
(reg)->enc = enc;
|
|
|
|
(reg)->options = option;
|
|
|
|
(reg)->syntax = syntax;
|
|
|
|
(reg)->optimize = 0;
|
|
|
|
(reg)->exact = (UChar* )NULL;
|
|
|
|
(reg)->int_map = (int* )NULL;
|
|
|
|
(reg)->int_map_backward = (int* )NULL;
|
|
|
|
(reg)->chain = (regex_t* )NULL;
|
|
|
|
|
|
|
|
(reg)->p = (UChar* )NULL;
|
|
|
|
(reg)->alloc = 0;
|
|
|
|
(reg)->used = 0;
|
|
|
|
(reg)->name_table = (void* )NULL;
|
|
|
|
|
|
|
|
(reg)->case_fold_flag = case_fold_flag;
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
extern int
|
|
|
|
onig_new_without_alloc(regex_t* reg, const UChar* pattern,
|
|
|
|
const UChar* pattern_end, OnigOptionType option, OnigEncoding enc,
|
|
|
|
OnigSyntaxType* syntax, OnigErrorInfo* einfo)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = onig_reg_init(reg, option, ONIGENC_CASE_FOLD_DEFAULT, enc, syntax);
|
|
|
|
if (r) return r;
|
|
|
|
|
|
|
|
r = onig_compile(reg, pattern, pattern_end, einfo, NULL, 0);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c: imported Oni Guruma 3.7.0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-02-23 15:47:23 +03:00
|
|
|
onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
|
2008-07-01 12:21:44 +04:00
|
|
|
OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax,
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigErrorInfo* einfo)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
*reg = (regex_t* )xmalloc(sizeof(regex_t));
|
|
|
|
if (IS_NULL(*reg)) return ONIGERR_MEMORY;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
r = onig_reg_init(*reg, option, ONIGENC_CASE_FOLD_DEFAULT, enc, syntax);
|
|
|
|
if (r) goto err;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2009-08-30 12:00:31 +04:00
|
|
|
r = onig_compile(*reg, pattern, pattern_end, einfo, NULL, 0);
|
2004-03-05 18:31:51 +03:00
|
|
|
if (r) {
|
2010-03-02 00:54:59 +03:00
|
|
|
err:
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_free(*reg);
|
|
|
|
*reg = NULL;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-03-02 00:54:59 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
2007-05-23 05:32:08 +04:00
|
|
|
onig_init(void)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
if (onig_inited != 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-05-23 05:32:08 +04:00
|
|
|
THREAD_SYSTEM_INIT;
|
2004-03-05 18:31:51 +03:00
|
|
|
THREAD_ATOMIC_START;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
onig_inited = 1;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
onigenc_init();
|
2007-07-23 13:39:30 +04:00
|
|
|
/* onigenc_set_default_caseconv_table((UChar* )0); */
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG_STATISTICS
|
|
|
|
onig_statistics_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
THREAD_ATOMIC_END;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
extern int
|
2007-03-19 06:58:57 +03:00
|
|
|
onig_end(void)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
THREAD_ATOMIC_START;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef ONIG_DEBUG_STATISTICS
|
2010-11-26 03:24:28 +03:00
|
|
|
if (!onig_is_prelude()) onig_print_statistics(stderr);
|
2004-03-05 18:31:51 +03:00
|
|
|
#endif
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
#ifdef USE_SHARED_CCLASS_TABLE
|
|
|
|
onig_free_shared_cclass_table();
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
#ifdef USE_PARSE_TREE_NODE_RECYCLE
|
2006-08-05 17:54:40 +04:00
|
|
|
onig_free_node_list();
|
|
|
|
#endif
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
onig_inited = 0;
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
|
|
|
THREAD_ATOMIC_END;
|
2007-05-23 05:32:08 +04:00
|
|
|
THREAD_SYSTEM_END;
|
2004-03-05 18:31:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
extern int
|
|
|
|
onig_is_in_code_range(const UChar* p, OnigCodePoint code)
|
|
|
|
{
|
|
|
|
OnigCodePoint n, *data;
|
|
|
|
OnigCodePoint low, high, x;
|
|
|
|
|
|
|
|
GET_CODE_POINT(n, p);
|
|
|
|
data = (OnigCodePoint* )p;
|
|
|
|
data++;
|
|
|
|
|
|
|
|
for (low = 0, high = n; low < high; ) {
|
|
|
|
x = (low + high) >> 1;
|
|
|
|
if (code > data[x * 2 + 1])
|
|
|
|
low = x + 1;
|
|
|
|
else
|
|
|
|
high = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((low < n && code >= data[low * 2]) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
2008-01-03 18:55:04 +03:00
|
|
|
onig_is_code_in_cc_len(int elen, OnigCodePoint code, CClassNode* cc)
|
2007-07-23 13:39:30 +04:00
|
|
|
{
|
|
|
|
int found;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
if (elen > 1 || (code >= SINGLE_BYTE_SIZE)) {
|
2007-07-23 13:39:30 +04:00
|
|
|
if (IS_NULL(cc->mbuf)) {
|
|
|
|
found = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
found = (onig_is_in_code_range(cc->mbuf->p, code) != 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
found = (BITSET_AT(cc->bs, code) == 0 ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_NCCLASS_NOT(cc))
|
|
|
|
return !found;
|
|
|
|
else
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int
|
|
|
|
onig_is_code_in_cc(OnigEncoding enc, OnigCodePoint code, CClassNode* cc)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (ONIGENC_MBC_MINLEN(enc) > 1) {
|
|
|
|
len = 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = ONIGENC_CODE_TO_MBCLEN(enc, code);
|
|
|
|
}
|
|
|
|
return onig_is_code_in_cc_len(len, code, cc);
|
|
|
|
}
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
#ifdef ONIG_DEBUG
|
|
|
|
|
2006-08-27 16:58:22 +04:00
|
|
|
/* arguments type */
|
|
|
|
#define ARG_SPECIAL -1
|
|
|
|
#define ARG_NON 0
|
|
|
|
#define ARG_RELADDR 1
|
|
|
|
#define ARG_ABSADDR 2
|
|
|
|
#define ARG_LENGTH 3
|
|
|
|
#define ARG_MEMNUM 4
|
|
|
|
#define ARG_OPTION 5
|
|
|
|
#define ARG_STATE_CHECK 6
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigOpInfoType OnigOpInfo[] = {
|
|
|
|
{ OP_FINISH, "finish", ARG_NON },
|
|
|
|
{ OP_END, "end", ARG_NON },
|
|
|
|
{ OP_EXACT1, "exact1", ARG_SPECIAL },
|
|
|
|
{ OP_EXACT2, "exact2", ARG_SPECIAL },
|
|
|
|
{ OP_EXACT3, "exact3", ARG_SPECIAL },
|
|
|
|
{ OP_EXACT4, "exact4", ARG_SPECIAL },
|
|
|
|
{ OP_EXACT5, "exact5", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTN, "exactn", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTMB2N1, "exactmb2-n1", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTMB2N2, "exactmb2-n2", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTMB2N3, "exactmb2-n3", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTMB2N, "exactmb2-n", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTMB3N, "exactmb3n" , ARG_SPECIAL },
|
|
|
|
{ OP_EXACTMBN, "exactmbn", ARG_SPECIAL },
|
|
|
|
{ OP_EXACT1_IC, "exact1-ic", ARG_SPECIAL },
|
|
|
|
{ OP_EXACTN_IC, "exactn-ic", ARG_SPECIAL },
|
|
|
|
{ OP_CCLASS, "cclass", ARG_SPECIAL },
|
|
|
|
{ OP_CCLASS_MB, "cclass-mb", ARG_SPECIAL },
|
|
|
|
{ OP_CCLASS_MIX, "cclass-mix", ARG_SPECIAL },
|
|
|
|
{ OP_CCLASS_NOT, "cclass-not", ARG_SPECIAL },
|
|
|
|
{ OP_CCLASS_MB_NOT, "cclass-mb-not", ARG_SPECIAL },
|
|
|
|
{ OP_CCLASS_MIX_NOT, "cclass-mix-not", ARG_SPECIAL },
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
{ OP_CCLASS_NODE, "cclass-node", ARG_SPECIAL },
|
2004-03-05 18:31:51 +03:00
|
|
|
{ OP_ANYCHAR, "anychar", ARG_NON },
|
|
|
|
{ OP_ANYCHAR_ML, "anychar-ml", ARG_NON },
|
|
|
|
{ OP_ANYCHAR_STAR, "anychar*", ARG_NON },
|
|
|
|
{ OP_ANYCHAR_ML_STAR, "anychar-ml*", ARG_NON },
|
|
|
|
{ OP_ANYCHAR_STAR_PEEK_NEXT, "anychar*-peek-next", ARG_SPECIAL },
|
|
|
|
{ OP_ANYCHAR_ML_STAR_PEEK_NEXT, "anychar-ml*-peek-next", ARG_SPECIAL },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_WORD, "word", ARG_NON },
|
|
|
|
{ OP_NOT_WORD, "not-word", ARG_NON },
|
|
|
|
{ OP_WORD_BOUND, "word-bound", ARG_NON },
|
|
|
|
{ OP_NOT_WORD_BOUND, "not-word-bound", ARG_NON },
|
|
|
|
{ OP_WORD_BEGIN, "word-begin", ARG_NON },
|
|
|
|
{ OP_WORD_END, "word-end", ARG_NON },
|
2012-02-17 11:42:23 +04:00
|
|
|
{ OP_ASCII_WORD, "ascii-word", ARG_NON },
|
|
|
|
{ OP_NOT_ASCII_WORD, "not-ascii-word", ARG_NON },
|
|
|
|
{ OP_ASCII_WORD_BOUND, "ascii-word-bound", ARG_NON },
|
|
|
|
{ OP_NOT_ASCII_WORD_BOUND,"not-ascii-word-bound", ARG_NON },
|
|
|
|
{ OP_ASCII_WORD_BEGIN, "ascii-word-begin", ARG_NON },
|
|
|
|
{ OP_ASCII_WORD_END, "ascii-word-end", ARG_NON },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_BEGIN_BUF, "begin-buf", ARG_NON },
|
|
|
|
{ OP_END_BUF, "end-buf", ARG_NON },
|
|
|
|
{ OP_BEGIN_LINE, "begin-line", ARG_NON },
|
|
|
|
{ OP_END_LINE, "end-line", ARG_NON },
|
|
|
|
{ OP_SEMI_END_BUF, "semi-end-buf", ARG_NON },
|
|
|
|
{ OP_BEGIN_POSITION, "begin-position", ARG_NON },
|
2012-02-17 11:42:23 +04:00
|
|
|
{ OP_BEGIN_POS_OR_LINE, "begin-pos-or-line", ARG_NON },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_BACKREF1, "backref1", ARG_NON },
|
|
|
|
{ OP_BACKREF2, "backref2", ARG_NON },
|
|
|
|
{ OP_BACKREFN, "backrefn", ARG_MEMNUM },
|
|
|
|
{ OP_BACKREFN_IC, "backrefn-ic", ARG_SPECIAL },
|
|
|
|
{ OP_BACKREF_MULTI, "backref_multi", ARG_SPECIAL },
|
|
|
|
{ OP_BACKREF_MULTI_IC, "backref_multi-ic", ARG_SPECIAL },
|
2012-02-17 11:42:23 +04:00
|
|
|
{ OP_BACKREF_WITH_LEVEL, "backref_at_level", ARG_SPECIAL },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_MEMORY_START_PUSH, "mem-start-push", ARG_MEMNUM },
|
|
|
|
{ OP_MEMORY_START, "mem-start", ARG_MEMNUM },
|
|
|
|
{ OP_MEMORY_END_PUSH, "mem-end-push", ARG_MEMNUM },
|
|
|
|
{ OP_MEMORY_END_PUSH_REC, "mem-end-push-rec", ARG_MEMNUM },
|
|
|
|
{ OP_MEMORY_END, "mem-end", ARG_MEMNUM },
|
|
|
|
{ OP_MEMORY_END_REC, "mem-end-rec", ARG_MEMNUM },
|
|
|
|
{ OP_SET_OPTION_PUSH, "set-option-push", ARG_OPTION },
|
|
|
|
{ OP_SET_OPTION, "set-option", ARG_OPTION },
|
2012-02-17 11:42:23 +04:00
|
|
|
{ OP_KEEP, "keep", ARG_NON },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_FAIL, "fail", ARG_NON },
|
|
|
|
{ OP_JUMP, "jump", ARG_RELADDR },
|
|
|
|
{ OP_PUSH, "push", ARG_RELADDR },
|
|
|
|
{ OP_POP, "pop", ARG_NON },
|
|
|
|
{ OP_PUSH_OR_JUMP_EXACT1, "push-or-jump-e1", ARG_SPECIAL },
|
|
|
|
{ OP_PUSH_IF_PEEK_NEXT, "push-if-peek-next", ARG_SPECIAL },
|
|
|
|
{ OP_REPEAT, "repeat", ARG_SPECIAL },
|
|
|
|
{ OP_REPEAT_NG, "repeat-ng", ARG_SPECIAL },
|
|
|
|
{ OP_REPEAT_INC, "repeat-inc", ARG_MEMNUM },
|
|
|
|
{ OP_REPEAT_INC_NG, "repeat-inc-ng", ARG_MEMNUM },
|
|
|
|
{ OP_REPEAT_INC_SG, "repeat-inc-sg", ARG_MEMNUM },
|
|
|
|
{ OP_REPEAT_INC_NG_SG, "repeat-inc-ng-sg", ARG_MEMNUM },
|
|
|
|
{ OP_NULL_CHECK_START, "null-check-start", ARG_MEMNUM },
|
|
|
|
{ OP_NULL_CHECK_END, "null-check-end", ARG_MEMNUM },
|
|
|
|
{ OP_NULL_CHECK_END_MEMST,"null-check-end-memst", ARG_MEMNUM },
|
|
|
|
{ OP_NULL_CHECK_END_MEMST_PUSH,"null-check-end-memst-push", ARG_MEMNUM },
|
|
|
|
{ OP_PUSH_POS, "push-pos", ARG_NON },
|
|
|
|
{ OP_POP_POS, "pop-pos", ARG_NON },
|
|
|
|
{ OP_PUSH_POS_NOT, "push-pos-not", ARG_RELADDR },
|
|
|
|
{ OP_FAIL_POS, "fail-pos", ARG_NON },
|
|
|
|
{ OP_PUSH_STOP_BT, "push-stop-bt", ARG_NON },
|
|
|
|
{ OP_POP_STOP_BT, "pop-stop-bt", ARG_NON },
|
|
|
|
{ OP_LOOK_BEHIND, "look-behind", ARG_SPECIAL },
|
2004-03-05 18:31:51 +03:00
|
|
|
{ OP_PUSH_LOOK_BEHIND_NOT, "push-look-behind-not", ARG_SPECIAL },
|
|
|
|
{ OP_FAIL_LOOK_BEHIND_NOT, "fail-look-behind-not", ARG_NON },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_CALL, "call", ARG_ABSADDR },
|
|
|
|
{ OP_RETURN, "return", ARG_NON },
|
2012-02-17 11:42:23 +04:00
|
|
|
{ OP_CONDITION, "condition", ARG_SPECIAL },
|
2006-08-27 16:58:22 +04:00
|
|
|
{ OP_STATE_CHECK_PUSH, "state-check-push", ARG_SPECIAL },
|
|
|
|
{ OP_STATE_CHECK_PUSH_OR_JUMP, "state-check-push-or-jump", ARG_SPECIAL },
|
|
|
|
{ OP_STATE_CHECK, "state-check", ARG_STATE_CHECK },
|
|
|
|
{ OP_STATE_CHECK_ANYCHAR_STAR, "state-check-anychar*", ARG_STATE_CHECK },
|
|
|
|
{ OP_STATE_CHECK_ANYCHAR_ML_STAR,
|
|
|
|
"state-check-anychar-ml*", ARG_STATE_CHECK },
|
2004-03-05 18:31:51 +03:00
|
|
|
{ -1, "", ARG_NON }
|
|
|
|
};
|
|
|
|
|
2010-11-17 09:21:11 +03:00
|
|
|
static const char*
|
2004-03-05 18:31:51 +03:00
|
|
|
op2name(int opcode)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; OnigOpInfo[i].opcode >= 0; i++) {
|
|
|
|
if (opcode == OnigOpInfo[i].opcode)
|
|
|
|
return OnigOpInfo[i].name;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
op2arg_type(int opcode)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; OnigOpInfo[i].opcode >= 0; i++) {
|
|
|
|
if (opcode == OnigOpInfo[i].opcode)
|
|
|
|
return OnigOpInfo[i].arg_type;
|
|
|
|
}
|
|
|
|
return ARG_SPECIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Indent(FILE* f, int indent)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < indent; i++) putc(' ', f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
p_string(FILE* f, int len, UChar* s)
|
|
|
|
{
|
|
|
|
fputs(":", f);
|
|
|
|
while (len-- > 0) { fputc(*s++, f); }
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
p_len_string(FILE* f, LengthType len, int mb_len, UChar* s)
|
|
|
|
{
|
|
|
|
int x = len * mb_len;
|
|
|
|
|
|
|
|
fprintf(f, ":%d:", len);
|
|
|
|
while (x-- > 0) { fputc(*s++, f); }
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void
|
2009-12-21 04:11:15 +03:00
|
|
|
onig_print_compiled_byte_code(FILE* f, UChar* bp, UChar* bpend, UChar** nextp,
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
OnigEncoding enc)
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int i, n, arg_type;
|
|
|
|
RelAddrType addr;
|
|
|
|
LengthType len;
|
|
|
|
MemNumType mem;
|
2006-08-27 16:58:22 +04:00
|
|
|
StateCheckNumType scn;
|
2004-03-05 18:31:51 +03:00
|
|
|
OnigCodePoint code;
|
|
|
|
UChar *q;
|
|
|
|
|
|
|
|
fprintf(f, "[%s", op2name(*bp));
|
|
|
|
arg_type = op2arg_type(*bp);
|
|
|
|
if (arg_type != ARG_SPECIAL) {
|
|
|
|
bp++;
|
|
|
|
switch (arg_type) {
|
|
|
|
case ARG_NON:
|
|
|
|
break;
|
|
|
|
case ARG_RELADDR:
|
2004-11-28 06:06:39 +03:00
|
|
|
GET_RELADDR_INC(addr, bp);
|
2004-03-05 18:31:51 +03:00
|
|
|
fprintf(f, ":(%d)", addr);
|
|
|
|
break;
|
|
|
|
case ARG_ABSADDR:
|
|
|
|
GET_ABSADDR_INC(addr, bp);
|
|
|
|
fprintf(f, ":(%d)", addr);
|
|
|
|
break;
|
|
|
|
case ARG_LENGTH:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
fprintf(f, ":%d", len);
|
|
|
|
break;
|
|
|
|
case ARG_MEMNUM:
|
|
|
|
mem = *((MemNumType* )bp);
|
|
|
|
bp += SIZE_MEMNUM;
|
|
|
|
fprintf(f, ":%d", mem);
|
|
|
|
break;
|
|
|
|
case ARG_OPTION:
|
|
|
|
{
|
|
|
|
OnigOptionType option = *((OnigOptionType* )bp);
|
|
|
|
bp += SIZE_OPTION;
|
|
|
|
fprintf(f, ":%d", option);
|
|
|
|
}
|
|
|
|
break;
|
2006-08-27 16:58:22 +04:00
|
|
|
|
|
|
|
case ARG_STATE_CHECK:
|
|
|
|
scn = *((StateCheckNumType* )bp);
|
|
|
|
bp += SIZE_STATE_CHECK_NUM;
|
|
|
|
fprintf(f, ":%d", scn);
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (*bp++) {
|
|
|
|
case OP_EXACT1:
|
|
|
|
case OP_ANYCHAR_STAR_PEEK_NEXT:
|
|
|
|
case OP_ANYCHAR_ML_STAR_PEEK_NEXT:
|
|
|
|
p_string(f, 1, bp++); break;
|
|
|
|
case OP_EXACT2:
|
|
|
|
p_string(f, 2, bp); bp += 2; break;
|
|
|
|
case OP_EXACT3:
|
|
|
|
p_string(f, 3, bp); bp += 3; break;
|
|
|
|
case OP_EXACT4:
|
|
|
|
p_string(f, 4, bp); bp += 4; break;
|
|
|
|
case OP_EXACT5:
|
|
|
|
p_string(f, 5, bp); bp += 5; break;
|
|
|
|
case OP_EXACTN:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
p_len_string(f, len, 1, bp);
|
|
|
|
bp += len;
|
|
|
|
break;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case OP_EXACTMB2N1:
|
|
|
|
p_string(f, 2, bp); bp += 2; break;
|
|
|
|
case OP_EXACTMB2N2:
|
|
|
|
p_string(f, 4, bp); bp += 4; break;
|
|
|
|
case OP_EXACTMB2N3:
|
|
|
|
p_string(f, 6, bp); bp += 6; break;
|
|
|
|
case OP_EXACTMB2N:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
p_len_string(f, len, 2, bp);
|
|
|
|
bp += len * 2;
|
|
|
|
break;
|
|
|
|
case OP_EXACTMB3N:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
p_len_string(f, len, 3, bp);
|
|
|
|
bp += len * 3;
|
|
|
|
break;
|
|
|
|
case OP_EXACTMBN:
|
|
|
|
{
|
|
|
|
int mb_len;
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
GET_LENGTH_INC(mb_len, bp);
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
fprintf(f, ":%d:%d:", mb_len, len);
|
|
|
|
n = len * mb_len;
|
|
|
|
while (n-- > 0) { fputc(*bp++, f); }
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_EXACT1_IC:
|
2009-12-21 04:11:15 +03:00
|
|
|
len = enclen(enc, bp, bpend);
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
p_string(f, len, bp);
|
|
|
|
bp += len;
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
case OP_EXACTN_IC:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
p_len_string(f, len, 1, bp);
|
|
|
|
bp += len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CCLASS:
|
|
|
|
n = bitset_on_num((BitSetRef )bp);
|
|
|
|
bp += SIZE_BITSET;
|
|
|
|
fprintf(f, ":%d", n);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CCLASS_NOT:
|
|
|
|
n = bitset_on_num((BitSetRef )bp);
|
|
|
|
bp += SIZE_BITSET;
|
|
|
|
fprintf(f, ":%d", n);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CCLASS_MB:
|
|
|
|
case OP_CCLASS_MB_NOT:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
q = bp;
|
|
|
|
#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
|
|
|
|
ALIGNMENT_RIGHT(q);
|
|
|
|
#endif
|
|
|
|
GET_CODE_POINT(code, q);
|
|
|
|
bp += len;
|
|
|
|
fprintf(f, ":%d:%d", (int )code, len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CCLASS_MIX:
|
|
|
|
case OP_CCLASS_MIX_NOT:
|
|
|
|
n = bitset_on_num((BitSetRef )bp);
|
|
|
|
bp += SIZE_BITSET;
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
q = bp;
|
|
|
|
#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
|
|
|
|
ALIGNMENT_RIGHT(q);
|
|
|
|
#endif
|
|
|
|
GET_CODE_POINT(code, q);
|
|
|
|
bp += len;
|
|
|
|
fprintf(f, ":%d:%d:%d", n, (int )code, len);
|
|
|
|
break;
|
|
|
|
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
case OP_CCLASS_NODE:
|
|
|
|
{
|
|
|
|
CClassNode *cc;
|
|
|
|
|
|
|
|
GET_POINTER_INC(cc, bp);
|
|
|
|
n = bitset_on_num(cc->bs);
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, ":%"PRIuPTR":%d", (uintptr_t)cc, n);
|
* ascii.c, euc_jp.c, hash.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, st.c, st.h, utf8.c: imported Oni Guruma 3.5.4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-01-28 18:21:48 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case OP_BACKREFN_IC:
|
|
|
|
mem = *((MemNumType* )bp);
|
|
|
|
bp += SIZE_MEMNUM;
|
|
|
|
fprintf(f, ":%d", mem);
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case OP_BACKREF_MULTI_IC:
|
* ascii.c, euc_jp.c, oniggnu.h, oniguruma.h, regcomp.c, regenc.c, regenc.h, regerror.c, regexec.c, reggnu.c, regint.h, regparse.c, regparse.h, sjis.c, utf8.c:
imported Oni Guruma 3.4.0.
* parse.y, re.c: Now mbclen() takes unsigned char as its argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-04 17:43:08 +03:00
|
|
|
case OP_BACKREF_MULTI:
|
2004-03-05 18:31:51 +03:00
|
|
|
fputs(" ", f);
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GET_MEMNUM_INC(mem, bp);
|
|
|
|
if (i > 0) fputs(", ", f);
|
|
|
|
fprintf(f, "%d", mem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-01-03 18:55:04 +03:00
|
|
|
case OP_BACKREF_WITH_LEVEL:
|
2006-08-05 17:54:40 +04:00
|
|
|
{
|
|
|
|
OnigOptionType option;
|
|
|
|
LengthType level;
|
|
|
|
|
|
|
|
GET_OPTION_INC(option, bp);
|
|
|
|
fprintf(f, ":%d", option);
|
|
|
|
GET_LENGTH_INC(level, bp);
|
|
|
|
fprintf(f, ":%d", level);
|
|
|
|
|
|
|
|
fputs(" ", f);
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GET_MEMNUM_INC(mem, bp);
|
|
|
|
if (i > 0) fputs(", ", f);
|
|
|
|
fprintf(f, "%d", mem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
case OP_REPEAT:
|
|
|
|
case OP_REPEAT_NG:
|
|
|
|
{
|
|
|
|
mem = *((MemNumType* )bp);
|
|
|
|
bp += SIZE_MEMNUM;
|
|
|
|
addr = *((RelAddrType* )bp);
|
|
|
|
bp += SIZE_RELADDR;
|
|
|
|
fprintf(f, ":%d:%d", mem, addr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_PUSH_OR_JUMP_EXACT1:
|
|
|
|
case OP_PUSH_IF_PEEK_NEXT:
|
|
|
|
addr = *((RelAddrType* )bp);
|
|
|
|
bp += SIZE_RELADDR;
|
|
|
|
fprintf(f, ":(%d)", addr);
|
|
|
|
p_string(f, 1, bp);
|
|
|
|
bp += 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_LOOK_BEHIND:
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
fprintf(f, ":%d", len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_PUSH_LOOK_BEHIND_NOT:
|
|
|
|
GET_RELADDR_INC(addr, bp);
|
|
|
|
GET_LENGTH_INC(len, bp);
|
|
|
|
fprintf(f, ":%d:(%d)", len, addr);
|
2006-08-27 16:58:22 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_STATE_CHECK_PUSH:
|
|
|
|
case OP_STATE_CHECK_PUSH_OR_JUMP:
|
|
|
|
scn = *((StateCheckNumType* )bp);
|
|
|
|
bp += SIZE_STATE_CHECK_NUM;
|
|
|
|
addr = *((RelAddrType* )bp);
|
|
|
|
bp += SIZE_RELADDR;
|
|
|
|
fprintf(f, ":%d:(%d)", scn, addr);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
case OP_CONDITION:
|
|
|
|
GET_MEMNUM_INC(mem, bp);
|
|
|
|
GET_RELADDR_INC(addr, bp);
|
|
|
|
fprintf(f, ":%d:(%d)", mem, addr);
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "onig_print_compiled_byte_code: undefined code %d\n",
|
|
|
|
*--bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputs("]", f);
|
|
|
|
if (nextp) *nextp = bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_compiled_byte_code_list(FILE* f, regex_t* reg)
|
|
|
|
{
|
|
|
|
int ncode;
|
|
|
|
UChar* bp = reg->p;
|
|
|
|
UChar* end = reg->p + reg->used;
|
|
|
|
|
2012-02-17 11:42:23 +04:00
|
|
|
fprintf(f, "code length: %d", reg->used);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2010-11-26 03:24:28 +03:00
|
|
|
ncode = -1;
|
2004-03-05 18:31:51 +03:00
|
|
|
while (bp < end) {
|
|
|
|
ncode++;
|
2012-02-17 11:42:23 +04:00
|
|
|
if (ncode % 5 == 0)
|
|
|
|
fprintf(f, "\n%ld:", bp - reg->p);
|
|
|
|
else
|
|
|
|
fprintf(f, " %ld:", bp - reg->p);
|
2009-12-21 04:11:15 +03:00
|
|
|
onig_print_compiled_byte_code(f, bp, end, &bp, reg->enc);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_indent_tree(FILE* f, Node* node, int indent)
|
|
|
|
{
|
2010-11-26 03:24:28 +03:00
|
|
|
int i, type, container_p = 0;
|
2004-03-05 18:31:51 +03:00
|
|
|
int add = 3;
|
|
|
|
UChar* p;
|
|
|
|
|
|
|
|
Indent(f, indent);
|
|
|
|
if (IS_NULL(node)) {
|
|
|
|
fprintf(f, "ERROR: null node!!!\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
type = NTYPE(node);
|
|
|
|
switch (type) {
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_LIST:
|
|
|
|
case NT_ALT:
|
|
|
|
if (NTYPE(node) == NT_LIST)
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<list:%"PRIxPTR">\n", (intptr_t)node);
|
2004-03-05 18:31:51 +03:00
|
|
|
else
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<alt:%"PRIxPTR">\n", (intptr_t)node);
|
2004-03-05 18:31:51 +03:00
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
print_indent_tree(f, NCAR(node), indent + add);
|
|
|
|
while (IS_NOT_NULL(node = NCDR(node))) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (NTYPE(node) != type) {
|
|
|
|
fprintf(f, "ERROR: list/alt right is not a cons. %d\n", NTYPE(node));
|
|
|
|
exit(0);
|
|
|
|
}
|
2007-07-23 13:39:30 +04:00
|
|
|
print_indent_tree(f, NCAR(node), indent + add);
|
2004-03-05 18:31:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_STR:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<string%s:%"PRIxPTR">",
|
|
|
|
(NSTRING_IS_RAW(node) ? "-raw" : ""), (intptr_t)node);
|
2007-07-23 13:39:30 +04:00
|
|
|
for (p = NSTR(node)->s; p < NSTR(node)->end; p++) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (*p >= 0x20 && *p < 0x7f)
|
|
|
|
fputc(*p, f);
|
|
|
|
else {
|
|
|
|
fprintf(f, " 0x%02x", *p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CCLASS:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<cclass:%"PRIxPTR">", (intptr_t)node);
|
2008-01-03 18:55:04 +03:00
|
|
|
if (IS_NCCLASS_NOT(NCCLASS(node))) fputs(" not", f);
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NCCLASS(node)->mbuf) {
|
|
|
|
BBuf* bbuf = NCCLASS(node)->mbuf;
|
2012-02-17 11:42:23 +04:00
|
|
|
for (i = 0; i < (int )bbuf->used; i++) {
|
2004-03-05 18:31:51 +03:00
|
|
|
if (i > 0) fprintf(f, ",");
|
|
|
|
fprintf(f, "%0x", bbuf->p[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CTYPE:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<ctype:%"PRIxPTR"> ", (intptr_t)node);
|
2007-07-23 13:39:30 +04:00
|
|
|
switch (NCTYPE(node)->ctype) {
|
2007-05-23 05:32:08 +04:00
|
|
|
case ONIGENC_CTYPE_WORD:
|
2007-07-23 13:39:30 +04:00
|
|
|
if (NCTYPE(node)->not != 0)
|
2007-05-23 05:32:08 +04:00
|
|
|
fputs("not word", f);
|
|
|
|
else
|
|
|
|
fputs("word", f);
|
|
|
|
break;
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
default:
|
|
|
|
fprintf(f, "ERROR: undefined ctype.\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CANY:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<anychar:%"PRIxPTR">", (intptr_t)node);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ANCHOR:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<anchor:%"PRIxPTR"> ", (intptr_t)node);
|
2007-07-23 13:39:30 +04:00
|
|
|
switch (NANCHOR(node)->type) {
|
2004-03-05 18:31:51 +03:00
|
|
|
case ANCHOR_BEGIN_BUF: fputs("begin buf", f); break;
|
|
|
|
case ANCHOR_END_BUF: fputs("end buf", f); break;
|
|
|
|
case ANCHOR_BEGIN_LINE: fputs("begin line", f); break;
|
|
|
|
case ANCHOR_END_LINE: fputs("end line", f); break;
|
|
|
|
case ANCHOR_SEMI_END_BUF: fputs("semi end buf", f); break;
|
|
|
|
case ANCHOR_BEGIN_POSITION: fputs("begin position", f); break;
|
2012-02-17 11:42:23 +04:00
|
|
|
case ANCHOR_ANYCHAR_STAR: fputs("begin position/line", f); break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
case ANCHOR_WORD_BOUND: fputs("word bound", f); break;
|
|
|
|
case ANCHOR_NOT_WORD_BOUND: fputs("not word bound", f); break;
|
|
|
|
#ifdef USE_WORD_BEGIN_END
|
|
|
|
case ANCHOR_WORD_BEGIN: fputs("word begin", f); break;
|
|
|
|
case ANCHOR_WORD_END: fputs("word end", f); break;
|
|
|
|
#endif
|
2010-11-26 03:24:28 +03:00
|
|
|
case ANCHOR_PREC_READ: fputs("prec read", f); container_p = TRUE; break;
|
|
|
|
case ANCHOR_PREC_READ_NOT: fputs("prec read not", f); container_p = TRUE; break;
|
|
|
|
case ANCHOR_LOOK_BEHIND: fputs("look_behind", f); container_p = TRUE; break;
|
|
|
|
case ANCHOR_LOOK_BEHIND_NOT: fputs("look_behind_not",f); container_p = TRUE; break;
|
2012-02-17 11:42:23 +04:00
|
|
|
case ANCHOR_KEEP: fputs("keep",f); break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(f, "ERROR: undefined anchor type.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_BREF:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
|
|
|
int* p;
|
2007-07-23 13:39:30 +04:00
|
|
|
BRefNode* br = NBREF(node);
|
2004-03-05 18:31:51 +03:00
|
|
|
p = BACKREFS_P(br);
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<backref:%"PRIxPTR">", (intptr_t)node);
|
2004-03-05 18:31:51 +03:00
|
|
|
for (i = 0; i < br->back_num; i++) {
|
|
|
|
if (i > 0) fputs(", ", f);
|
|
|
|
fprintf(f, "%d", p[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef USE_SUBEXP_CALL
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_CALL:
|
2004-03-05 18:31:51 +03:00
|
|
|
{
|
2007-07-23 13:39:30 +04:00
|
|
|
CallNode* cn = NCALL(node);
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<call:%"PRIxPTR">", (intptr_t)node);
|
2004-03-05 18:31:51 +03:00
|
|
|
p_string(f, cn->name_end - cn->name, cn->name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_QTFR:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<quantifier:%"PRIxPTR">{%d,%d}%s\n", (intptr_t)node,
|
2007-07-23 13:39:30 +04:00
|
|
|
NQTFR(node)->lower, NQTFR(node)->upper,
|
|
|
|
(NQTFR(node)->greedy ? "" : "?"));
|
|
|
|
print_indent_tree(f, NQTFR(node)->target, indent + add);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
case NT_ENCLOSE:
|
2010-11-17 09:21:11 +03:00
|
|
|
fprintf(f, "<enclose:%"PRIxPTR"> ", (intptr_t)node);
|
2007-07-23 13:39:30 +04:00
|
|
|
switch (NENCLOSE(node)->type) {
|
|
|
|
case ENCLOSE_OPTION:
|
|
|
|
fprintf(f, "option:%d\n", NENCLOSE(node)->option);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_MEMORY:
|
|
|
|
fprintf(f, "memory:%d", NENCLOSE(node)->regnum);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
2007-07-23 13:39:30 +04:00
|
|
|
case ENCLOSE_STOP_BACKTRACK:
|
2004-03-05 18:31:51 +03:00
|
|
|
fprintf(f, "stop-bt");
|
|
|
|
break;
|
2012-02-17 11:42:23 +04:00
|
|
|
case ENCLOSE_CONDITION:
|
|
|
|
fprintf(f, "condition:%d", NENCLOSE(node)->regnum);
|
|
|
|
break;
|
2004-03-05 18:31:51 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf(f, "\n");
|
2007-07-23 13:39:30 +04:00
|
|
|
print_indent_tree(f, NENCLOSE(node)->target, indent + add);
|
2004-03-05 18:31:51 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(f, "print_indent_tree: undefined node type %d\n", NTYPE(node));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:39:30 +04:00
|
|
|
if (type != NT_LIST && type != NT_ALT && type != NT_QTFR &&
|
|
|
|
type != NT_ENCLOSE)
|
2004-03-05 18:31:51 +03:00
|
|
|
fprintf(f, "\n");
|
2010-11-26 03:24:28 +03:00
|
|
|
|
|
|
|
if (container_p) print_indent_tree(f, NANCHOR(node)->target, indent + add);
|
|
|
|
|
2004-03-05 18:31:51 +03:00
|
|
|
fflush(f);
|
|
|
|
}
|
|
|
|
#endif /* ONIG_DEBUG */
|
|
|
|
|
|
|
|
#ifdef ONIG_DEBUG_PARSE_TREE
|
|
|
|
static void
|
|
|
|
print_tree(FILE* f, Node* node)
|
|
|
|
{
|
|
|
|
print_indent_tree(f, node, 0);
|
|
|
|
}
|
|
|
|
#endif
|