summaryrefslogtreecommitdiff
path: root/src/regparse.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-12-19 08:12:44 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-12-19 08:12:44 +0100
commit7547c5a1405dff1aac1ab054a24907b3ae724c12 (patch)
tree4ca475fcd4511e8cd245ce31349f4efb56089aaf /src/regparse.c
parent9d10df3f441724d605cd8729c8e8d3ba1ad816f4 (diff)
parente87df9b5e9eea77d2155767952c996f91b5eebfc (diff)
Merge branch 'release/debian/6.9.9-1'HEADdebian/6.9.9-1master
Diffstat (limited to 'src/regparse.c')
-rw-r--r--src/regparse.c601
1 files changed, 341 insertions, 260 deletions
diff --git a/src/regparse.c b/src/regparse.c
index b8f08ab..d7d188a 100644
--- a/src/regparse.c
+++ b/src/regparse.c
@@ -2,7 +2,7 @@
regparse.c - Oniguruma (regular expression library)
**********************************************************************/
/*-
- * Copyright (c) 2002-2022 K.Kosako
+ * Copyright (c) 2002-2023 K.Kosako
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,7 @@
* SUCH DAMAGE.
*/
-#ifdef DEBUG_NODE_FREE
+#ifdef DEBUG_ND_FREE
#ifndef NEED_TO_INCLUDE_STDIO
#define NEED_TO_INCLUDE_STDIO
#endif
@@ -486,6 +486,7 @@ onig_strcpy(UChar* dest, const UChar* src, const UChar* end)
#define PFETCH_READY UChar* pfetch_prev
#define PEND (p < end ? 0 : 1)
#define PUNFETCH p = pfetch_prev
+#define PPREV pfetch_prev
#define PINC do { \
pfetch_prev = p; \
p += ONIGENC_MBC_ENC_LEN(enc, p); \
@@ -547,8 +548,10 @@ typedef struct {
} st_str_end_key;
static int
-str_end_cmp(st_str_end_key* x, st_str_end_key* y)
+str_end_cmp(st_data_t ax, st_data_t ay)
{
+ st_str_end_key* x = (st_str_end_key* )ax;
+ st_str_end_key* y = (st_str_end_key* )ay;
UChar *p, *q;
int c;
@@ -568,8 +571,9 @@ str_end_cmp(st_str_end_key* x, st_str_end_key* y)
}
static int
-str_end_hash(st_str_end_key* x)
+str_end_hash(st_data_t ax)
{
+ st_str_end_key* x = (st_str_end_key* )ax;
UChar *p;
unsigned val = 0;
@@ -634,8 +638,10 @@ typedef struct {
} st_callout_name_key;
static int
-callout_name_table_cmp(st_callout_name_key* x, st_callout_name_key* y)
+callout_name_table_cmp(st_data_t ax, st_data_t ay)
{
+ st_callout_name_key* x = (st_callout_name_key* )ax;
+ st_callout_name_key* y = (st_callout_name_key* )ay;
UChar *p, *q;
int c;
@@ -657,8 +663,9 @@ callout_name_table_cmp(st_callout_name_key* x, st_callout_name_key* y)
}
static int
-callout_name_table_hash(st_callout_name_key* x)
+callout_name_table_hash(st_data_t ax)
{
+ st_callout_name_key* x = (st_callout_name_key* )ax;
UChar *p;
unsigned int val = 0;
@@ -2149,27 +2156,27 @@ node_free_body(Node* node)
{
if (IS_NULL(node)) return ;
- switch (NODE_TYPE(node)) {
- case NODE_STRING:
+ switch (ND_TYPE(node)) {
+ case ND_STRING:
if (STR_(node)->capacity != 0 &&
IS_NOT_NULL(STR_(node)->s) && STR_(node)->s != STR_(node)->buf) {
xfree(STR_(node)->s);
}
break;
- case NODE_LIST:
- case NODE_ALT:
- onig_node_free(NODE_CAR(node));
- node = NODE_CDR(node);
+ case ND_LIST:
+ case ND_ALT:
+ onig_node_free(ND_CAR(node));
+ node = ND_CDR(node);
while (IS_NOT_NULL(node)) {
- Node* next = NODE_CDR(node);
- onig_node_free(NODE_CAR(node));
+ Node* next = ND_CDR(node);
+ onig_node_free(ND_CAR(node));
xfree(node);
node = next;
}
break;
- case NODE_CCLASS:
+ case ND_CCLASS:
{
CClassNode* cc = CCLASS_(node);
@@ -2178,14 +2185,14 @@ node_free_body(Node* node)
}
break;
- case NODE_BACKREF:
+ case ND_BACKREF:
if (IS_NOT_NULL(BACKREF_(node)->back_dynamic))
xfree(BACKREF_(node)->back_dynamic);
break;
- case NODE_BAG:
- if (NODE_BODY(node))
- onig_node_free(NODE_BODY(node));
+ case ND_BAG:
+ if (ND_BODY(node))
+ onig_node_free(ND_BODY(node));
{
BagNode* en = BAG_(node);
@@ -2196,21 +2203,21 @@ node_free_body(Node* node)
}
break;
- case NODE_QUANT:
- if (NODE_BODY(node))
- onig_node_free(NODE_BODY(node));
+ case ND_QUANT:
+ if (ND_BODY(node))
+ onig_node_free(ND_BODY(node));
break;
- case NODE_ANCHOR:
- if (NODE_BODY(node))
- onig_node_free(NODE_BODY(node));
+ case ND_ANCHOR:
+ if (ND_BODY(node))
+ onig_node_free(ND_BODY(node));
if (IS_NOT_NULL(ANCHOR_(node)->lead_node))
onig_node_free(ANCHOR_(node)->lead_node);
break;
- case NODE_CTYPE:
- case NODE_CALL:
- case NODE_GIMMICK:
+ case ND_CTYPE:
+ case ND_CALL:
+ case ND_GIMMICK:
break;
}
}
@@ -2220,7 +2227,7 @@ onig_node_free(Node* node)
{
if (IS_NULL(node)) return ;
-#ifdef DEBUG_NODE_FREE
+#ifdef DEBUG_ND_FREE
fprintf(stderr, "onig_node_free: %p\n", node);
#endif
@@ -2231,8 +2238,8 @@ onig_node_free(Node* node)
static void
cons_node_free_alone(Node* node)
{
- NODE_CAR(node) = 0;
- NODE_CDR(node) = 0;
+ ND_CAR(node) = 0;
+ ND_CDR(node) = 0;
onig_node_free(node);
}
@@ -2245,7 +2252,7 @@ node_new(void)
CHECK_NULL_RETURN(node);
xmemset(node, 0, sizeof(*node));
-#ifdef DEBUG_NODE_FREE
+#ifdef DEBUG_ND_FREE
fprintf(stderr, "node_new: %p\n", node);
#endif
return node;
@@ -2259,15 +2266,15 @@ onig_node_copy(Node** rcopy, Node* from)
*rcopy = NULL_NODE;
- switch (NODE_TYPE(from)) {
- case NODE_LIST:
- case NODE_ALT:
- case NODE_ANCHOR:
+ switch (ND_TYPE(from)) {
+ case ND_LIST:
+ case ND_ALT:
+ case ND_ANCHOR:
/* These node's link to other nodes are processed by caller. */
break;
- case NODE_STRING:
- case NODE_CCLASS:
- case NODE_CTYPE:
+ case ND_STRING:
+ case ND_CCLASS:
+ case ND_CTYPE:
/* Fixed contents after copy. */
break;
default:
@@ -2280,8 +2287,8 @@ onig_node_copy(Node** rcopy, Node* from)
CHECK_NULL_RETURN_MEMERR(copy);
xmemcpy(copy, from, sizeof(*copy));
- switch (NODE_TYPE(copy)) {
- case NODE_STRING:
+ switch (ND_TYPE(copy)) {
+ case ND_STRING:
r = onig_node_str_set(copy, STR_(from)->s, STR_(from)->end, FALSE);
if (r != 0) {
err:
@@ -2290,7 +2297,7 @@ onig_node_copy(Node** rcopy, Node* from)
}
break;
- case NODE_CCLASS:
+ case ND_CCLASS:
{
CClassNode *fcc, *tcc;
@@ -2326,7 +2333,7 @@ node_new_cclass(void)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_CCLASS);
+ ND_SET_TYPE(node, ND_CCLASS);
initialize_cclass(CCLASS_(node));
return node;
}
@@ -2337,7 +2344,7 @@ node_new_ctype(int type, int not, OnigOptionType options)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_CTYPE);
+ ND_SET_TYPE(node, ND_CTYPE);
CTYPE_(node)->ctype = type;
CTYPE_(node)->not = not;
CTYPE_(node)->ascii_mode = OPTON_IS_ASCII_MODE_CTYPE(type, options);
@@ -2353,7 +2360,7 @@ node_new_anychar(OnigOptionType options)
CHECK_NULL_RETURN(node);
if (OPTON_MULTILINE(options))
- NODE_STATUS_ADD(node, MULTILINE);
+ ND_STATUS_ADD(node, MULTILINE);
return node;
}
@@ -2385,9 +2392,9 @@ node_new_list(Node* left, Node* right)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_LIST);
- NODE_CAR(node) = left;
- NODE_CDR(node) = right;
+ ND_SET_TYPE(node, ND_LIST);
+ ND_CAR(node) = left;
+ ND_CDR(node) = right;
return node;
}
@@ -2403,9 +2410,9 @@ onig_node_new_alt(Node* left, Node* right)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_ALT);
- NODE_CAR(node) = left;
- NODE_CDR(node) = right;
+ ND_SET_TYPE(node, ND_ALT);
+ ND_CAR(node) = left;
+ ND_CDR(node) = right;
return node;
}
@@ -2419,9 +2426,9 @@ make_list_or_alt(NodeType type, int n, Node* ns[])
if (n == 1) {
r = node_new();
CHECK_NULL_RETURN(r);
- NODE_SET_TYPE(r, type);
- NODE_CAR(r) = ns[0];
- NODE_CDR(r) = NULL_NODE;
+ ND_SET_TYPE(r, type);
+ ND_CAR(r) = ns[0];
+ ND_CDR(r) = NULL_NODE;
}
else {
Node* right;
@@ -2435,9 +2442,9 @@ make_list_or_alt(NodeType type, int n, Node* ns[])
return NULL_NODE;
}
- NODE_SET_TYPE(r, type);
- NODE_CAR(r) = ns[0];
- NODE_CDR(r) = right;
+ ND_SET_TYPE(r, type);
+ ND_CAR(r) = ns[0];
+ ND_CDR(r) = right;
}
return r;
@@ -2446,13 +2453,13 @@ make_list_or_alt(NodeType type, int n, Node* ns[])
static Node*
make_list(int n, Node* ns[])
{
- return make_list_or_alt(NODE_LIST, n, ns);
+ return make_list_or_alt(ND_LIST, n, ns);
}
static Node*
make_alt(int n, Node* ns[])
{
- return make_list_or_alt(NODE_ALT, n, ns);
+ return make_list_or_alt(ND_ALT, n, ns);
}
static Node*
@@ -2463,7 +2470,7 @@ node_new_anchor(int type)
node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_ANCHOR);
+ ND_SET_TYPE(node, ND_ANCHOR);
ANCHOR_(node)->type = type;
ANCHOR_(node)->char_min_len = 0;
ANCHOR_(node)->char_max_len = INFINITE_LEN;
@@ -2487,7 +2494,7 @@ node_new_anchor_with_options(int type, OnigOptionType options)
if (type == ANCR_TEXT_SEGMENT_BOUNDARY ||
type == ANCR_NO_TEXT_SEGMENT_BOUNDARY) {
if (OPTON_TEXT_SEGMENT_WORD(options))
- NODE_STATUS_ADD(node, TEXT_SEGMENT_WORD);
+ ND_STATUS_ADD(node, TEXT_SEGMENT_WORD);
}
return node;
@@ -2506,18 +2513,18 @@ node_new_backref(int back_num, int* backrefs, int by_name,
node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_BACKREF);
+ ND_SET_TYPE(node, ND_BACKREF);
BACKREF_(node)->back_num = back_num;
BACKREF_(node)->back_dynamic = (int* )NULL;
if (by_name != 0)
- NODE_STATUS_ADD(node, BY_NAME);
+ ND_STATUS_ADD(node, BY_NAME);
if (OPTON_IGNORECASE(env->options))
- NODE_STATUS_ADD(node, IGNORECASE);
+ ND_STATUS_ADD(node, IGNORECASE);
#ifdef USE_BACKREF_WITH_LEVEL
if (exist_level != 0) {
- NODE_STATUS_ADD(node, NEST_LEVEL);
+ ND_STATUS_ADD(node, NEST_LEVEL);
BACKREF_(node)->nest_level = nest_level;
}
#endif
@@ -2525,12 +2532,12 @@ node_new_backref(int back_num, int* backrefs, int by_name,
for (i = 0; i < back_num; i++) {
if (backrefs[i] <= env->num_mem &&
IS_NULL(PARSEENV_MEMENV(env)[backrefs[i]].mem_node)) {
- NODE_STATUS_ADD(node, RECURSION); /* /...(\1).../ */
+ ND_STATUS_ADD(node, RECURSION); /* /...(\1).../ */
break;
}
}
- if (back_num <= NODE_BACKREFS_SIZE) {
+ if (back_num <= ND_BACKREFS_SIZE) {
for (i = 0; i < back_num; i++)
BACKREF_(node)->back_static[i] = backrefs[i];
}
@@ -2565,7 +2572,7 @@ node_new_backref_checker(int back_num, int* backrefs, int by_name,
env);
CHECK_NULL_RETURN(node);
- NODE_STATUS_ADD(node, CHECKER);
+ ND_STATUS_ADD(node, CHECKER);
return node;
}
@@ -2576,7 +2583,7 @@ node_new_call(UChar* name, UChar* name_end, int gnum, int by_number)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_CALL);
+ ND_SET_TYPE(node, ND_CALL);
CALL_(node)->by_number = by_number;
CALL_(node)->name = name;
CALL_(node)->name_end = name_end;
@@ -2592,7 +2599,7 @@ node_new_quantifier(int lower, int upper, int by_number)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_QUANT);
+ ND_SET_TYPE(node, ND_QUANT);
QUANT_(node)->lower = lower;
QUANT_(node)->upper = upper;
QUANT_(node)->greedy = 1;
@@ -2602,7 +2609,7 @@ node_new_quantifier(int lower, int upper, int by_number)
QUANT_(node)->include_referred = 0;
QUANT_(node)->empty_status_mem = 0;
if (by_number != 0)
- NODE_STATUS_ADD(node, BY_NUMBER);
+ ND_STATUS_ADD(node, BY_NUMBER);
return node;
}
@@ -2613,7 +2620,7 @@ node_new_bag(enum BagType type)
Node* node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_BAG);
+ ND_SET_TYPE(node, ND_BAG);
BAG_(node)->type = type;
switch (type) {
@@ -2654,7 +2661,7 @@ node_new_bag_if_else(Node* cond, Node* Then, Node* Else)
n = node_new_bag(BAG_IF_ELSE);
CHECK_NULL_RETURN(n);
- NODE_BODY(n) = cond;
+ ND_BODY(n) = cond;
BAG_(n)->te.Then = Then;
BAG_(n)->te.Else = Else;
return n;
@@ -2666,7 +2673,7 @@ node_new_memory(int is_named)
Node* node = node_new_bag(BAG_MEMORY);
CHECK_NULL_RETURN(node);
if (is_named != 0)
- NODE_STATUS_ADD(node, NAMED_GROUP);
+ ND_STATUS_ADD(node, NAMED_GROUP);
return node;
}
@@ -2687,9 +2694,9 @@ node_new_group(Node* content)
node = node_new();
CHECK_NULL_RETURN(node);
- NODE_SET_TYPE(node, NODE_LIST);
- NODE_CAR(node) = content;
- NODE_CDR(node) = NULL_NODE;
+ ND_SET_TYPE(node, ND_LIST);
+ ND_CAR(node) = content;
+ ND_CDR(node) = NULL_NODE;
return node;
}
@@ -2699,8 +2706,8 @@ node_drop_group(Node* group)
{
Node* content;
- content = NODE_CAR(group);
- NODE_CAR(group) = NULL_NODE;
+ content = ND_CAR(group);
+ ND_CAR(group) = NULL_NODE;
onig_node_free(group);
return content;
}
@@ -2708,7 +2715,7 @@ node_drop_group(Node* group)
static int
node_set_fail(Node* node)
{
- NODE_SET_TYPE(node, NODE_GIMMICK);
+ ND_SET_TYPE(node, ND_GIMMICK);
GIMMICK_(node)->type = GIMMICK_FAIL;
return ONIG_NORMAL;
}
@@ -2739,7 +2746,7 @@ node_new_save_gimmick(Node** node, enum SaveType save_type, ParseEnv* env)
*node = node_new();
CHECK_NULL_RETURN_MEMERR(*node);
- NODE_SET_TYPE(*node, NODE_GIMMICK);
+ ND_SET_TYPE(*node, ND_GIMMICK);
GIMMICK_(*node)->id = id;
GIMMICK_(*node)->type = GIMMICK_SAVE;
GIMMICK_(*node)->detail_type = (int )save_type;
@@ -2754,7 +2761,7 @@ node_new_update_var_gimmick(Node** node, enum UpdateVarType update_var_type,
*node = node_new();
CHECK_NULL_RETURN_MEMERR(*node);
- NODE_SET_TYPE(*node, NODE_GIMMICK);
+ ND_SET_TYPE(*node, ND_GIMMICK);
GIMMICK_(*node)->id = id;
GIMMICK_(*node)->type = GIMMICK_UPDATE_VAR;
GIMMICK_(*node)->detail_type = (int )update_var_type;
@@ -2874,7 +2881,7 @@ node_new_callout(Node** node, OnigCalloutOf callout_of, int num, int id,
*node = node_new();
CHECK_NULL_RETURN_MEMERR(*node);
- NODE_SET_TYPE(*node, NODE_GIMMICK);
+ ND_SET_TYPE(*node, ND_GIMMICK);
GIMMICK_(*node)->id = id;
GIMMICK_(*node)->num = num;
GIMMICK_(*node)->type = GIMMICK_CALLOUT;
@@ -2911,7 +2918,7 @@ make_text_segment(Node** node, ParseEnv* env)
x = node_new_quantifier(0, INFINITE_REPEAT, TRUE);
if (IS_NULL(x)) goto err;
- NODE_BODY(x) = ns[0];
+ ND_BODY(x) = ns[0];
ns[0] = NULL_NODE;
ns[1] = x;
@@ -2927,7 +2934,7 @@ make_text_segment(Node** node, ParseEnv* env)
x = node_new_bag(BAG_STOP_BACKTRACK);
if (IS_NULL(x)) goto err;
- NODE_BODY(x) = ns[0];
+ ND_BODY(x) = ns[0];
*node = x;
return ONIG_NORMAL;
@@ -2963,7 +2970,7 @@ make_absent_engine(Node** node, int pre_save_right_id, Node* absent,
if (r != 0) goto err;
if (is_range_cutter != 0)
- NODE_STATUS_ADD(ns[2], ABSENT_WITH_SIDE_EFFECTS);
+ ND_STATUS_ADD(ns[2], ABSENT_WITH_SIDE_EFFECTS);
r = node_new_fail(&ns[3], env);
if (r != 0) goto err;
@@ -2983,14 +2990,14 @@ make_absent_engine(Node** node, int pre_save_right_id, Node* absent,
x = node_new_quantifier(lower, upper, FALSE);
if (IS_NULL(x)) goto err0;
- NODE_BODY(x) = ns[0];
+ ND_BODY(x) = ns[0];
ns[0] = x;
if (possessive != 0) {
x = node_new_bag(BAG_STOP_BACKTRACK);
if (IS_NULL(x)) goto err0;
- NODE_BODY(x) = ns[0];
+ ND_BODY(x) = ns[0];
ns[0] = x;
}
@@ -3010,7 +3017,7 @@ make_absent_engine(Node** node, int pre_save_right_id, Node* absent,
if (IS_NULL(x)) goto err0;
if (is_range_cutter != FALSE)
- NODE_STATUS_ADD(x, SUPER);
+ ND_STATUS_ADD(x, SUPER);
*node = x;
return ONIG_NORMAL;
@@ -3104,12 +3111,12 @@ make_range_clear(Node** node, ParseEnv* env)
r = node_new_update_var_gimmick(&ns[0], UPDATE_VAR_RIGHT_RANGE_INIT,
ID_NOT_USED_DONT_CARE_ME, env);
if (r != 0) goto err;
- NODE_STATUS_ADD(ns[0], ABSENT_WITH_SIDE_EFFECTS);
+ ND_STATUS_ADD(ns[0], ABSENT_WITH_SIDE_EFFECTS);
x = make_alt(2, ns);
if (IS_NULL(x)) goto err0;
- NODE_STATUS_ADD(x, SUPER);
+ ND_STATUS_ADD(x, SUPER);
ns[0] = save;
ns[1] = x;
@@ -3139,16 +3146,16 @@ is_simple_one_char_repeat(Node* node, Node** rquant, Node** rbody,
*rquant = *rbody = 0;
*is_possessive = 0;
- if (NODE_TYPE(node) == NODE_QUANT) {
+ if (ND_TYPE(node) == ND_QUANT) {
quant = node;
}
else {
- if (NODE_TYPE(node) == NODE_BAG) {
+ if (ND_TYPE(node) == ND_BAG) {
BagNode* en = BAG_(node);
if (en->type == BAG_STOP_BACKTRACK) {
*is_possessive = 1;
- quant = NODE_BAG_BODY(en);
- if (NODE_TYPE(quant) != NODE_QUANT)
+ quant = ND_BAG_BODY(en);
+ if (ND_TYPE(quant) != ND_QUANT)
return 0;
}
else
@@ -3161,9 +3168,9 @@ is_simple_one_char_repeat(Node* node, Node** rquant, Node** rbody,
if (QUANT_(quant)->greedy == 0)
return 0;
- body = NODE_BODY(quant);
- switch (NODE_TYPE(body)) {
- case NODE_STRING:
+ body = ND_BODY(quant);
+ switch (ND_TYPE(body)) {
+ case ND_STRING:
{
int len;
StrNode* sn = STR_(body);
@@ -3178,7 +3185,7 @@ is_simple_one_char_repeat(Node* node, Node** rquant, Node** rbody,
return 0;
}
- case NODE_CCLASS:
+ case ND_CCLASS:
break;
default:
@@ -3187,10 +3194,10 @@ is_simple_one_char_repeat(Node* node, Node** rquant, Node** rbody,
}
if (node != quant) {
- NODE_BODY(node) = 0;
+ ND_BODY(node) = 0;
onig_node_free(node);
}
- NODE_BODY(quant) = NULL_NODE;
+ ND_BODY(quant) = NULL_NODE;
*rquant = quant;
*rbody = body;
return 1;
@@ -3346,9 +3353,9 @@ onig_node_str_cat(Node* node, const UChar* s, const UChar* end)
if (addlen > 0) {
int len = (int )(STR_(node)->end - STR_(node)->s);
- if (STR_(node)->capacity > 0 || (len + addlen > NODE_STRING_BUF_SIZE - 1)) {
+ if (STR_(node)->capacity > 0 || (len + addlen > ND_STRING_BUF_SIZE - 1)) {
UChar* p;
- int capa = len + addlen + NODE_STRING_MARGIN;
+ int capa = len + addlen + ND_STRING_MARGIN;
if (capa <= STR_(node)->capacity) {
onig_strcpy(STR_(node)->s + len, s, end);
@@ -3410,7 +3417,7 @@ node_set_str(Node* node, const UChar* s, const UChar* end)
{
int r;
- NODE_SET_TYPE(node, NODE_STRING);
+ ND_SET_TYPE(node, ND_STRING);
STR_(node)->flag = 0;
STR_(node)->s = STR_(node)->buf;
STR_(node)->end = STR_(node)->buf;
@@ -3463,7 +3470,7 @@ node_new_str_with_options(const UChar* s, const UChar* end,
node = node_new_str(s, end);
if (OPTON_IGNORECASE(options))
- NODE_STATUS_ADD(node, IGNORECASE);
+ ND_STATUS_ADD(node, IGNORECASE);
return node;
}
@@ -3473,7 +3480,7 @@ node_new_str_crude(UChar* s, UChar* end, OnigOptionType options)
{
Node* node = node_new_str_with_options(s, end, options);
CHECK_NULL_RETURN(node);
- NODE_STRING_SET_CRUDE(node);
+ ND_STRING_SET_CRUDE(node);
return node;
}
@@ -3492,9 +3499,10 @@ node_new_str_crude_char(UChar c, OnigOptionType options)
p[0] = c;
node = node_new_str_crude(p, p + 1, options);
+ CHECK_NULL_RETURN(node);
/* clear buf tail */
- for (i = 1; i < NODE_STRING_BUF_SIZE; i++)
+ for (i = 1; i < ND_STRING_BUF_SIZE; i++)
STR_(node)->buf[i] = '\0';
return node;
@@ -3517,7 +3525,7 @@ str_node_split_last_char(Node* node, OnigEncoding enc)
sn->end = (UChar* )p;
STR_(rn)->flag = sn->flag;
- NODE_STATUS(rn) = NODE_STATUS(node);
+ ND_STATUS(rn) = ND_STATUS(node);
}
}
@@ -4276,28 +4284,28 @@ conv_backslash_value(OnigCodePoint c, ParseEnv* env)
static int
is_invalid_quantifier_target(Node* node)
{
- switch (NODE_TYPE(node)) {
- case NODE_ANCHOR:
- case NODE_GIMMICK:
+ switch (ND_TYPE(node)) {
+ case ND_ANCHOR:
+ case ND_GIMMICK:
return 1;
break;
- case NODE_BAG:
+ case ND_BAG:
/* allow enclosed elements */
- /* return is_invalid_quantifier_target(NODE_BODY(node)); */
+ /* return is_invalid_quantifier_target(ND_BODY(node)); */
break;
- case NODE_LIST:
+ case ND_LIST:
do {
- if (! is_invalid_quantifier_target(NODE_CAR(node))) return 0;
- } while (IS_NOT_NULL(node = NODE_CDR(node)));
+ if (! is_invalid_quantifier_target(ND_CAR(node))) return 0;
+ } while (IS_NOT_NULL(node = ND_CDR(node)));
return 0;
break;
- case NODE_ALT:
+ case ND_ALT:
do {
- if (is_invalid_quantifier_target(NODE_CAR(node))) return 1;
- } while (IS_NOT_NULL(node = NODE_CDR(node)));
+ if (is_invalid_quantifier_target(ND_CAR(node))) return 1;
+ } while (IS_NOT_NULL(node = ND_CDR(node)));
break;
default:
@@ -4334,7 +4342,7 @@ quantifier_type_num(QuantNode* q)
enum ReduceType {
RQ_ASIS = 0, /* as is */
- RQ_DEL = 1, /* delete parent */
+ RQ_DEL, /* delete parent */
RQ_A, /* to '*' */
RQ_P, /* to '+' */
RQ_AQ, /* to '*?' */
@@ -4358,7 +4366,7 @@ onig_reduce_nested_quantifier(Node* pnode)
QuantNode *p, *c;
Node* cnode;
- cnode = NODE_BODY(pnode);
+ cnode = ND_BODY(pnode);
p = QUANT_(pnode);
c = QUANT_(cnode);
@@ -4370,7 +4378,7 @@ onig_reduce_nested_quantifier(Node* pnode)
if (n < 0) return ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE;
p->lower = p->upper = n;
- NODE_BODY(pnode) = NODE_BODY(cnode);
+ ND_BODY(pnode) = ND_BODY(cnode);
goto remove_cnode;
}
@@ -4383,22 +4391,22 @@ onig_reduce_nested_quantifier(Node* pnode)
goto remove_cnode;
break;
case RQ_A:
- NODE_BODY(pnode) = NODE_BODY(cnode);
+ ND_BODY(pnode) = ND_BODY(cnode);
p->lower = 0; p->upper = INFINITE_REPEAT; p->greedy = 1;
goto remove_cnode;
break;
case RQ_P:
- NODE_BODY(pnode) = NODE_BODY(cnode);
+ ND_BODY(pnode) = ND_BODY(cnode);
p->lower = 1; p->upper = INFINITE_REPEAT; p->greedy = 1;
goto remove_cnode;
break;
case RQ_AQ:
- NODE_BODY(pnode) = NODE_BODY(cnode);
+ ND_BODY(pnode) = ND_BODY(cnode);
p->lower = 0; p->upper = INFINITE_REPEAT; p->greedy = 0;
goto remove_cnode;
break;
case RQ_QQ:
- NODE_BODY(pnode) = NODE_BODY(cnode);
+ ND_BODY(pnode) = ND_BODY(cnode);
p->lower = 0; p->upper = 1; p->greedy = 0;
goto remove_cnode;
break;
@@ -4413,7 +4421,7 @@ onig_reduce_nested_quantifier(Node* pnode)
return 0;
remove_cnode:
- NODE_BODY(cnode) = NULL_NODE;
+ ND_BODY(cnode) = NULL_NODE;
onig_node_free(cnode);
return 0;
}
@@ -4471,7 +4479,7 @@ node_new_general_newline(Node** node, ParseEnv* env)
enum TokenSyms {
TK_EOT = 0, /* end of token */
- TK_CRUDE_BYTE = 1,
+ TK_CRUDE_BYTE,
TK_CHAR,
TK_STRING,
TK_CODE_POINT,
@@ -5103,41 +5111,96 @@ find_str_position(OnigCodePoint s[], int n, UChar* from, UChar* to,
}
static int
-str_exist_check_with_esc(OnigCodePoint s[], int n, UChar* from, UChar* to,
- OnigCodePoint bad, OnigEncoding enc, OnigSyntaxType* syn)
+is_head_of_bre_subexp(UChar* p, UChar* end, OnigEncoding enc, ParseEnv* env)
{
- int i, in_esc;
- OnigCodePoint x;
- UChar *q;
- UChar *p = from;
+ UChar* start;
+ OnigCodePoint code;
- in_esc = 0;
- while (p < to) {
- if (in_esc) {
- in_esc = 0;
- p += enclen(enc, p);
- }
- else {
- x = ONIGENC_MBC_TO_CODE(enc, p, to);
- q = p + enclen(enc, p);
- if (x == s[0]) {
- for (i = 1; i < n && q < to; i++) {
- x = ONIGENC_MBC_TO_CODE(enc, q, to);
- if (x != s[i]) break;
- q += enclen(enc, q);
+ start = env->pattern;
+ if (p > start) {
+ p = onigenc_get_prev_char_head(enc, start, p);
+ if (p > start) {
+ code = ONIGENC_MBC_TO_CODE(enc, p, end);
+ if (code == '(' ||
+ (code == '|' &&
+ IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_VBAR_ALT))) {
+ p = onigenc_get_prev_char_head(enc, start, p);
+ code = ONIGENC_MBC_TO_CODE(enc, p, end);
+ if (IS_MC_ESC_CODE(code, env->syntax)) {
+ int count = 0;
+ while (p > start) {
+ p = onigenc_get_prev_char_head(enc, start, p);
+ code = ONIGENC_MBC_TO_CODE(enc, p, end);
+ if (! IS_MC_ESC_CODE(code, env->syntax)) break;
+ count++;
+ }
+ return (count % 2 == 0);
}
- if (i >= n) return 1;
- p += enclen(enc, p);
}
- else {
+ }
+ return FALSE;
+ }
+ else {
+ return TRUE;
+ }
+}
+
+static int
+is_end_of_bre_subexp(UChar* p, UChar* end, OnigEncoding enc, ParseEnv* env)
+{
+ OnigCodePoint code;
+
+ if (p == end) return TRUE;
+
+ code = ONIGENC_MBC_TO_CODE(enc, p, end);
+ if (IS_MC_ESC_CODE(code, env->syntax)) {
+ p += ONIGENC_MBC_ENC_LEN(enc, p);
+ if (p < end) {
+ code = ONIGENC_MBC_TO_CODE(enc, p, end);
+ if (code == ')' ||
+ (code == '|' &&
+ IS_SYNTAX_OP(env->syntax, ONIG_SYN_OP_ESC_VBAR_ALT)))
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static int
+is_posix_bracket_start(UChar* from, UChar* to, OnigEncoding enc)
+{
+ int n;
+ OnigCodePoint x;
+ UChar *p;
+
+ n = 0;
+ p = from;
+ while (p < to) {
+ x = ONIGENC_MBC_TO_CODE(enc, p, to);
+ p += enclen(enc, p);
+ if (x == ':') {
+ if (p < to) {
x = ONIGENC_MBC_TO_CODE(enc, p, to);
- if (x == bad) return 0;
- else if (x == MC_ESC(syn)) in_esc = 1;
- p = q;
+ if (x == ']') {
+ if (n == 0) return FALSE;
+ else return TRUE;
+ }
}
+
+ return FALSE;
+ }
+ else if (x == '^' && n == 0) {
+ ;
}
+ else if (! ONIGENC_IS_CODE_ALPHA(enc, x)) {
+ break;
+ }
+
+ n += 1;
}
- return 0;
+
+ return FALSE;
}
static int
@@ -5392,11 +5455,9 @@ fetch_token_cc(PToken* tok, UChar** src, UChar* end, ParseEnv* env, int state)
}
else if (c == '[') {
if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_POSIX_BRACKET) && (PPEEK_IS(':'))) {
- OnigCodePoint send[] = { (OnigCodePoint )':', (OnigCodePoint )']' };
tok->backp = p; /* point at '[' is read */
PINC;
- if (str_exist_check_with_esc(send, 2, p, end,
- (OnigCodePoint )']', enc, syn)) {
+ if (is_posix_bracket_start(p, end, enc)) {
tok->type = TK_CC_POSIX_BRACKET_OPEN;
}
else {
@@ -6163,8 +6224,20 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ParseEnv* env)
case '-':
case '+':
- goto lparen_qmark_num;
+ if (! PEND) {
+ PINC;
+ if (! PEND) {
+ c = PPEEK;
+ if (ONIGENC_IS_CODE_DIGIT(enc, c)) {
+ PUNFETCH;
+ goto lparen_qmark_num;
+ }
+ }
+ }
+ p = prev;
+ goto lparen_qmark_end2;
break;
+
default:
if (! ONIGENC_IS_CODE_DIGIT(enc, c)) goto lparen_qmark_end;
@@ -6197,6 +6270,7 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ParseEnv* env)
}
break;
}
+ break;
}
else if (c == 'P' &&
IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_CAPITAL_P_NAME)) {
@@ -6238,6 +6312,9 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ParseEnv* env)
case '^':
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
+ if (IS_SYNTAX_BV(syn, ONIG_SYN_BRE_ANCHOR_AT_EDGE_OF_SUBEXP)) {
+ if (! is_head_of_bre_subexp(PPREV, end, enc, env)) break;
+ }
tok->type = TK_ANCHOR;
tok->u.subtype = (OPTON_SINGLELINE(env->options)
? ANCR_BEGIN_BUF : ANCR_BEGIN_LINE);
@@ -6245,6 +6322,9 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ParseEnv* env)
case '$':
if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
+ if (IS_SYNTAX_BV(syn, ONIG_SYN_BRE_ANCHOR_AT_EDGE_OF_SUBEXP)) {
+ if (! is_end_of_bre_subexp(p, end, enc, env)) break;
+ }
tok->type = TK_ANCHOR;
tok->u.subtype = (OPTON_SINGLELINE(env->options)
? ANCR_SEMI_END_BUF : ANCR_END_LINE);
@@ -6560,9 +6640,6 @@ add_ctype_to_cc(CClassNode* cc, int ctype, int not, ParseEnv* env)
static int
prs_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ParseEnv* env)
{
-#define POSIX_BRACKET_CHECK_LIMIT_LENGTH 20
-#define POSIX_BRACKET_NAME_MIN_LEN 4
-
static PosixBracketEntryType PBS[] = {
{ (UChar* )"alnum", ONIGENC_CTYPE_ALNUM, 5 },
{ (UChar* )"alpha", ONIGENC_CTYPE_ALPHA, 5 },
@@ -6582,8 +6659,7 @@ prs_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ParseEnv* env)
};
PosixBracketEntryType *pb;
- int not, i, r;
- OnigCodePoint c;
+ int not, r;
OnigEncoding enc = env->enc;
UChar *p = *src;
@@ -6594,14 +6670,11 @@ prs_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ParseEnv* env)
else
not = 0;
- if (onigenc_strlen(enc, p, end) < POSIX_BRACKET_NAME_MIN_LEN + 3)
- goto not_posix_bracket;
-
for (pb = PBS; IS_NOT_NULL(pb->name); pb++) {
if (onigenc_with_ascii_strncmp(enc, p, end, pb->name, pb->len) == 0) {
p = (UChar* )onigenc_step(enc, p, end, pb->len);
if (onigenc_with_ascii_strncmp(enc, p, end, (UChar* )":]", 2) != 0)
- return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
+ break;
r = add_ctype_to_cc(cc, pb->ctype, not, env);
if (r != 0) return r;
@@ -6612,23 +6685,7 @@ prs_posix_bracket(CClassNode* cc, UChar** src, UChar* end, ParseEnv* env)
}
}
- not_posix_bracket:
- c = 0;
- i = 0;
- while (!PEND && ((c = PPEEK) != ':') && c != ']') {
- PINC_S;
- if (++i > POSIX_BRACKET_CHECK_LIMIT_LENGTH) break;
- }
- if (c == ':' && ! PEND) {
- PINC_S;
- if (! PEND) {
- PFETCH_S(c);
- if (c == ']')
- return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
- }
- }
-
- return 1; /* 1: is not POSIX bracket, but no error. */
+ return ONIGERR_INVALID_POSIX_BRACKET_TYPE;
}
static int
@@ -6676,6 +6733,12 @@ prs_char_property(Node** np, PToken* tok, UChar** src, UChar* end,
ctype = fetch_char_property_to_ctype(src, end, env);
if (ctype < 0) return ctype;
+ if (ctype == ONIGENC_CTYPE_WORD) {
+ *np = node_new_ctype(ctype, tok->u.prop.not, env->options);
+ CHECK_NULL_RETURN_MEMERR(*np);
+ return 0;
+ }
+
*np = node_new_cclass();
CHECK_NULL_RETURN_MEMERR(*np);
cc = CCLASS_(*np);
@@ -6912,6 +6975,11 @@ prs_cc(Node** np, PToken* tok, UChar** src, UChar* end, ParseEnv* env)
goto crude_single;
}
else {
+ if (! ONIGENC_IS_VALID_MBC_STRING(env->enc, buf, buf + len)) {
+ r = ONIGERR_INVALID_WIDE_CHAR_VALUE;
+ goto err;
+ }
+
in_code = ONIGENC_MBC_TO_CODE(env->enc, buf, bufe);
in_type = CV_MB;
}
@@ -7675,6 +7743,37 @@ prs_callout_of_name(Node** np, int cterm, UChar** src, UChar* end,
}
#endif
+#ifdef USE_WHOLE_OPTIONS
+static int
+set_whole_options(OnigOptionType option, ParseEnv* env)
+{
+ if ((env->flags & PE_FLAG_HAS_WHOLE_OPTIONS) != 0)
+ return ONIGERR_INVALID_GROUP_OPTION;
+
+ env->flags |= PE_FLAG_HAS_WHOLE_OPTIONS;
+
+ if (OPTON_DONT_CAPTURE_GROUP(option)) {
+ env->reg->options |= ONIG_OPTION_DONT_CAPTURE_GROUP;
+ 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;
+ }
+
+ if ((option & ONIG_OPTION_IGNORECASE_IS_ASCII) != 0) {
+ env->reg->case_fold_flag &=
+ ~(INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR |
+ ONIGENC_CASE_FOLD_TURKISH_AZERI);
+ env->reg->case_fold_flag |= ONIGENC_CASE_FOLD_ASCII_ONLY;
+ env->reg->options |= ONIG_OPTION_IGNORECASE_IS_ASCII;
+ }
+
+ if (OPTON_FIND_LONGEST(option)) {
+ env->reg->options |= ONIG_OPTION_FIND_LONGEST;
+ }
+
+ return 0;
+}
+#endif
+
static int
prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
ParseEnv* env)
@@ -7794,6 +7893,7 @@ prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
PINC;
r = make_range_clear(np, env);
if (r != 0) return r;
+ env->flags |= PE_FLAG_HAS_ABSENT_STOPPER;
goto end;
}
}
@@ -7812,21 +7912,21 @@ prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
is_range_cutter = 0;
if (head_bar != 0) {
Node* top = absent;
- if (NODE_TYPE(top) != NODE_ALT || IS_NULL(NODE_CDR(top))) {
+ if (ND_TYPE(top) != ND_ALT || IS_NULL(ND_CDR(top))) {
expr = NULL_NODE;
is_range_cutter = 1;
- /* return ONIGERR_INVALID_ABSENT_GROUP_GENERATOR_PATTERN; */
+ env->flags |= PE_FLAG_HAS_ABSENT_STOPPER;
}
else {
- absent = NODE_CAR(top);
- expr = NODE_CDR(top);
- NODE_CAR(top) = NULL_NODE;
- NODE_CDR(top) = NULL_NODE;
+ absent = ND_CAR(top);
+ expr = ND_CDR(top);
+ ND_CAR(top) = NULL_NODE;
+ ND_CDR(top) = NULL_NODE;
onig_node_free(top);
- if (IS_NULL(NODE_CDR(expr))) {
+ if (IS_NULL(ND_CDR(expr))) {
top = expr;
- expr = NODE_CAR(top);
- NODE_CAR(top) = NULL_NODE;
+ expr = ND_CAR(top);
+ ND_CAR(top) = NULL_NODE;
onig_node_free(top);
}
}
@@ -8034,14 +8134,14 @@ prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
Else = target;
}
else {
- if (NODE_TYPE(target) == NODE_ALT) {
- Then = NODE_CAR(target);
- if (NODE_CDR(NODE_CDR(target)) == NULL_NODE) {
- Else = NODE_CAR(NODE_CDR(target));
- cons_node_free_alone(NODE_CDR(target));
+ if (ND_TYPE(target) == ND_ALT) {
+ Then = ND_CAR(target);
+ if (ND_CDR(ND_CDR(target)) == NULL_NODE) {
+ Else = ND_CAR(ND_CDR(target));
+ cons_node_free_alone(ND_CDR(target));
}
else {
- Else = NODE_CDR(target);
+ Else = ND_CDR(target);
}
cons_node_free_alone(target);
}
@@ -8274,43 +8374,27 @@ prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
if (c == ')') {
*np = node_new_option(option);
CHECK_NULL_RETURN_MEMERR(*np);
- r = 2; /* option only */
#ifdef USE_WHOLE_OPTIONS
- set_whole_options:
if (whole_options == TRUE) {
- if ((env->flags & PE_FLAG_HAS_WHOLE_OPTIONS) != 0)
- return ONIGERR_INVALID_GROUP_OPTION;
-
- env->flags |= PE_FLAG_HAS_WHOLE_OPTIONS;
- NODE_STATUS_ADD(*np, WHOLE_OPTIONS);
-
- if (OPTON_DONT_CAPTURE_GROUP(option)) {
- env->reg->options |= ONIG_OPTION_DONT_CAPTURE_GROUP;
- 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;
- }
-
- if ((option & ONIG_OPTION_IGNORECASE_IS_ASCII) != 0) {
- env->reg->case_fold_flag &=
- ~(INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR |
- ONIGENC_CASE_FOLD_TURKISH_AZERI);
- env->reg->case_fold_flag |= ONIGENC_CASE_FOLD_ASCII_ONLY;
- env->reg->options |= ONIG_OPTION_IGNORECASE_IS_ASCII;
- }
-
- if (OPTON_FIND_LONGEST(option)) {
- env->reg->options |= ONIG_OPTION_FIND_LONGEST;
- }
+ r = set_whole_options(option, env);
+ if (r != 0) return r;
+ ND_STATUS_ADD(*np, WHOLE_OPTIONS);
}
#endif
*src = p;
- return r;
+ return 2; /* option only */
}
else if (c == ':') {
OnigOptionType prev = env->options;
env->options = option;
+#ifdef USE_WHOLE_OPTIONS
+ if (whole_options == TRUE) {
+ r = set_whole_options(option, env);
+ if (r != 0) return r;
+ }
+#endif
r = fetch_token(tok, &p, end, env);
if (r < 0) return r;
r = prs_alts(&target, tok, term, &p, end, env, FALSE);
@@ -8319,16 +8403,12 @@ prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
onig_node_free(target);
return r;
}
+
*np = node_new_option(option);
CHECK_NULL_RETURN_MEMERR(*np);
- NODE_BODY(*np) = target;
+ ND_BODY(*np) = target;
+ ND_STATUS_ADD(*np, WHOLE_OPTIONS);
-#ifdef USE_WHOLE_OPTIONS
- if (whole_options == TRUE) {
- r = 0;
- goto set_whole_options;
- }
-#endif
*src = p;
return 0;
}
@@ -8373,9 +8453,9 @@ prs_bag(Node** np, PToken* tok, int term, UChar** src, UChar* end,
return r;
}
- NODE_BODY(*np) = target;
+ ND_BODY(*np) = target;
- if (NODE_TYPE(*np) == NODE_BAG) {
+ if (ND_TYPE(*np) == ND_BAG) {
if (BAG_(*np)->type == BAG_MEMORY) {
/* Don't move this to previous of prs_alts() */
r = scan_env_set_mem_node(env, BAG_(*np)->m.regnum, *np);
@@ -8405,20 +8485,20 @@ assign_quantifier_body(Node* qnode, Node* target, int group, ParseEnv* env)
if (qn->lower == 1 && qn->upper == 1)
return 1;
- switch (NODE_TYPE(target)) {
- case NODE_STRING:
+ switch (ND_TYPE(target)) {
+ case ND_STRING:
if (group == 0) {
if (str_node_can_be_split(target, env->enc)) {
Node* n = str_node_split_last_char(target, env->enc);
if (IS_NOT_NULL(n)) {
- NODE_BODY(qnode) = n;
+ ND_BODY(qnode) = n;
return 2;
}
}
}
break;
- case NODE_QUANT:
+ case ND_QUANT:
{ /* check redundant double repeat. */
/* verbose warn (?:.?)? etc... but not warn (.?)? etc... */
QuantNode* qnt = QUANT_(target);
@@ -8471,7 +8551,7 @@ assign_quantifier_body(Node* qnode, Node* target, int group, ParseEnv* env)
else {
int r;
- NODE_BODY(qnode) = target;
+ ND_BODY(qnode) = target;
r = onig_reduce_nested_quantifier(qnode);
return r;
}
@@ -8482,7 +8562,7 @@ assign_quantifier_body(Node* qnode, Node* target, int group, ParseEnv* env)
break;
}
- NODE_BODY(qnode) = target;
+ ND_BODY(qnode) = target;
return 0;
}
@@ -8628,14 +8708,14 @@ i_apply_case_fold(OnigCodePoint from, OnigCodePoint to[], int to_len,
}
else {
len = ONIGENC_CODE_TO_MBC(enc, to[i], buf);
- if (n == 0 || NODE_TYPE(ns[n-1]) != NODE_STRING) {
+ if (n == 0 || ND_TYPE(ns[n-1]) != ND_STRING) {
csnode = node_new_str(buf, buf + len);
if (IS_NULL(csnode)) goto err_free_ns;
if (index == 0)
- NODE_STATUS_ADD(csnode, IGNORECASE);
+ ND_STATUS_ADD(csnode, IGNORECASE);
else
- NODE_STRING_SET_CASE_EXPANDED(csnode);
+ ND_STRING_SET_CASE_EXPANDED(csnode);
ns[n++] = csnode;
}
@@ -8656,7 +8736,7 @@ i_apply_case_fold(OnigCodePoint from, OnigCodePoint to[], int to_len,
onig_node_free(list_node);
return ONIGERR_MEMORY;
}
- iarg->ptail = &(NODE_CDR((*(iarg->ptail))));
+ iarg->ptail = &(ND_CDR((*(iarg->ptail))));
}
}
@@ -8726,7 +8806,7 @@ prs_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
onig_node_free(target);
return r;
}
- NODE_BODY(*np) = target;
+ ND_BODY(*np) = target;
}
return tok->type;
}
@@ -8790,7 +8870,7 @@ prs_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
if (! ONIGENC_IS_VALID_MBC_STRING(env->enc, STR_(*np)->s, STR_(*np)->end))
return ONIGERR_INVALID_WIDE_CHAR_VALUE;
- NODE_STRING_CLEAR_CRUDE(*np);
+ ND_STRING_CLEAR_CRUDE(*np);
goto string_end;
}
break;
@@ -8883,7 +8963,7 @@ prs_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
iarg.alt_root = NULL_NODE;
iarg.ptail = &(iarg.alt_root);
- r = ONIGENC_APPLY_ALL_CASE_FOLD(env->enc, env->case_fold_flag,
+ r = ONIGENC_APPLY_ALL_CASE_FOLD(env->enc, env->reg->case_fold_flag,
i_apply_case_fold, &iarg);
if (r != 0) {
onig_node_free(iarg.alt_root);
@@ -8911,7 +8991,7 @@ prs_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
CHECK_NULL_RETURN_MEMERR(*np);
qn = node_new_quantifier(0, INFINITE_REPEAT, FALSE);
CHECK_NULL_RETURN_MEMERR(qn);
- NODE_BODY(qn) = *np;
+ ND_BODY(qn) = *np;
*np = qn;
break;
@@ -9035,7 +9115,7 @@ prs_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
onig_node_free(qn);
return ONIGERR_MEMORY;
}
- NODE_BODY(en) = qn;
+ ND_BODY(en) = qn;
qn = en;
}
@@ -9054,12 +9134,12 @@ prs_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
onig_node_free(qn);
return ONIGERR_MEMORY;
}
- tmp = NODE_CDR(*tp) = node_new_list(qn, NULL);
+ tmp = ND_CDR(*tp) = node_new_list(qn, NULL);
if (IS_NULL(tmp)) {
onig_node_free(qn);
return ONIGERR_MEMORY;
}
- tp = &(NODE_CAR(tmp));
+ tp = &(ND_CAR(tmp));
}
group = 0;
goto re_entry;
@@ -9096,7 +9176,7 @@ prs_branch(Node** top, PToken* tok, int term, UChar** src, UChar* end,
return ONIGERR_MEMORY;
}
- headp = &(NODE_CDR(*top));
+ headp = &(ND_CDR(*top));
while (r != TK_EOT && r != term && r != TK_ALT) {
r = prs_exp(&node, tok, term, src, end, env, FALSE);
if (r < 0) {
@@ -9104,15 +9184,15 @@ prs_branch(Node** top, PToken* tok, int term, UChar** src, UChar* end,
return r;
}
- if (NODE_TYPE(node) == NODE_LIST) {
+ if (ND_TYPE(node) == ND_LIST) {
*headp = node;
- while (IS_NOT_NULL(NODE_CDR(node))) node = NODE_CDR(node);
- headp = &(NODE_CDR(node));
+ while (IS_NOT_NULL(ND_CDR(node))) node = ND_CDR(node);
+ headp = &(ND_CDR(node));
}
else {
*headp = node_new_list(node, NULL);
if (IS_NULL(*headp)) goto mem_err;
- headp = &(NODE_CDR(*headp));
+ headp = &(ND_CDR(*headp));
}
}
}
@@ -9150,7 +9230,7 @@ prs_alts(Node** top, PToken* tok, int term, UChar** src, UChar* end,
return ONIGERR_MEMORY;
}
- headp = &(NODE_CDR(*top));
+ headp = &(ND_CDR(*top));
while (r == TK_ALT) {
r = fetch_token(tok, src, end, env);
if (r < 0) return r;
@@ -9163,10 +9243,11 @@ prs_alts(Node** top, PToken* tok, int term, UChar** src, UChar* end,
if (IS_NULL(*headp)) {
onig_node_free(node);
onig_node_free(*top);
+ *top = NULL_NODE;
return ONIGERR_MEMORY;
}
- headp = &(NODE_CDR(*headp));
+ headp = &(ND_CDR(*headp));
}
if (tok->type != (enum TokenSyms )term)
@@ -9210,7 +9291,7 @@ make_call_zero_body(Node* node, ParseEnv* env, Node** rnode)
Node* x = node_new_memory(0 /* 0: is not named */);
CHECK_NULL_RETURN_MEMERR(x);
- NODE_BODY(x) = node;
+ ND_BODY(x) = node;
BAG_(x)->m.regnum = 0;
r = scan_env_set_mem_node(env, 0, x);
if (r != 0) {