forked from alex-eg/sex
look past comments in a public form's header
This commit is contained in:
15
utils.scm
15
utils.scm
@@ -45,6 +45,21 @@
|
||||
(define (comment-form? form)
|
||||
(and (pair? form) (eq? (car form) 'comment)))
|
||||
|
||||
;;; Remove the comment forms from the first COUNT elements of FORM --
|
||||
;;; its header -- so that the positional accessors reading it are not
|
||||
;;; shifted by one
|
||||
(define (strip-header-comments form count)
|
||||
;; This always rebuilds the list, so the location has to be carried
|
||||
;; over explicitly -- otherwise every form loses it
|
||||
(copy-form-source!
|
||||
form
|
||||
(let loop ((rest form) (kept 0) (acc (list)))
|
||||
(cond
|
||||
((null? rest) (reverse acc))
|
||||
((= kept count) (append (reverse acc) rest))
|
||||
((comment-form? (car rest)) (loop (cdr rest) kept acc))
|
||||
(else (loop (cdr rest) (+ kept 1) (cons (car rest) acc)))))))
|
||||
|
||||
(define (list-split src-list split-elt)
|
||||
;; split '(1 2 / 3 4 / 5 6) by '/ -> '((1 2) (3 4) (5 6))
|
||||
(fold (lambda (elt acc)
|
||||
|
||||
Reference in New Issue
Block a user