From e9f9fd4e5d780e6b2927add95618989966b3cc0f Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Wed, 12 Jul 2017 14:05:38 +0900 Subject: [PATCH] reimplement node_new_keep() --- src/regcomp.c | 3 +++ src/regparse.c | 26 +++++++++----------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index 1f53511..57985a5 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -7229,6 +7229,9 @@ print_indent_tree(FILE* f, Node* node, int indent) case GIMMICK_KEEP: fprintf(f, "keep:%d", GIMMICK_(node)->id); break; + case GIMMICK_SAVE: + fprintf(f, "save:%d:%d", GIMMICK_(node)->detail_type, GIMMICK_(node)->id); + break; } break; diff --git a/src/regparse.c b/src/regparse.c index f92f425..1ac0a5f 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -1509,13 +1509,12 @@ node_new_fail(Node** node, ScanEnv* env) */ static int -node_new_keep(Node** node, ScanEnv* env) +node_new_save_gimmick(Node** node, enum SaveType save_type, ScanEnv* env) { int id; int r; - *node = 0; - r = save_entry(env, SAVE_KEEP, &id); + r = save_entry(env, save_type, &id); if (r != ONIG_NORMAL) return r; *node = node_new(); @@ -1523,28 +1522,21 @@ node_new_keep(Node** node, ScanEnv* env) NODE_SET_TYPE(*node, NODE_GIMMICK); GIMMICK_(*node)->id = id; - GIMMICK_(*node)->type = GIMMICK_KEEP; - env->keep_num++; + GIMMICK_(*node)->type = GIMMICK_SAVE; + GIMMICK_(*node)->detail_type = (int )save_type; + return ONIG_NORMAL; } static int -node_new_save_gimmick(Node** node, ScanEnv* env) +node_new_keep(Node** node, ScanEnv* env) { - int id; int r; - r = save_entry(env, SAVE_RIGHT_RANGE, &id); - if (r != ONIG_NORMAL) return r; - - *node = node_new(); - CHECK_NULL_RETURN_MEMERR(*node); - - NODE_SET_TYPE(*node, NODE_GIMMICK); - GIMMICK_(*node)->id = id; - GIMMICK_(*node)->type = GIMMICK_SAVE; - GIMMICK_(*node)->detail_type = SAVE_RIGHT_RANGE; + r = node_new_save_gimmick(node, SAVE_KEEP, env); + if (r != 0) return r; + env->keep_num++; return ONIG_NORMAL; } -- 2.40.0