Created
October 19, 2013 09:41
-
-
Save leque/7053723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/gauche/regexp.scm b/lib/gauche/regexp.scm | |
index 76cdb44..3ca5c1c 100644 | |
--- a/lib/gauche/regexp.scm | |
+++ b/lib/gauche/regexp.scm | |
@@ -190,7 +190,7 @@ | |
[(assert nassert) (apply unparse-assert-like test)] | |
[else (err "invalid AST in the test part of cpat" test)])) | |
(seq yes) | |
- (when no (disp "|") (seq no)) | |
+ (unless (null? no) (disp "|") (seq no)) | |
(disp ")")) | |
(define (unparse-assert-like op . asst) | |
diff --git a/src/regexp.c b/src/regexp.c | |
index e3d4670..7a621fd 100644 | |
--- a/src/regexp.c | |
+++ b/src/regexp.c | |
@@ -922,7 +922,7 @@ static ScmObj rc1_parse(regcomp_ctx *ctx, int bolp, ScmObj groups) | |
npat = SCM_CDDR(elt); | |
} else { | |
ypat = item; | |
- npat = SCM_FALSE; | |
+ npat = SCM_NIL; | |
} | |
PUSH(SCM_LIST4(SCM_SYM_CPAT, cond, ypat, npat)); | |
bolp = FALSE; | |
@@ -1693,8 +1693,7 @@ static void rc3_rec(regcomp_ctx *ctx, ScmObj ast, int lastp) | |
ocodep2 = ctx->codep; | |
rc3_emit_offset(ctx, 0); /* will be patched */ | |
rc3_fill_offset(ctx, ocodep1, ctx->codep); | |
- if (SCM_FALSEP(npat)) rc3_emit(ctx, RE_FAIL); | |
- else rc3_seq(ctx, npat, lastp); | |
+ rc3_seq(ctx, npat, lastp); | |
rc3_fill_offset(ctx, ocodep2, ctx->codep); | |
} else { | |
SCM_ASSERT(SCM_EQ(SCM_CAR(cond), SCM_SYM_ASSERT) | |
@@ -1712,8 +1711,7 @@ static void rc3_rec(regcomp_ctx *ctx, ScmObj ast, int lastp) | |
ocodep3 = ctx->codep; | |
rc3_emit_offset(ctx, 0); /* will be patched */ | |
rc3_fill_offset(ctx, ocodep2, ctx->codep); | |
- if (SCM_FALSEP(npat)) rc3_emit(ctx, RE_FAIL); | |
- else rc3_seq(ctx, npat, lastp); | |
+ rc3_seq(ctx, npat, lastp); | |
rc3_fill_offset(ctx, ocodep3, ctx->codep); | |
} | |
return; | |
diff --git a/test/regexp.scm b/test/regexp.scm | |
index 1b2c1c3..7757df5 100644 | |
--- a/test/regexp.scm | |
+++ b/test/regexp.scm | |
@@ -66,11 +66,11 @@ | |
(test-parse "(?<=ab)" '(0 #f (assert (lookbehind #\a #\b)))) | |
(test-parse "(?<!ab)" '(0 #f (nassert (lookbehind #\a #\b)))) | |
(test-parse "(?<name>a)" '(0 #f (1 name #\a))) | |
-(test-parse "(?(?=)y)" '(0 #f (cpat (assert) (#\y) #f))) | |
+(test-parse "(?(?=)y)" '(0 #f (cpat (assert) (#\y) ()))) | |
(test-parse "(?(?=)y|n)" '(0 #f (cpat (assert) (#\y) (#\n)))) | |
-(test-parse "(?(?<=)y)" '(0 #f (cpat (assert (lookbehind)) (#\y) #f))) | |
+(test-parse "(?(?<=)y)" '(0 #f (cpat (assert (lookbehind)) (#\y) ()))) | |
(test-parse "(?(?<=)y|n)" '(0 #f (cpat (assert (lookbehind)) (#\y) (#\n)))) | |
-(test-parse "()(?(1)y)" '(0 #f (1 #f) (cpat 1 (#\y) #f))) | |
+(test-parse "()(?(1)y)" '(0 #f (1 #f) (cpat 1 (#\y) ()))) | |
(test-parse "()(?(1)y|n)"'(0 #f (1 #f) (cpat 1 (#\y) (#\n)))) | |
(test-parse "()\\1" '(0 #f (1 #f) (backref . 1))) | |
(test-parse "(?<name>)\\k<name>" '(0 #f (1 name) (backref . 1))) | |
@@ -653,11 +653,11 @@ | |
(test-re #/(a)(?(1)b)/ "ac" '()) | |
(test-re #/(a)?(?(1)b|c)/ "xb" '()) | |
(test-re #/(a)?(?(1)b|c)/ "xc" '("c" #f)) | |
-(test-re #/(?(?<=a)b)/ "ab" '("b")) | |
-(test-re #/(?(?<=a)b)/ "ac" '()) | |
-(test-re #/(?(?<=a)b)/ "xb" '()) | |
-(test-re #/(?(?<=a)b)/ "ab" '("b")) | |
-(test-re #/(?(?<=a)b)/ "ac" '()) | |
+(test-re #/(<)?[^<>]+(?(1)>)/ "<foo>" '("<foo>" "<")) | |
+(test-re #/(<)?[^<>]+(?(1)>)/ "foo" '("foo" #f)) | |
+(test-re #/(?(?<=a)b)/ "ab" '("")) | |
+(test-re #/(?(?<=a)b)/ "ac" '("")) | |
+(test-re #/(?(?<=a)b)/ "xb" '("")) | |
(test-parse "(?(?a)b|c)" (test-error)) | |
(test-re #/()(?(1))/ "" '("" "")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment