From 4a08e57d3f8e7b31c4646c225362d386e03f684d Mon Sep 17 00:00:00 2001 From: w6vvn Date: Mon, 1 Sep 2025 20:41:22 -0700 Subject: [PATCH] reverse document and preformatted structures at end of parsing of each so that the document structure is in logical order --- gem300.rkt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gem300.rkt b/gem300.rkt index b39cbe9..a081006 100644 --- a/gem300.rkt +++ b/gem300.rkt @@ -26,7 +26,8 @@ (define (iter document lines state) ;; when there are no more lines, we have finished parsing. (if (empty? lines) - document + ;; consing inherently makes everything backwards + (reverse document) ;; otherwise, we have a state machine to traverse. (cond @@ -35,7 +36,13 @@ (or (empty? (cdr lines)) (string-prefix? (car lines) "```"))) - (iter document + ;; also hard to follow. at this point: + ;; 1. the car of the document is necessarily a preformatted block + ;; and the contents of that block are backwards + ;; 2. take those contents, reverse them, append them to the + ;; cdr of the document + (iter (cons (preformatted (reverse (preformatted-str (car document)))) + document) (cdr lines) 'normal)]