From 9b97c918e354e008a3583fcb96495e37c15494cc Mon Sep 17 00:00:00 2001 From: Nathan Trapuzzano Date: Tue, 25 Feb 2014 22:36:56 -0500 Subject: [PATCH] Create new bindings for the referenced register upon entry to subpattern-reference. When entering a register x via subpattern-reference, the registers local to x receive new dynamic bindings, which shadow the old bindings for the duration of the subpattern call. Previously, "local" did not include the register itself--x in this case. With this patch, the referenced register now receives a new binding as well. It's not entirely clear that this is the appropriate behavior. In a regex like "(.\1?)(?1)", the back-reference to '\1' now will always fail, rather than potentially matching according to what was matched in the first pass through the first register. --- closures.lisp | 4 ++-- test/simple | 16 ++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/closures.lisp b/closures.lisp index 4e3a67d..9e12c98 100644 --- a/closures.lisp +++ b/closures.lisp @@ -97,14 +97,14 @@ such that the call to NEXT-FN after the match would succeed.")) (labels ((pop-offsets (offsets offsets-stacks) (declare (simple-vector offsets offsets-stacks)) - (loop for idx from (1+ num) upto (+ num subregister-count) + (loop for idx from num upto (+ num subregister-count) collect (let () (declare (fixnum idx)) (setf (svref offsets idx) (pop (svref offsets-stacks idx)))))) (push-offsets (offsets saved-offsets offsets-stacks) (declare (simple-vector offsets offsets-stacks) (list saved-offsets)) - (loop for idx from (1+ num) upto (+ num subregister-count) do + (loop for idx from num upto (+ num subregister-count) do (let () (declare (fixnum idx)) (push (svref offsets idx) (svref offsets-stacks idx)) diff --git a/test/simple b/test/simple index 5242bfa..6035f4a 100644 --- a/test/simple +++ b/test/simple @@ -422,15 +422,11 @@ characters if there's a match." (scan regex "fffffff")) '(0 7 #(0 4 4 6) #(1 7 5 7)))) -(equalp (multiple-value-list - (scan "^(.\\1?)(?1)$" "aba")) - '(0 3 #(0) #(1))) +(null (scan "^(.\\1?)(?1)$" "aba")) (let ((*allow-named-registers* t) (regex "^(?.\\k?)(?®One)$")) - (equalp (multiple-value-list - (scan regex "aba")) - '(0 3 #(0) #(1)))) + (null (scan regex "aba"))) (equalp (multiple-value-list (scan "^(.\\2?)(.)(?1)$" "abcb")) @@ -454,13 +450,9 @@ characters if there's a match." ;; (scan regex "aaba")) ;; '(0 4 #(nil 0 0) #(nil 1 1)))) -(equalp (multiple-value-list - (scan "^(a|\\3(?1)\\2|(?2))((b|c)(?4)?)(?1)(d(?1))$" "abbcdcabbda")) - '(0 11 #(0 1 1 9) #(1 2 2 11))) +(null (scan "^(a|\\3(?1)\\2|(?2))((b|c)(?4)?)(?1)(d(?1))$" "abbcdcabbda")) ;; Cf. #17 ;; (let ((*allow-named-registers* t) ;; (regex "^(?a|\\k(?®One)\\k|(?®Two))(?(?b|c)(?®Four)?)(?®One)(?d(?®One))$")) -;; (equalp (multiple-value-list -;; (scan regex "abbcdcabbda")) -;; '(0 11 #(0 1 1 9) #(1 2 2 11)))) +;; (null (scan regex "abbcdcabbda")))