From 1740e5fcf8a7f748b3ebdb4b0dd1002c035ddae5 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 3 May 2025 22:16:46 +0200 Subject: debug: use match --- cook/debug.sld | 44 ++++++++++++++++++++++---------------------- cook/parse-internals.sld | 12 +++++++++++- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cook/debug.sld b/cook/debug.sld index 638c13a..c35f8f9 100644 --- a/cook/debug.sld +++ b/cook/debug.sld @@ -4,31 +4,31 @@ (srfi 9) (srfi 69) (chibi) + (chibi match) (cook parse-internals)) (begin (define (cook->list y) - (cond - ((amount? y) - (list 'amount (amount-quantity y) (amount-unit y))) - ((comment? y) - (list 'comment (comment-text y))) - ((component? y) - (list 'component (component-name y) (cook->list (component-amount y)))) - ((cookware? y) - (list 'cookware (cookware-name y) (cook->list (cookware-amount y)))) - ((ingredient? y) - (list 'ingredient (ingredient-name y) (cook->list (ingredient-amount y)))) - ((timer? y) - (list 'timer (timer-name y) (cook->list (timer-amount y)))) - ((metadata-line? y) - (list 'metadata-line (metadata-line-key y) (metadata-line-value y))) - ((step? y) - (list 'step (map cook->list (step-elements y)))) - ((hash-table? y) + (match y + (($ quantity unit) + (list 'amount quantity unit)) + (($ text) + (list 'comment text)) + (($ name amount) + (list 'component name (cook->list amount))) + (($ name amount) + (list 'cookware name (cook->list amount))) + (($ name amount) + (list 'ingredient name (cook->list amount))) + (($ name amount) + (list 'timer name (cook->list amount))) + (($ key value) + (list 'metadata-line key value)) + (($ elements) + (list 'step (map cook->list elements ))) + ((? hash-table? y) (list 'metadata (cook->list (hash-table->alist y)))) - ((recipe? y) - (list 'recipe (cook->list (recipe-metadata y)) - (cook->list (recipe-body y)))) - ((list? y) + (($ metadata body) + (list 'recipe (cook->list metadata) (cook->list body))) + ((? list? y) (map cook->list y)) (else y))))) diff --git a/cook/parse-internals.sld b/cook/parse-internals.sld index d73a3c3..d2099e1 100644 --- a/cook/parse-internals.sld +++ b/cook/parse-internals.sld @@ -10,31 +10,41 @@ (chibi regexp) (chibi string) (cook unicode)) - (export amount? + (export + amount? amount-quantity amount-unit + ingredient? ingredient-name ingredient-amount + timer? timer-name timer-amount + component? component-name component-amount + cookware? cookware-name cookware-amount + metadata-line? metadata-line-key metadata-line-value + recipe? recipe-metadata recipe-body + step? step-elements + comment? comment-text + ;; Functions parse-cook nl whitespace -- cgit v1.2.3