From 9ab8056f789afd7c0b8f500d873b9b535a2067fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 11 Jul 2022 22:29:42 +0200 Subject: Remove usage of zipper. --- module/c/preprocessor2.scm | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'module/c') diff --git a/module/c/preprocessor2.scm b/module/c/preprocessor2.scm index 71c2a09e..8bec237a 100644 --- a/module/c/preprocessor2.scm +++ b/module/c/preprocessor2.scm @@ -19,8 +19,6 @@ :use-module (c unlex) :use-module (c cpp-types) :use-module (c cpp-util) - :use-module ((c zipper) :select (list-zipper left focused right zip-find-right - list->zipper zipper->list)) :export (defined-macro)) (define-syntax-rule (alist-of variable key-type value-type) @@ -67,38 +65,30 @@ (define (expand## tokens) (typecheck tokens (list-of lexeme?)) - (let loop ((zipper (list->zipper tokens))) - (cond ((equal? "##" (punctuator-token? (focused zipper))) - (let ((l (drop-whitespace (left zipper))) - (r (drop-whitespace (right zipper)))) + (let loop ((left '()) + (right tokens)) + (cond ((null? right) + (reverse left)) + ((equal? "##" (punctuator-token? (car right))) + (let ((l (drop-whitespace left)) + (r (drop-whitespace (cdr right)))) (cond ((or (null? l) (null? r)) (scm-error 'cpp-error "expand##" "## can't be first or last token: ~s" (list (unlex tokens)) #f)) ((and (placemaker-token? (car l)) (placemaker-token? (car r))) - (loop (list-zipper left: (cdr l) - right: (cdr r) - focused: (placemaker)))) + (loop (cdr l) (cons (placemaker) (cdr r)))) ((placemaker-token? (car l)) - (loop (list-zipper left: (cdr l) - right: (cdr r) - focused: (car r)))) + (loop (cdr l) r)) ((placemaker-token? (car r)) - (loop (list-zipper left: (cdr l) - right: (cdr r) - focused: (car l)))) - (else - (loop (list-zipper left: (cdr l) - right: (cdr r) - focused: (concatenate-tokens - (car l) (car r)))))))) - ((null? (right zipper)) - (zipper->list zipper)) + (loop (cdr l) (cons (car l) (cdr r)))) + (else (loop (cdr l) (cons (concatenate-tokens (car l) (car r)) + (cdr r))))))) (else - (loop (zip-find-right - (lambda (token) (equal? "##" (punctuator-token? token))) - zipper)))))) + (let ((pre post (break (lambda (token) (equal? "##" (punctuator-token? token))) + right))) + (loop (append left (reverse pre)) post)))))) ;; expand function like macro -- cgit v1.2.3