From 68a122a2a54675a01f0f58356c99a118fc0f9b13 Mon Sep 17 00:00:00 2001 From: jottbee Date: Sat, 26 Feb 2005 07:24:30 +0000 Subject: [PATCH] support for rx with three submatches in common rules. --- SYNTAX | 38 ++++++++++++++++--------- common-rules.scm | 74 ++++++++++++++++++++++++++++++------------------ 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/SYNTAX b/SYNTAX index a293a75..f1e3ab8 100644 --- a/SYNTAX +++ b/SYNTAX @@ -59,29 +59,29 @@ MAKEFILE: ::= "once" | "file-once" - ::= '(' + - + - + + ::= '(' + + + + + + + + ')' ::= '(' + - + - + + + + + + + + ')' ::= '(' + - + - + + + + + + + ')' ::= '(' + - + - + + + + + + + ')' ::= '(' + - + - + + + + + + + ')' ::= "common-file" @@ -102,13 +102,25 @@ MAKEFILE: ::= "common-once" | "common-file-once" + ::= | | + ::= | + ::= '"' + + '%' + + '"' + ::= * + ::= * + ::= '(' + "rx" + '(' + + + {3} + ')' + ')' + + ::= + ::= '"' + + '%' + + '"' + ::= '(' + { | }* + ')' + ::= | ::= ::= '(' + + + ')' - ::= | + ::= ::= - ::= '(' + * + ')' + ::= '(' + * + ')' ::= | diff --git a/common-rules.scm b/common-rules.scm index 2b32d52..f554f1b 100644 --- a/common-rules.scm +++ b/common-rules.scm @@ -42,12 +42,20 @@ (suffix (list-ref maybe-target 2)) (target-name (string-append prefix match suffix)) (cooked-prereqs (map (lambda (prereq) - (replace-by-match prereq match)) + (if (string? prereq) + (replace-by-match prereq match) + prereq)) (common-rule-prereqs current))) (make-wants-build? (common-rule-wants-build? current)) - (wants-build? (apply make-wants-build? - (append (list target-name) - cooked-prereqs))) + (wants-build? + (lambda args + (bind-fluids-common target-name prefix match suffix + (lambda () + (apply + (apply make-wants-build? + (append (list target-name) + cooked-prereqs)) + args))))) (make-build-func (common-rule-build-func current)) (build-func (lambda args @@ -84,30 +92,40 @@ ;;; (is-matched-by? "%.tex" "bar.o") ---> #f ;;; (define (is-matched-by? target-descr target-name) - (let* ((submatches (map (lambda (match-no) - (match:substring - (regexp-search (rx (: (submatch (* any)) - (submatch "%") - (submatch (* any)))) - target-descr) - match-no)) - (list 1 2 3))) - (left (list-ref submatches 0)) - (middle (list-ref submatches 1)) - (right (list-ref submatches 2)) - (constructed-rx (if (string=? "%" middle) - (rx (: (submatch ,left) - (submatch (* any)) - (submatch ,right))) - (rx (: (submatch ,left) - (submatch ,middle) - (submatch ,right))))) - (maybe-match (regexp-search constructed-rx target-name))) - (if maybe-match - (map (lambda (match-no) - (match:substring maybe-match match-no)) - (list 1 2 3)) - #f))) + (let ((submatches (if (string? target-descr) + (get-submatches-percent target-descr) + #f))) + (if submatches + (let* ((left (list-ref submatches 0)) + (middle (list-ref submatches 1)) + (right (list-ref submatches 2)) + (constructed-rx (if (and (string? middle) (string=? "%" middle)) + (rx (: (submatch ,left) + (submatch (* any)) + (submatch ,right))) + (rx (: (submatch ,left) + (submatch ,middle) + (submatch ,right))))) + (maybe-match (regexp-search constructed-rx target-name))) + (if maybe-match + (map (lambda (match-no) + (match:substring maybe-match match-no)) + (list 1 2 3)) + #f)) + (let ((maybe-match (regexp-search target-descr target-name))) + (if maybe-match + (map (lambda (match-no) (match:substring maybe-match match-no)) + (list 1 2 3)) + #f))))) + +(define (get-submatches-percent target-descr) + (map (lambda (match-no) + (match:substring (regexp-search (rx (: (submatch (* any)) + (submatch "%") + (submatch (* any)))) + target-descr) + match-no)) + (list 1 2 3))) ;;; ;;; returns the string where the match is replaced with replacement