From bfcb8e7cf94529ab626d6d4ee544c6afeaff6ee5 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 12 Sep 2024 13:00:23 +0100 Subject: reader: Refactor type normalization into separate function. * ravanan/reader.scm (normalize-formals): Refactor type normalization into ... [normalize-type]: ... new function. --- ravanan/reader.scm | 28 +++++++++++++++------------- 1 file 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"))) -- cgit v1.2.3