303
#ifdef USE_ST_HASH_TABLE
303
#ifdef USE_ST_LIBRARY
308
308
unsigned char* s;
309
309
unsigned char* end;
312
static int strend_cmp(st_strend_key*, st_strend_key*);
313
static int strend_hash(st_strend_key*);
315
static struct st_hash_type type_strend_hash = {
313
str_end_cmp(st_strend_key* x, st_strend_key* y)
315
unsigned char *p, *q;
318
if ((x->end - x->s) != (y->end - y->s))
324
c = (int )*p - (int )*q;
325
if (c != 0) return c;
334
str_end_hash(st_strend_key* x)
341
val = val * 997 + (int )*p++;
344
return val + (val >> 5);
320
347
extern hash_table_type*
321
348
onig_st_init_strend_table_with_size(int size)
323
return (hash_table_type* )onig_st_init_table_with_size(&type_strend_hash,
350
static struct st_hash_type hashType = {
355
return (hash_table_type* )
356
onig_st_init_table_with_size(&hashType, size);
712
709
e = name_find(reg, name, name_end);
713
710
if (IS_NULL(e)) {
714
#ifdef USE_ST_HASH_TABLE
711
#ifdef USE_ST_LIBRARY
715
712
if (IS_NULL(t)) {
716
713
t = onig_st_init_strend_table_with_size(5);
717
714
reg->name_table = (void* )t;
719
716
e = (NameEntry* )xmalloc(sizeof(NameEntry));
720
CHECK_NULL_RETURN_VAL(e, ONIGERR_MEMORY);
717
CHECK_NULL_RETURN_MEMERR(e);
722
719
e->name = strdup_with_null(reg->enc, name, name_end);
723
720
if (IS_NULL(e->name)) return ONIGERR_MEMORY;
990
987
if (IS_NULL(node)) return ;
992
989
switch (NTYPE(node)) {
994
if (NSTRING(node).capa != 0 &&
995
IS_NOT_NULL(NSTRING(node).s) && NSTRING(node).s != NSTRING(node).buf) {
996
xfree(NSTRING(node).s);
991
if (NSTR(node)->capa != 0 &&
992
IS_NOT_NULL(NSTR(node)->s) && NSTR(node)->s != NSTR(node)->buf) {
993
xfree(NSTR(node)->s);
1002
onig_node_free(NCONS(node).left);
1003
/* onig_node_free(NCONS(node).right); */
999
onig_node_free(NCAR(node));
1005
Node* next_node = NCONS(node).right;
1001
Node* next_node = NCDR(node);
1007
#ifdef USE_RECYCLE_NODE
1003
#ifdef USE_PARSE_TREE_NODE_RECYCLE
1009
1005
FreeNode* n = (FreeNode* )node;
1026
CClassNode* cc = &(NCCLASS(node));
1022
CClassNode* cc = NCCLASS(node);
1028
if (IS_CCLASS_SHARE(cc)) return ;
1024
if (IS_NCCLASS_SHARE(cc)) return ;
1030
1026
bbuf_free(cc->mbuf);
1035
if (NQUANTIFIER(node).target)
1036
onig_node_free(NQUANTIFIER(node).target);
1040
if (NEFFECT(node).target)
1041
onig_node_free(NEFFECT(node).target);
1045
if (IS_NOT_NULL(NBACKREF(node).back_dynamic))
1046
xfree(NBACKREF(node).back_dynamic);
1050
if (NANCHOR(node).target)
1051
onig_node_free(NANCHOR(node).target);
1031
if (NQTFR(node)->target)
1032
onig_node_free(NQTFR(node)->target);
1036
if (NENCLOSE(node)->target)
1037
onig_node_free(NENCLOSE(node)->target);
1041
if (IS_NOT_NULL(NBREF(node)->back_dynamic))
1042
xfree(NBREF(node)->back_dynamic);
1046
if (NANCHOR(node)->target)
1047
onig_node_free(NANCHOR(node)->target);
1055
#ifdef USE_RECYCLE_NODE
1051
#ifdef USE_PARSE_TREE_NODE_RECYCLE
1057
1053
FreeNode* n = (FreeNode* )node;
1264
1265
Node* node = node_new();
1266
1267
CHECK_NULL_RETURN(node);
1267
node->type = N_BACKREF;
1268
NBACKREF(node).state = 0;
1269
NBACKREF(node).back_num = back_num;
1270
NBACKREF(node).back_dynamic = (int* )NULL;
1269
SET_NTYPE(node, NT_BREF);
1270
NBREF(node)->state = 0;
1271
NBREF(node)->back_num = back_num;
1272
NBREF(node)->back_dynamic = (int* )NULL;
1271
1273
if (by_name != 0)
1272
NBACKREF(node).state |= NST_NAME_REF;
1274
NBREF(node)->state |= NST_NAME_REF;
1274
1276
#ifdef USE_BACKREF_AT_LEVEL
1275
1277
if (exist_level != 0) {
1276
NBACKREF(node).state |= NST_NEST_LEVEL;
1277
NBACKREF(node).nest_level = nest_level;
1278
NBREF(node)->state |= NST_NEST_LEVEL;
1279
NBREF(node)->nest_level = nest_level;
1281
1283
for (i = 0; i < back_num; i++) {
1282
1284
if (backrefs[i] <= env->num_mem &&
1283
1285
IS_NULL(SCANENV_MEM_NODES(env)[backrefs[i]])) {
1284
NBACKREF(node).state |= NST_RECURSION; /* /...(\1).../ */
1286
NBREF(node)->state |= NST_RECURSION; /* /...(\1).../ */
1289
1291
if (back_num <= NODE_BACKREFS_SIZE) {
1290
1292
for (i = 0; i < back_num; i++)
1291
NBACKREF(node).back_static[i] = backrefs[i];
1293
NBREF(node)->back_static[i] = backrefs[i];
1294
1296
int* p = (int* )xmalloc(sizeof(int) * back_num);
1310
1312
Node* node = node_new();
1311
1313
CHECK_NULL_RETURN(node);
1313
node->type = N_CALL;
1314
NCALL(node).state = 0;
1315
NCALL(node).ref_num = CALLNODE_REFNUM_UNDEF;
1316
NCALL(node).target = NULL_NODE;
1317
NCALL(node).name = name;
1318
NCALL(node).name_end = name_end;
1315
SET_NTYPE(node, NT_CALL);
1316
NCALL(node)->state = 0;
1317
NCALL(node)->ref_num = CALLNODE_REFNUM_UNDEF;
1318
NCALL(node)->target = NULL_NODE;
1319
NCALL(node)->name = name;
1320
NCALL(node)->name_end = name_end;
1326
1328
Node* node = node_new();
1327
1329
CHECK_NULL_RETURN(node);
1328
node->type = N_QUANTIFIER;
1329
NQUANTIFIER(node).state = 0;
1330
NQUANTIFIER(node).target = NULL;
1331
NQUANTIFIER(node).lower = lower;
1332
NQUANTIFIER(node).upper = upper;
1333
NQUANTIFIER(node).greedy = 1;
1334
NQUANTIFIER(node).target_empty_info = NQ_TARGET_ISNOT_EMPTY;
1335
NQUANTIFIER(node).head_exact = NULL_NODE;
1336
NQUANTIFIER(node).next_head_exact = NULL_NODE;
1337
NQUANTIFIER(node).is_refered = 0;
1331
SET_NTYPE(node, NT_QTFR);
1332
NQTFR(node)->state = 0;
1333
NQTFR(node)->target = NULL;
1334
NQTFR(node)->lower = lower;
1335
NQTFR(node)->upper = upper;
1336
NQTFR(node)->greedy = 1;
1337
NQTFR(node)->target_empty_info = NQ_TARGET_ISNOT_EMPTY;
1338
NQTFR(node)->head_exact = NULL_NODE;
1339
NQTFR(node)->next_head_exact = NULL_NODE;
1340
NQTFR(node)->is_refered = 0;
1338
1341
if (by_number != 0)
1339
NQUANTIFIER(node).state |= NST_BY_NUMBER;
1342
NQTFR(node)->state |= NST_BY_NUMBER;
1341
1344
#ifdef USE_COMBINATION_EXPLOSION_CHECK
1342
NQUANTIFIER(node).comb_exp_check_num = 0;
1345
NQTFR(node)->comb_exp_check_num = 0;
1349
node_new_effect(int type)
1352
node_new_enclose(int type)
1351
1354
Node* node = node_new();
1352
1355
CHECK_NULL_RETURN(node);
1353
node->type = N_EFFECT;
1354
NEFFECT(node).type = type;
1355
NEFFECT(node).state = 0;
1356
NEFFECT(node).regnum = 0;
1357
NEFFECT(node).option = 0;
1358
NEFFECT(node).target = NULL;
1359
NEFFECT(node).call_addr = -1;
1360
NEFFECT(node).opt_count = 0;
1357
SET_NTYPE(node, NT_ENCLOSE);
1358
NENCLOSE(node)->type = type;
1359
NENCLOSE(node)->state = 0;
1360
NENCLOSE(node)->regnum = 0;
1361
NENCLOSE(node)->option = 0;
1362
NENCLOSE(node)->target = NULL;
1363
NENCLOSE(node)->call_addr = -1;
1364
NENCLOSE(node)->opt_count = 0;
1365
onig_node_new_effect(int type)
1369
onig_node_new_enclose(int type)
1367
return node_new_effect(type);
1371
return node_new_enclose(type);
1371
node_new_effect_memory(OnigOptionType option, int is_named)
1375
node_new_enclose_memory(OnigOptionType option, int is_named)
1373
Node* node = node_new_effect(EFFECT_MEMORY);
1377
Node* node = node_new_enclose(ENCLOSE_MEMORY);
1374
1378
CHECK_NULL_RETURN(node);
1375
1379
if (is_named != 0)
1376
SET_EFFECT_STATUS(node, NST_NAMED_GROUP);
1380
SET_ENCLOSE_STATUS(node, NST_NAMED_GROUP);
1378
1382
#ifdef USE_SUBEXP_CALL
1379
NEFFECT(node).option = option;
1383
NENCLOSE(node)->option = option;
1396
1400
int addlen = end - s;
1398
1402
if (addlen > 0) {
1399
int len = NSTRING(node).end - NSTRING(node).s;
1403
int len = NSTR(node)->end - NSTR(node)->s;
1401
if (NSTRING(node).capa > 0 || (len + addlen > NODE_STR_BUF_SIZE - 1)) {
1405
if (NSTR(node)->capa > 0 || (len + addlen > NODE_STR_BUF_SIZE - 1)) {
1403
1407
int capa = len + addlen + NODE_STR_MARGIN;
1405
if (capa <= NSTRING(node).capa) {
1406
onig_strcpy(NSTRING(node).s + len, s, end);
1409
if (capa <= NSTR(node)->capa) {
1410
onig_strcpy(NSTR(node)->s + len, s, end);
1409
if (NSTRING(node).s == NSTRING(node).buf)
1410
p = strcat_capa_from_static(NSTRING(node).s, NSTRING(node).end,
1413
if (NSTR(node)->s == NSTR(node)->buf)
1414
p = strcat_capa_from_static(NSTR(node)->s, NSTR(node)->end,
1413
p = strcat_capa(NSTRING(node).s, NSTRING(node).end, s, end, capa);
1417
p = strcat_capa(NSTR(node)->s, NSTR(node)->end, s, end, capa);
1415
CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);
1416
NSTRING(node).s = p;
1417
NSTRING(node).capa = capa;
1419
CHECK_NULL_RETURN_MEMERR(p);
1421
NSTR(node)->capa = capa;
1421
onig_strcpy(NSTRING(node).s + len, s, end);
1425
onig_strcpy(NSTR(node)->s + len, s, end);
1423
NSTRING(node).end = NSTRING(node).s + len + addlen;
1427
NSTR(node)->end = NSTR(node)->s + len + addlen;
1446
1450
onig_node_conv_to_str_node(Node* node, int flag)
1448
node->type = N_STRING;
1450
NSTRING(node).flag = flag;
1451
NSTRING(node).capa = 0;
1452
NSTRING(node).s = NSTRING(node).buf;
1453
NSTRING(node).end = NSTRING(node).buf;
1452
SET_NTYPE(node, NT_STR);
1453
NSTR(node)->flag = flag;
1454
NSTR(node)->capa = 0;
1455
NSTR(node)->s = NSTR(node)->buf;
1456
NSTR(node)->end = NSTR(node)->buf;
1457
1460
onig_node_str_clear(Node* node)
1459
if (NSTRING(node).capa != 0 &&
1460
IS_NOT_NULL(NSTRING(node).s) && NSTRING(node).s != NSTRING(node).buf) {
1461
xfree(NSTRING(node).s);
1462
if (NSTR(node)->capa != 0 &&
1463
IS_NOT_NULL(NSTR(node)->s) && NSTR(node)->s != NSTR(node)->buf) {
1464
xfree(NSTR(node)->s);
1464
NSTRING(node).capa = 0;
1465
NSTRING(node).flag = 0;
1466
NSTRING(node).s = NSTRING(node).buf;
1467
NSTRING(node).end = NSTRING(node).buf;
1467
NSTR(node)->capa = 0;
1468
NSTR(node)->flag = 0;
1469
NSTR(node)->s = NSTR(node)->buf;
1470
NSTR(node)->end = NSTR(node)->buf;
2120
2123
is_invalid_quantifier_target(Node* node)
2122
2125
switch (NTYPE(node)) {
2128
if (NEFFECT(node).type == EFFECT_OPTION)
2129
return is_invalid_quantifier_target(NEFFECT(node).target);
2131
/* allow enclosed elements */
2132
/* return is_invalid_quantifier_target(NENCLOSE(node)->target); */
2132
case N_LIST: /* ex. (?:\G\A)* */
2134
if (! is_invalid_quantifier_target(NCONS(node).left)) return 0;
2135
} while (IS_NOT_NULL(node = NCONS(node).right));
2137
if (! is_invalid_quantifier_target(NCAR(node))) return 0;
2138
} while (IS_NOT_NULL(node = NCDR(node)));
2139
case N_ALT: /* ex. (?:abc|\A)* */
2141
if (is_invalid_quantifier_target(NCONS(node).left)) return 1;
2142
} while (IS_NOT_NULL(node = NCONS(node).right));
2144
if (is_invalid_quantifier_target(NCAR(node))) return 1;
2145
} while (IS_NOT_NULL(node = NCDR(node)));
2197
2200
onig_reduce_nested_quantifier(Node* pnode, Node* cnode)
2199
2202
int pnum, cnum;
2200
QuantifierNode *p, *c;
2202
p = &(NQUANTIFIER(pnode));
2203
c = &(NQUANTIFIER(cnode));
2204
2207
pnum = popular_quantifier_num(p);
2205
2208
cnum = popular_quantifier_num(c);
2209
if (pnum < 0 || cnum < 0) return ;
2207
2211
switch(ReduceTypeTable[cnum][pnum]) {
2212
2216
p->target = c->target;
3887
3891
if (ctype < 0) return ctype;
3889
3893
*np = node_new_cclass();
3890
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
3891
cc = &(NCCLASS(*np));
3894
CHECK_NULL_RETURN_MEMERR(*np);
3892
3896
r = add_ctype_to_cc(cc, ctype, 0, env);
3893
3897
if (r != 0) return r;
3894
if (tok->u.prop.not != 0) CCLASS_SET_NOT(cc);
3898
if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc);
4359
4363
UChar** src, UChar* end, ScanEnv* env);
4362
parse_effect(Node** np, OnigToken* tok, int term, UChar** src, UChar* end,
4366
parse_enclose(Node** np, OnigToken* tok, int term, UChar** src, UChar* end,
4366
4370
int list_capture;
4441
4445
r = name_add(env->reg, name, name_end, num, env);
4442
4446
if (r != 0) return r;
4443
*np = node_new_effect_memory(env->option, 1);
4444
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
4445
NEFFECT(*np).regnum = num;
4447
*np = node_new_enclose_memory(env->option, 1);
4448
CHECK_NULL_RETURN_MEMERR(*np);
4449
NENCLOSE(*np)->regnum = num;
4446
4450
if (list_capture != 0)
4447
4451
BIT_STATUS_ON_AT_SIMPLE(env->capture_history, num);
4448
4452
env->num_named++;
4568
4572
if (ONIG_IS_OPTION_ON(env->option, ONIG_OPTION_DONT_CAPTURE_GROUP))
4571
*np = node_new_effect_memory(env->option, 0);
4572
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
4575
*np = node_new_enclose_memory(env->option, 0);
4576
CHECK_NULL_RETURN_MEMERR(*np);
4573
4577
num = scan_env_add_mem_entry(env);
4574
4578
if (num < 0) return num;
4575
NEFFECT(*np).regnum = num;
4579
NENCLOSE(*np)->regnum = num;
4578
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
4582
CHECK_NULL_RETURN_MEMERR(*np);
4579
4583
r = fetch_token(tok, &p, end, env);
4580
4584
if (r < 0) return r;
4581
4585
r = parse_subexp(&target, tok, term, &p, end, env);
4582
4586
if (r < 0) return r;
4584
if (NTYPE(*np) == N_ANCHOR)
4585
NANCHOR(*np).target = target;
4588
if (NTYPE(*np) == NT_ANCHOR)
4589
NANCHOR(*np)->target = target;
4587
NEFFECT(*np).target = target;
4588
if (NEFFECT(*np).type == EFFECT_MEMORY) {
4591
NENCLOSE(*np)->target = target;
4592
if (NENCLOSE(*np)->type == ENCLOSE_MEMORY) {
4589
4593
/* Don't move this to previous of parse_subexp() */
4590
r = scan_env_set_mem_node(env, NEFFECT(*np).regnum, *np);
4594
r = scan_env_set_mem_node(env, NENCLOSE(*np)->regnum, *np);
4591
4595
if (r != 0) return r;
4608
4612
set_quantifier(Node* qnode, Node* target, int group, ScanEnv* env)
4612
qn = &(NQUANTIFIER(qnode));
4613
4617
if (qn->lower == 1 && qn->upper == 1) {
4617
4621
switch (NTYPE(target)) {
4620
StrNode* sn = &(NSTRING(target));
4624
StrNode* sn = NSTR(target);
4621
4625
if (str_node_can_be_split(sn, env->enc)) {
4622
4626
Node* n = str_node_split_last_char(sn, env->enc);
4623
4627
if (IS_NOT_NULL(n)) {
4718
4722
static int type_cclass_hash(type_cclass_key* key)
4725
p = (unsigned char* )&(key->enc);
4729
p = (UChar* )&(key->enc);
4726
4730
for (i = 0; i < sizeof(key->enc); i++) {
4727
4731
val = val * 997 + (int )*p++;
4730
p = (unsigned char* )(&key->type);
4734
p = (UChar* )(&key->type);
4731
4735
for (i = 0; i < sizeof(key->type); i++) {
4732
4736
val = val * 997 + (int )*p++;
4795
4800
if (to_len == 1) {
4797
4802
in_cc = onig_is_code_in_cc(env->enc, from, cc);
4798
if ((in_cc != 0 && !IS_CCLASS_NOT(cc)) ||
4799
(in_cc == 0 && IS_CCLASS_NOT(cc))) {
4800
if (ONIGENC_MBC_MINLEN(env->enc) > 1 || from >= SINGLE_BYTE_SIZE) {
4803
if ((in_cc != 0 && !IS_NCCLASS_NOT(cc)) ||
4804
(in_cc == 0 && IS_NCCLASS_NOT(cc))) {
4805
if (ONIGENC_MBC_MINLEN(env->enc) > 1 || *to >= SINGLE_BYTE_SIZE) {
4806
if (IS_NCCLASS_NOT(cc)) clear_not_flag_cclass(cc, env->enc);
4801
4807
add_code_range(&(cc->mbuf), env, *to, *to);
4804
if (BITSET_AT(bs, from)) {
4805
/* /(?i:[^A-C])/.match("a") ==> fail. */
4810
/* /(?i:[^A-C])/.match("a") ==> fail. */
4811
if (IS_NCCLASS_NOT(cc))
4812
BITSET_CLEAR_BIT(bs, *to);
4806
4814
BITSET_SET_BIT(bs, *to);
4814
4821
Node *snode = NULL_NODE;
4816
4823
if (onig_is_code_in_cc(env->enc, from, cc)) {
4817
if (IS_CCLASS_NOT(cc)) clear_not_flag_cclass(cc, env->enc);
4824
if (IS_NCCLASS_NOT(cc)) clear_not_flag_cclass(cc, env->enc);
4819
4826
for (i = 0; i < to_len; i++) {
4820
4827
len = ONIGENC_CODE_TO_MBC(env->enc, to[i], buf);
4822
4829
snode = onig_node_new_str(buf, buf + len);
4823
CHECK_NULL_RETURN_VAL(snode, ONIGERR_MEMORY);
4830
CHECK_NULL_RETURN_MEMERR(snode);
4825
4832
/* char-class expanded multi-char only
4826
4833
compare with string folded at match time. */
4867
4874
case TK_SUBEXP_OPEN:
4868
r = parse_effect(np, tok, TK_SUBEXP_CLOSE, src, end, env);
4875
r = parse_enclose(np, tok, TK_SUBEXP_CLOSE, src, end, env);
4869
4876
if (r < 0) return r;
4870
4877
if (r == 1) group = 1;
4871
4878
else if (r == 2) { /* option only */
4873
4880
OnigOptionType prev = env->option;
4875
env->option = NEFFECT(*np).option;
4882
env->option = NENCLOSE(*np)->option;
4876
4883
r = fetch_token(tok, src, end, env);
4877
4884
if (r < 0) return r;
4878
4885
r = parse_subexp(&target, tok, term, src, end, env);
4879
4886
env->option = prev;
4880
4887
if (r < 0) return r;
4881
NEFFECT(*np).target = target;
4888
NENCLOSE(*np)->target = target;
4882
4889
return tok->type;
4918
4925
*np = node_new_str_raw_char((UChar )tok->u.c);
4919
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
4926
CHECK_NULL_RETURN_MEMERR(*np);
4922
4929
if (len >= ONIGENC_MBC_MINLEN(env->enc)) {
4923
if (len == enc_len(env->enc, NSTRING(*np).s)) {
4930
if (len == enc_len(env->enc, NSTR(*np)->s)) {
4924
4931
r = fetch_token(tok, src, end, env);
4925
4932
NSTRING_CLEAR_RAW(*np);
4926
4933
goto string_end;
4936
4943
if (len < ONIGENC_MBC_MINLEN(env->enc)) {
4937
4944
rem = ONIGENC_MBC_MINLEN(env->enc) - len;
4938
(void )node_str_head_pad(&NSTRING(*np), rem, (UChar )0);
4939
if (len + rem == enc_len(env->enc, NSTRING(*np).s)) {
4945
(void )node_str_head_pad(NSTR(*np), rem, (UChar )0);
4946
if (len + rem == enc_len(env->enc, NSTR(*np)->s)) {
4940
4947
NSTRING_CLEAR_RAW(*np);
4941
4948
goto string_end;
5053
5061
*np = node_new_cclass();
5054
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
5055
cc = &(NCCLASS(*np));
5062
CHECK_NULL_RETURN_MEMERR(*np);
5056
5064
add_ctype_to_cc(cc, tok->u.prop.ctype, 0, env);
5057
if (tok->u.prop.not != 0) CCLASS_SET_NOT(cc);
5065
if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc);
5058
5066
#ifdef USE_SHARED_CCLASS_TABLE
5080
5088
r = parse_char_class(np, tok, src, end, env);
5081
5089
if (r != 0) return r;
5083
cc = &(NCCLASS(*np));
5085
5092
if (IS_IGNORECASE(env->option)) {
5086
ICaseFoldArgType iarg;
5093
IApplyCaseFoldArg iarg;
5090
5097
iarg.alt_root = NULL_NODE;
5091
5098
iarg.ptail = &(iarg.alt_root);
5093
5100
r = ONIGENC_APPLY_ALL_CASE_FOLD(env->enc, env->case_fold_flag,
5094
i_case_fold, &iarg);
5101
i_apply_case_fold, &iarg);
5096
if (IS_NOT_NULL(iarg.alt_root))
5097
onig_node_free(iarg.alt_root);
5103
onig_node_free(iarg.alt_root);
5100
5106
if (IS_NOT_NULL(iarg.alt_root)) {
5112
5118
case TK_ANYCHAR:
5113
5119
*np = node_new_anychar();
5114
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
5120
CHECK_NULL_RETURN_MEMERR(*np);
5117
5123
case TK_ANYCHAR_ANYTIME:
5118
5124
*np = node_new_anychar();
5119
CHECK_NULL_RETURN_VAL(*np, ONIGERR_MEMORY);
5125
CHECK_NULL_RETURN_MEMERR(*np);
5120
5126
qn = node_new_quantifier(0, REPEAT_INFINITE, 0);
5121
CHECK_NULL_RETURN_VAL(qn, ONIGERR_MEMORY);
5122
NQUANTIFIER(qn).target = *np;
5127
CHECK_NULL_RETURN_MEMERR(qn);
5128
NQTFR(qn)->target = *np;
5179
5185
return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;
5181
5187
qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper,
5182
(r == TK_INTERVAL ? 1 : 0));
5183
CHECK_NULL_RETURN_VAL(qn, ONIGERR_MEMORY);
5184
NQUANTIFIER(qn).greedy = tok->u.repeat.greedy;
5188
(r == TK_INTERVAL ? 1 : 0));
5189
CHECK_NULL_RETURN_MEMERR(qn);
5190
NQTFR(qn)->greedy = tok->u.repeat.greedy;
5185
5191
r = set_quantifier(qn, *targetp, group, env);
5186
5192
if (r < 0) return r;
5188
5194
if (tok->u.repeat.possessive != 0) {
5190
en = node_new_effect(EFFECT_STOP_BACKTRACK);
5191
CHECK_NULL_RETURN_VAL(en, ONIGERR_MEMORY);
5192
NEFFECT(en).target = qn;
5196
en = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
5197
CHECK_NULL_RETURN_MEMERR(en);
5198
NENCLOSE(en)->target = qn;
5202
5208
*targetp = node_new_list(*targetp, NULL);
5203
CHECK_NULL_RETURN_VAL(*targetp, ONIGERR_MEMORY);
5204
tmp = NCONS(*targetp).right = node_new_list(qn, NULL);
5205
CHECK_NULL_RETURN_VAL(tmp, ONIGERR_MEMORY);
5206
targetp = &(NCONS(tmp).left);
5209
CHECK_NULL_RETURN_MEMERR(*targetp);
5210
tmp = NCDR(*targetp) = node_new_list(qn, NULL);
5211
CHECK_NULL_RETURN_MEMERR(tmp);
5212
targetp = &(NCAR(tmp));
5230
5236
*top = node_new_list(node, NULL);
5231
headp = &(NCONS(*top).right);
5237
headp = &(NCDR(*top));
5232
5238
while (r != TK_EOT && r != term && r != TK_ALT) {
5233
5239
r = parse_exp(&node, tok, term, src, end, env);
5234
5240
if (r < 0) return r;
5236
if (NTYPE(node) == N_LIST) {
5242
if (NTYPE(node) == NT_LIST) {
5238
while (IS_NOT_NULL(NCONS(node).right)) node = NCONS(node).right;
5239
headp = &(NCONS(node).right);
5244
while (IS_NOT_NULL(NCDR(node))) node = NCDR(node);
5245
headp = &(NCDR(node));
5242
5248
*headp = node_new_list(node, NULL);
5243
headp = &(NCONS(*headp).right);
5249
headp = &(NCDR(*headp));