support for rx with three submatches in common rules.

This commit is contained in:
jottbee 2005-02-26 07:24:30 +00:00
parent 9a25d38343
commit 68a122a2a5
2 changed files with 71 additions and 41 deletions

38
SYNTAX
View File

@ -59,29 +59,29 @@ MAKEFILE:
<once-clause-identifier> ::= "once" <once-clause-identifier> ::= "once"
| "file-once" | "file-once"
<common-file-clause> ::= '(' + <common-fille-clause-identifier> <common-file-clause> ::= '(' + <common-file-clause-identifier>
+ <target-spec> + <common-target-spec>
+ <prereq-spec> + <common-prereq-spec>
+ <action>+ + ')' + <action>+ + ')'
<common-all-clause> ::= '(' + <common-all-clause-identifier> <common-all-clause> ::= '(' + <common-all-clause-identifier>
+ <target-spec> + <common-target-spec>
+ <prereq-spec> + <common-prereq-spec>
+ <action>+ + ')' + <action>+ + ')'
<common-md5-clause> ::= '(' + <common-md5-clause-identifier> <common-md5-clause> ::= '(' + <common-md5-clause-identifier>
+ <target-spec> + <common-target-spec>
+ <prereq-spec> + <common-prereq-spec>
+ <action-spec> + ')' + <action-spec> + ')'
<common-always-clause> ::= '(' + <common-always-clause-identifier> <common-always-clause> ::= '(' + <common-always-clause-identifier>
+ <target-spec> + <common-target-spec>
+ <prereq-spec> + <common-prereq-spec>
+ <action-spec> + ')' + <action-spec> + ')'
<common-once-clause> ::= '(' + <common-once-clause-identifier> <common-once-clause> ::= '(' + <common-once-clause-identifier>
+ <target-spec> + <common-target-spec>
+ <prereq-spec> + <common-prereq-spec>
+ <action-spec> + ')' + <action-spec> + ')'
<common-file-clause-identifier> ::= "common-file" <common-file-clause-identifier> ::= "common-file"
@ -102,13 +102,25 @@ MAKEFILE:
<common-once-clause-identifier> ::= "common-once" <common-once-clause-identifier> ::= "common-once"
| "common-file-once" | "common-file-once"
<common-target-spec> ::= <target-descr> | <target> | <target-list>
<target-descr> ::= <target-pattern> | <target-rx>
<target-pattern> ::= '"' + <prefix> + '%' + <suffix> + '"'
<prefix> ::= <letter-or-digit>*
<suffix> ::= <letter-or-digit>*
<target-rx> ::= '(' + "rx" + '(' + <submatch-connector>
+ <submatch-clause>{3} + ')' + ')'
<common-prereq-spec> ::= <prereq-descr>
<prereq-pattern> ::= '"' + <prefix> + '%' + <suffix> + '"'
<prereq-descr> ::= '(' + { <prereq-pattern> | <prereq> }* + ')'
<target-spec> ::= <target> | <target-list> <target-spec> ::= <target> | <target-list>
<target> ::= <filename> <target> ::= <filename>
<target-list> ::= '(' + <filename>+ + ')' <target-list> ::= '(' + <filename>+ + ')'
<prereq-spec> ::= <prereq> | <prereq-list> <prereq-spec> ::= <prereq-list>
<prereq> ::= <filename> <prereq> ::= <filename>
<prereq-list> ::= '(' + <filename>* + ')' <prereq-list> ::= '(' + <prereq>* + ')'
<action> ::= <function-call> | <value> <action> ::= <function-call> | <value>

View File

@ -42,12 +42,20 @@
(suffix (list-ref maybe-target 2)) (suffix (list-ref maybe-target 2))
(target-name (string-append prefix match suffix)) (target-name (string-append prefix match suffix))
(cooked-prereqs (map (lambda (prereq) (cooked-prereqs (map (lambda (prereq)
(replace-by-match prereq match)) (if (string? prereq)
(replace-by-match prereq match)
prereq))
(common-rule-prereqs current))) (common-rule-prereqs current)))
(make-wants-build? (common-rule-wants-build? current)) (make-wants-build? (common-rule-wants-build? current))
(wants-build? (apply make-wants-build? (wants-build?
(lambda args
(bind-fluids-common target-name prefix match suffix
(lambda ()
(apply
(apply make-wants-build?
(append (list target-name) (append (list target-name)
cooked-prereqs))) cooked-prereqs))
args)))))
(make-build-func (common-rule-build-func current)) (make-build-func (common-rule-build-func current))
(build-func (build-func
(lambda args (lambda args
@ -84,18 +92,14 @@
;;; (is-matched-by? "%.tex" "bar.o") ---> #f ;;; (is-matched-by? "%.tex" "bar.o") ---> #f
;;; ;;;
(define (is-matched-by? target-descr target-name) (define (is-matched-by? target-descr target-name)
(let* ((submatches (map (lambda (match-no) (let ((submatches (if (string? target-descr)
(match:substring (get-submatches-percent target-descr)
(regexp-search (rx (: (submatch (* any)) #f)))
(submatch "%") (if submatches
(submatch (* any)))) (let* ((left (list-ref submatches 0))
target-descr)
match-no))
(list 1 2 3)))
(left (list-ref submatches 0))
(middle (list-ref submatches 1)) (middle (list-ref submatches 1))
(right (list-ref submatches 2)) (right (list-ref submatches 2))
(constructed-rx (if (string=? "%" middle) (constructed-rx (if (and (string? middle) (string=? "%" middle))
(rx (: (submatch ,left) (rx (: (submatch ,left)
(submatch (* any)) (submatch (* any))
(submatch ,right))) (submatch ,right)))
@ -107,7 +111,21 @@
(map (lambda (match-no) (map (lambda (match-no)
(match:substring maybe-match match-no)) (match:substring maybe-match match-no))
(list 1 2 3)) (list 1 2 3))
#f))) #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 ;;; returns the string where the match is replaced with replacement