hholzgra                Mon Nov 12 23:47:49 2001 EDT

  Modified files:              (Branch: dev_docbook4)
    /phpdoc     html-common.dsl common.dsl.in print.dsl.in 
  Log:
  new optional parameter rendering for docbook 4 methodsynopsis
  
  
  
Index: phpdoc/html-common.dsl
diff -u phpdoc/html-common.dsl:1.17.2.1 phpdoc/html-common.dsl:1.17.2.2
--- phpdoc/html-common.dsl:1.17.2.1     Sun Nov 11 18:54:51 2001
+++ phpdoc/html-common.dsl      Mon Nov 12 23:47:49 2001
@@ -1,6 +1,6 @@
 ;; -*- Scheme -*-
 ;;
-;; $Id: html-common.dsl,v 1.17.2.1 2001/11/11 23:54:51 hholzgra Exp $
+;; $Id: html-common.dsl,v 1.17.2.2 2001/11/13 04:47:49 hholzgra Exp $
 ;;
 
 ;; Returns the depth of the auto-generated TOC (table of
@@ -21,130 +21,6 @@
   )
 
 
-(define (is-true-optional nl)
-  (and (equal? (gi (parent nl)) (normalize "parameter"))
-       (equal? 0 (string-length (strip (data (preced nl)))))
-       (equal? 0 (string-length (strip (data (follow nl)))))
-       )
-  )
-
-
-(define (has-true-optional nl)
-  (is-true-optional 
-   (node-list-first-element 
-    (select-elements 
-     (descendants nl) 
-     (normalize "optional"))
-    )
-   )
-  )
-
-
-(define (count-true-optionals nl)
-  (let loop 
-      ((result 0)
-       (nl (select-elements (descendants nl) (normalize "optional")))
-       )
-    (if(node-list-empty? nl)
-       result
-       (if(is-true-optional(node-list-first nl))
-          (loop (+ result 1) (node-list-rest nl))
-          (loop result (node-list-rest nl))
-          )
-       )
-    )
-  )
-
-
-;; There are two different kinds of optionals
-;; optional parameters and optional parameter parts.
-;; An optional parameter is identified by an optional tag
-;; with a parameter tag as its parent 
-;; and only whitespace between them
-(element optional 
-  ;;check for true optional parameter
-  (if (is-true-optional (current-node))
-      ;; yes - handle '[...]' in paramdef
-      (process-children-trim) 
-      ;; no - do '[...]' output
-      (make sequence
-        (literal %arg-choice-opt-open-str%)
-        (process-children-trim)
-        (literal %arg-choice-opt-close-str%)
-        )
-      )
-  )                
-
-;; Print out parameters in italic
-(element (paramdef parameter)
-  (make sequence
-    font-posture: 'italic                                                       
-    (process-children-trim)
-    )
-  )                                                       
-
-;; Now this is going to be tricky
-(element paramdef  
-  (make sequence
-    ;; special treatment for first parameter in funcsynopsis
-    (if (equal? (child-number (current-node)) 1)
-        ;; is first ?
-        (make sequence
-          ;; start parameter list
-          (literal " (") 
-          ;; is optional ?
-          ( if (has-true-optional (current-node))
-               (literal %arg-choice-opt-open-str%)
-               (empty-sosofo)
-               )
-          )
-        ;; not first
-        (empty-sosofo)
-        )
-    
-    ;;
-    (process-children-trim)
-    
-    ;; special treatment for last parameter 
-    (if (equal? (gi (ifollow (current-node))) (normalize "paramdef"))                 
                       
-        ;; more parameters will follow
-        (make sequence
-          ;; next is optional ?
-          ( if (has-true-optional (ifollow (current-node)))
-               ;; optional
-               (make sequence
-                 (literal " ")
-                 (literal %arg-choice-opt-open-str%)
-                 )
-               ;; not optional
-               (empty-sosofo)
-               )
-          (literal ", " ) 
-          )
-        ;; last parameter
-        (make sequence
-          (literal 
-           (let loop ((result "")(count (count-true-optionals (parent 
(current-node)))))
-             (if (<= count 0)
-                 result
-                 (loop (string-append result %arg-choice-opt-close-str%)(- count 1))
-                 )
-             )
-           )
-          ( literal ")" )
-          )
-        )
-    )
-  )
-
-
-;; How to print out void in a funcprototype
-(element (funcprototype void)
- (make sequence ( literal " (void)" )))
-
-;; How to print out varargs in a funcprototype
-(element (funcprototype varargs)
- (make sequence ( literal " (...)" )))
 
 
 ;; Linking types to the correct place
@@ -390,57 +266,6 @@
   (para-check 'restart)))))
 
 
-
-(element methodsynopsis 
-       (make sequence (process-children) (literal ")"))
-)
-
-(element (methodsynopsis type)
-       (make sequence 
-               (process-children-trim)
-               (literal " ")
-               )
-)
-
-(element (methodsynopsis methodname)
-       (make sequence
-               ($bold-seq$
-                (process-children-trim)
-                )
-               (literal " (")
-               )
-       )
-
-(element (methodsynopsis methodparam)
-       (make sequence 
-               (if  (equal? (attribute-string (normalize "choice")) "opt")
-                                (literal "[")
-                                (empty-sosofo)
-                                )
-               (process-children-trim)
-               (if  (equal? (attribute-string (normalize "choice")) "opt")
-                                (literal "]")
-                                (empty-sosofo)
-                                )
-    (if (equal? (gi (ifollow (current-node))) (normalize "methodparam"))    
-                               (literal ", ")
-        (empty-sosofo)
-                               )
-               )
-       )
-
-(element (methodparam type)
-       (make sequence 
-               (process-children-trim)
-               (literal " ")
-               )
-       )
-
-(element (methodparam parameter)
-       (make sequence
-               (process-children-trim)
-               )
-       )
 
 
 ;; vim: ts=2 sw=2 et
Index: phpdoc/common.dsl.in
diff -u phpdoc/common.dsl.in:1.16 phpdoc/common.dsl.in:1.16.2.1
--- phpdoc/common.dsl.in:1.16   Tue Oct 30 08:33:10 2001
+++ phpdoc/common.dsl.in        Mon Nov 12 23:47:49 2001
@@ -1,6 +1,6 @@
 ;; -*- Scheme -*-
 ;;
-;; $Id: common.dsl.in,v 1.16 2001/10/30 13:33:10 leszek Exp $
+;; $Id: common.dsl.in,v 1.16.2.1 2001/11/13 04:47:49 hholzgra Exp $
 ;;
 ;; This file contains stylesheet customization common to the HTML
 ;; and print versions.
@@ -114,4 +114,107 @@
        (normalize "copyright")
        (normalize "abstract")
        (normalize "legalnotice")))
+
+
+
+
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;
+;;;; render function prototypes, esp. with optional arguments
+;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; helper function generating closing optional brackets
+(define (methodsynopsis-generate-closing-optionals nl)
+  (if (node-list-empty? nl)
+      (empty-sosofo) ;; empty list -> do nothing
+      (make sequence ;; process list node
+        (if (attribute-string (normalize "choice") (node-list-first nl))
+            (if (string=? "opt" (attribute-string (normalize "choice") 
+(node-list-first nl)))
+                (literal %arg-choice-opt-close-str%) ;; is optional parameter -> 
+close a bracket
+                (empty-sosofo)
+                )         
+            (empty-sosofo)
+            )         
+        (methodsynopsis-generate-closing-optionals (node-list-rest nl)) ;; process 
+rest of list
+        )
+      )
+  )
+  
+;; render methodsynopsis
+(element methodsynopsis 
+       (make sequence 
+    (process-children) ;; render content
+    (methodsynopsis-generate-closing-optionals (children (current-node))) ;; close 
+optional brackets
+    (literal ")") ;; close parameter list
+    )
+)
+
+;; render return type
+(element (methodsynopsis type)
+       (make sequence 
+               (process-children-trim)
+               (literal " ")
+               )
+)
+
+;; render function name
+(element (methodsynopsis methodname)
+       (make sequence
+               ($bold-seq$
+                (process-children-trim)
+                )
+               (literal " ( ") ;; start parameter list
+               )
+       )
+
+;; render parameters
+(element (methodsynopsis methodparam)
+       (make sequence 
+    ;; special case -> first parameter is optional
+    (if (equal? (gi (ipreced (current-node))) (normalize "methodparam"))
+        (empty-sosofo) ;; have prev. parameters -> is not first
+        (if  (equal? (attribute-string (normalize "choice")) "opt")
+             (literal %arg-choice-opt-open-str%) ;; generate opening bracket
+             (empty-sosofo) 
+             )
+        )
+
+               (process-children-trim)
+
+    ;; have more parameters following me?
+    (if (equal? (gi (ifollow (current-node))) (normalize "methodparam"))
+        (make sequence
+          ;; is next parameter optional?
+          (if  (equal? (attribute-string (normalize "choice") (ifollow 
+(current-node))) "opt")
+               (make sequence 
+                 (literal " ")
+                 (literal %arg-choice-opt-open-str%)
+                 )
+               (empty-sosofo)
+               )
+          ;; parameter list separator
+          (literal ", ")
+          )
+        (empty-sosofo)
+        )
+    )
+  )
+  
+;; render parameter type
+(element (methodparam type)
+       (make sequence 
+               (process-children-trim)
+               (literal " ")
+               )
+       )
+
+;; render parameter name
+(element (methodparam parameter)
+       (make sequence
+               (process-children-trim)
+               )
+       )
 
Index: phpdoc/print.dsl.in
diff -u phpdoc/print.dsl.in:1.17 phpdoc/print.dsl.in:1.17.2.1
--- phpdoc/print.dsl.in:1.17    Sat Oct 13 14:51:17 2001
+++ phpdoc/print.dsl.in Mon Nov 12 23:47:49 2001
@@ -7,7 +7,7 @@
 
 <!--
 
-  $Id: print.dsl.in,v 1.17 2001/10/13 18:51:17 jimw Exp $
+  $Id: print.dsl.in,v 1.17.2.1 2001/11/13 04:47:49 hholzgra Exp $
 
   This file contains printout-specific stylesheet customization.
 
@@ -183,125 +183,13 @@
 
 
 
-;; there are two different kinds of optionals
-;; optional parameters and optional parameter parts
-;; an optional parameter is identified by an optional tag
-;; with a parameter tag as its parent 
-;; and only whitespace between them
-(define (is-true-optional nl)
-       (and (equal? (gi (parent nl)) (normalize "parameter"))
-                        (equal? 0 (string-length (strip (data (preced nl)))))
-                        (equal? 0 (string-length (strip (data (follow nl)))))
-                        )
-       )
-
-(define (has-true-optional nl)
-       (is-true-optional 
-        (node-list-first-element 
-               (select-elements 
-                (descendants nl) 
-                (normalize "optional"))
-               )
-        )
-       )
-
-
-(define (count-true-optionals nl)
-       (let loop 
-                       ((result 0)
-                        (nl (select-elements (descendants nl) (normalize "optional")))
-                        )
-               (if(node-list-empty? nl)
-                        result
-                        (if(is-true-optional(node-list-first nl))
-                                       (loop (+ result 1) (node-list-rest nl))
-                                       (loop result (node-list-rest nl))
-                               )
-                        )
-               )
-       )
-
-
-(element optional 
-       ;;check for true optional parameter
-    (if (is-true-optional (current-node))
-                               ;; yes - handle '[...]' in paramdef
-                               (process-children-trim) 
-                               ;; no - do '[...]' output
-                               (make sequence
-                                       (literal %arg-choice-opt-open-str%)
-                                       (process-children-trim)
-                                       (literal %arg-choice-opt-close-str%)
-                                       )
-                               )
-               )               
-
-(element (paramdef parameter)
+(element (metodparam parameter)
        (make sequence
     font-posture: 'italic                                                       
                (process-children-trim)
                )
        )                                                       
 
-;; now this is going to be tricky
-(element paramdef  
-  (make sequence
-               ;; special treatment for first parameter in funcsynopsis
-    (if (equal? (child-number (current-node)) 1)
-                               ;; is first ?
-                               (make sequence
-                                       ;; start parameter list
-                                       (literal " (") 
-                                       ;; is optional ?
-                                       ( if (has-true-optional (current-node))
-                                                        (literal 
%arg-choice-opt-open-str%)
-                                                        (empty-sosofo)
-                                                        )
-                                       )
-                               ;; not first
-                               (empty-sosofo)
-                               )
-
-               ;;
-    (process-children-trim)
-
-               ;; special treatment for last parameter 
-    (if (equal? (gi (ifollow (current-node))) (normalize "paramdef"))                 
                 
-                               ;; more parameters will follow
-                               (make sequence
-                                       ;; next is optional ?
-                                       ( if (has-true-optional (ifollow 
(current-node)))
-                                               ;; optional
-                                               (make sequence
-                                                       (literal " ")
-                                                       (literal 
%arg-choice-opt-open-str%)
-                                                       )
-                                               ;; not optional
-                                               (empty-sosofo)
-                                               )
-                                       (literal ", " )                                
                          
-                                       )
-                               ;; last parameter
-                               (make sequence
-                                       (literal 
-                                        (let loop ((result "")(count 
(count-true-optionals (parent (current-node)))))
-                                                (if (<= count 0)
-                                                                result
-                                                                (loop (string-append 
result %arg-choice-opt-close-str%)(- count 1))
-                                                                )
-                                                )
-                                        )
-                                        ( literal ")" )
-                                        )
-                                       )
-                               )
-               )
-
-(element (funcprototype void)
- (make sequence ( literal " ()" )))
- 
- (element (funcprototype varargs)
-   (make sequence ( literal " (...)" )))
    
 (element function
   (let* ((function-name (data (current-node)))


Reply via email to