ovidiu 02/01/31 17:41:18 Modified: src/scratchpad/schecoon/scheme sitemap.scm Log: Added support for named resources, which contain pipeline definitions. A named resource is translated to a Scheme function, which is invoked either dynamically if the name of the function is not known at sitemap compile time, or statically, if it is known. See sitemap.xmap for an example of how this can be specified. Revision Changes Path 1.8 +19 -15 xml-cocoon2/src/scratchpad/schecoon/scheme/sitemap.scm Index: sitemap.scm =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/schecoon/scheme/sitemap.scm,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- sitemap.scm 25 Jan 2002 22:59:29 -0000 1.7 +++ sitemap.scm 1 Feb 2002 01:41:18 -0000 1.8 @@ -118,10 +118,9 @@ ;; the original XML sitemap. ;; Converts a name to a resource. `name' is either a string or a -;; symbol. The return value is r_<name> and is of the same type as -;; `name'. +;; symbol. The return value is the symbol for r_<name>. (define (name->resource name) - (cond ((string? name) (string-append "r_" name)) + (cond ((string? name) (string->symbol (string-append "r_" name))) ((symbol? name) (name->resource (symbol->string name))) (else #f))) @@ -425,12 +424,19 @@ (sxml:attr node 'resource)) (let* ((args (get-attributes node '(resource) '() #t args-are-numbers?)) - (pipeline - ((sxpath '(resources (resource (@ (equal? (name )))))) - sitemap))) + (resource-name + (expand-value node (sxml:attr node 'resource) #t))) + ;; Optimization: if the resource name is statically known, + ;; there's no need to call resource-call-v to invoke the + ;; function representation of the resource. Instead we + ;; call the function directly. (match-pipeline-end (rest-of-nodes pipeline) - `(begin (display (format "calling ~s~%" ,@args)) (newline) (resource-call-v sitemap env ,@args) #t)) + (if (pair? resource-name) + `(resource-call-v sitemap env ,@args) + (let ((params (get-params (sxml:content node) #t))) + `(,(name->resource resource-name) sitemap env + (list ,@params))))) )) (else #f) ))) @@ -541,12 +547,11 @@ (if (not resname) (xml-error node "Resource must be named, use a 'name' attribute") (let* ((funname (name->resource resname)) - (funsymbol (string->symbol funname)) ;; Check to see if a similar resource has already ;; been defined. - (_ (if (lookup-resource funsymbol) + (_ (if (lookup-resource funname) (xml-error node "A resource named ~s already defined" - funsymbol))) + funname))) (attributes (map (lambda (x) (cadr x)) ((sxpath '(// @ (*))) node))) (source-arguments @@ -573,12 +578,14 @@ source-arguments))) (argument-symbols (map (lambda (x) (string->symbol x)) arguments)) - (funsig `(,funsymbol ,@argument-symbols)) + (funsig `(,funname ,@argument-symbols)) (funbody - `(function (,funsymbol sitemap env ,@argument-symbols) + `(function (,funname sitemap env ,@argument-symbols) ,(generate-function-body (reverse (sxml:child-elements node)) #f)))) (add-resource funsig funbody) + (pretty-print funbody) (newline) + (eval funbody (interaction-environment)) )))) ;; Process the SXML representation of the sitemap. This is done by @@ -610,9 +617,6 @@ '() (cons (caaar ms) (loop (cdr ms)))))) - ;; Generate the code for the resource function - ;; definitions - ,@(resources-get-function-bodies) ;; Generate the code corresponding to the ;; <map:match> definitions
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]