summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2024-09-12 13:00:23 +0100
committerArun Isaac2024-09-12 17:08:56 +0100
commitbfcb8e7cf94529ab626d6d4ee544c6afeaff6ee5 (patch)
tree502375097fc46aba4c960ff9d483ccf6cf118eb5
parenta7bdaa2b4814e7f77a08cec12b10fb0d4d58cab3 (diff)
downloadravanan-bfcb8e7cf94529ab626d6d4ee544c6afeaff6ee5.tar.gz
ravanan-bfcb8e7cf94529ab626d6d4ee544c6afeaff6ee5.tar.lz
ravanan-bfcb8e7cf94529ab626d6d4ee544c6afeaff6ee5.zip
reader: Refactor type normalization into separate function.
* ravanan/reader.scm (normalize-formals): Refactor type normalization
into ...
[normalize-type]: ... new function.
-rw-r--r--ravanan/reader.scm28
1 files changed, 15 insertions, 13 deletions
diff --git a/ravanan/reader.scm b/ravanan/reader.scm
index 1e3505c..afcf552 100644
--- a/ravanan/reader.scm
+++ b/ravanan/reader.scm
@@ -76,22 +76,24 @@ each association list of the returned vector of association lists. If
                    alist)))
 
 (define (normalize-formals parameters)
+  (define (normalize-type type)
+    (cond
+     ((not (string? type)) type)
+     ((string-suffix? "?" type)
+      (vector (substring type 0 (- (string-length type)
+                                   (string-length "?")))
+              'null))
+     ((string-suffix? "[]" type)
+      `(("type" . "array")
+        ("items" . ,(substring type 0 (- (string-length type)
+                                         (string-length "[]"))))))
+     (else type)))
+
   (vector-map (lambda (parameter)
                 ;; Normalize optional and array types.
                 (assoc-set parameter
-                           (cons "type"
-                                 (let ((type (assoc-ref parameter "type")))
-                                   (cond
-                                    ((not (string? type)) type)
-                                    ((string-suffix? "?" type)
-                                     (vector (substring type 0 (- (string-length type)
-                                                                  (string-length "?")))
-                                             'null))
-                                    ((string-suffix? "[]" type)
-                                     `(("type" . "array")
-                                       ("items" . ,(substring type 0 (- (string-length type)
-                                                                        (string-length "[]"))))))
-                                    (else type))))))
+                  (cons "type"
+                        (normalize-type (assoc-ref parameter "type")))))
               ;; Normalize formals to a vector.
               (coerce-alist->vector parameters "id" "type")))