From: matz@... (Yukihiro Matsumoto) Date: 1997-12-18T10:44:47+09:00 Subject: [ruby-dev:1128] Re: Regexp#operators (Re: ruby 1.1b1 released) まつもと ゆきひろです In message "[ruby-dev:1109] Re: Regexp#operators (Re: ruby 1.1b1 released)" on 97/12/16, WATANABE Hirofumi writes: |rbc0> x = "barfoo" |"barfoo" |rbc0> x =~ /(?=.*foo).*bar/ |false | |うーむ. true にならない. (?=RE) がバグってますね. そうでした.以下にパッチをつけます. # 思ったよりずっと大変だった ^^;;; --- regex.c~ Thu Dec 11 13:44:03 1997 +++ regex.c Thu Dec 18 00:23:53 1997 @@ -599,3 +599,4 @@ case start_nowidth: - printf ("/start_nowidth"); + EXTRACT_NUMBER_AND_INCR (mcnt, p); + printf ("/start_nowidth//%d", mcnt); break; @@ -603,3 +604,4 @@ case stop_nowidth: - printf ("/stop_nowidth"); + printf ("/stop_nowidth//"); + p += 2; break; @@ -1335,3 +1337,3 @@ if (c == '#') break; - if (stackp+5 >= stacke) { + if (stackp+6 >= stacke) { int *stackx; @@ -1362,8 +1364,9 @@ case '=': - BUFPUSH(start_nowidth); - *stackp++ = 0; - break; - case '!': BUFPUSH(start_nowidth); + *stackp++ = b - bufp->buffer; + BUFPUSH(0); /* temporary value */ + BUFPUSH(0); + if (c == '=') break; + BUFPUSH(on_failure_jump); @@ -1398,2 +1401,3 @@ STORE_NUMBER(bufp->buffer+stackp[-1], b - bufp->buffer - stackp[-1] - 2); + stackp--; /* fall through */ @@ -1401,2 +1405,6 @@ BUFPUSH(stop_nowidth); + /* tell stack-pos place to start_nowidth */ + STORE_NUMBER(bufp->buffer+stackp[-1], b - bufp->buffer - stackp[-1] - 2); + BUFPUSH(0); /* space to hold stack pos */ + BUFPUSH(0); break; @@ -2052,4 +2060,2 @@ case wordend: - case start_nowidth: - case stop_nowidth: case pop_and_fail: @@ -2095,5 +2101,7 @@ + case start_nowidth: + case stop_nowidth: case finalize_push: p += 2; - break; + continue; @@ -2101,3 +2109,3 @@ p += 4; - break; + continue; @@ -2528,3 +2536,3 @@ *stackp++ = string_place; \ - *stackp++ = (unsigned char *)1; \ + *stackp++ = (unsigned char *)0; /* non-greedy flag */ \ } @@ -2894,11 +2902,16 @@ PUSH_FAILURE_POINT(0, d); - break; + EXTRACT_NUMBER_AND_INCR(mcnt, p); + STORE_NUMBER(p+mcnt, stackp - stackb); + continue; case stop_nowidth: + EXTRACT_NUMBER_AND_INCR(mcnt, p); + stackp = stackb + mcnt; d = stackp[-2]; POP_FAILURE_POINT(); - break; + continue; case pop_and_fail: - POP_FAILURE_POINT(); + EXTRACT_NUMBER(mcnt, p+1); + stackp = stackb + mcnt; POP_FAILURE_POINT(); @@ -3129,3 +3142,3 @@ PUSH_FAILURE_POINT(p, d); - stackp[1] = (unsigned char*)0; + stackp[-1] = (unsigned char*)1; } @@ -3138,3 +3151,3 @@ PUSH_FAILURE_POINT(p + mcnt, d); - stackp[-1] = (unsigned char*)0; + stackp[-1] = (unsigned char*)1; continue; @@ -3150,3 +3163,3 @@ PUSH_FAILURE_POINT(p + mcnt, d); - stackp[-1] = (unsigned char*)0; + stackp[-1] = (unsigned char*)1; p += 7; /* skip n and set_number_at after destination */ @@ -3253,3 +3266,3 @@ } - if (stackp != stackb && (int)stackp[-1] == 0) + if (stackp != stackb && (int)stackp[-1] == 1) POP_FAILURE_POINT();