APPROVE COMMIT 21.4
Thanks for the patch, Stephen. These changes will appear in XEmacs
21.4.17, "Jumbo Shrimp".
- Vin
"Stephen J. Turnbull" <stephen(a)xemacs.org> writes:
SUPERSEDES RECOMMEND 21.4
Grr. CVS and Mac OS X. The previous patch probably won't apply
because CVS 1.10 doesn't properly set up the file paths except in the
Index: line, which it ignores in favor of the --- line. Grr. Sorry,
caught it in one file but not in the rest.
Not needed in 21.5.
I found one error in my backport of Ben's revision of the shy group
support for 21.5. I don't know if this helps Andrey Slusar's issue;
I'm still trying to figure out exactly how all this stuff works.
Includes the (rather trivial) test that helped me find this bug.
Sorry, Andrey, but would you try applying this patch to see if it
fixes your bug? It's going to be some time before I can take a look
at your full report.
Index: src/ChangeLog
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/src/ChangeLog,v
retrieving revision 1.290.2.83
diff -u -r1.290.2.83 ChangeLog
--- src/ChangeLog 2005/01/11 02:02:11 1.290.2.83
+++ src/ChangeLog 2005/01/13 12:24:53
@@ -0,0 +1,7 @@
+2005-01-13 Stephen J. Turnbull <stephen(a)xemacs.org>
+
+ Fix backreference bug caught by test suite.
+
+ * regex.c (regex_compile):
+ Make backref duplicate internal register.
+
Index: src/regex.c
===================================================================
RCS file: /Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/src/regex.c,v
retrieving revision 1.25.2.10
diff -u -r1.25.2.10 regex.c
--- src/regex.c 2004/10/08 00:40:33 1.25.2.10
+++ src/regex.c 2005/01/13 12:22:03
@@ -3053,24 +3057,24 @@
case '6': case '7': case '8': case '9':
{
int reg;
+
if (syntax & RE_NO_BK_REFS)
goto normal_char;
+ /* External register indexing. */
reg = c - '0';
if (reg > bufp->re_nsub)
FREE_STACK_RETURN (REG_ESUBREG);
- {
- int regint = bufp->external_to_internal_register[reg];
- /* Can't back reference to a subexpression if inside it. */
- if (group_in_compile_stack (compile_stack, regint))
- {
- goto normal_char;
- }
- }
+ /* Convert external to internal as soon as possible. */
+ reg = bufp->external_to_internal_register[reg];
+ /* Can't back reference to a subexpression if inside it. */
+ if (group_in_compile_stack (compile_stack, reg))
+ goto normal_char;
+
laststart = buf_end;
BUF_PUSH_2 (duplicate, reg);
}
Index: tests/ChangeLog
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/tests/ChangeLog,v
retrieving revision 1.2.2.37
diff -u -r1.2.2.37 ChangeLog
--- tests/ChangeLog 2004/12/06 01:08:35 1.2.2.37
+++ tests/ChangeLog 2005/01/12 21:33:37
@@ -0,0 +1,5 @@
+2005-01-13 Stephen J. Turnbull <stephen(a)xemacs.org>
+
+ * automated/regexp-tests.el:
+ Test trivial subpatterns and backreferences with shy groups.
+
Index: tests/automated/regexp-tests.el
===================================================================
RCS file:
/Users/steve/Software/Repositories/cvs.xemacs.org/XEmacs/xemacs/tests/automated/regexp-tests.el,v
retrieving revision 1.2.2.8
diff -u -r1.2.2.8 regexp-tests.el
--- tests/automated/regexp-tests.el 2004/10/08 00:40:38 1.2.2.8
+++ tests/automated/regexp-tests.el 2005/01/12 21:33:03
@@ -414,3 +414,33 @@
(Assert (null (match-string 4 text))) ; nil
)
+;; trivial subpatterns and backreferences with shy groups
+(let ((text1 "abb")
+ (text2 "aba")
+ (re0 "\\(a\\)\\(b\\)\\2")
+ (re1 "\\(?:a\\)\\(b\\)\\2")
+ (re2 "\\(?:a\\)\\(b\\)\\1")
+ (re3 "\\(a\\)\\(?:b\\)\\1"))
+
+ (Assert (eq 0 (string-match re0 text1)))
+ (Assert (string= text1 (match-string 0 text1)))
+ (Assert (string= "a" (match-string 1 text1)))
+ (Assert (string= "b" (match-string 2 text1)))
+ (Assert (null (string-match re0 text2)))
+
+ (Check-Error-Message 'invalid-regexp "Invalid back reference"
+ (string-match re1 text1))
+
+ (Assert (eq 0 (string-match re2 text1)))
+ (Assert (string= text1 (match-string 0 text1)))
+ (Assert (string= "b" (match-string 1 text1)))
+ (Assert (null (match-string 2 text1)))
+ (Assert (null (string-match re2 text2)))
+
+ (Assert (null (string-match re3 text1)))
+ (Assert (eq 0 (string-match re3 text2)))
+ (Assert (string= text2 (match-string 0 text2)))
+ (Assert (string= "a" (match-string 1 text2)))
+ (Assert (null (match-string 2 text2)))
+)
+
--
Institute of Policy and Planning Sciences
http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Ask not how you can "do" free software business;
ask what your business can "do for" free software.