hello,
i just want to skip comments and blank lines at the beginning of a file, i find a solution that rewind the port/file using file-position but is there other method/solution?
(require (only-in racket/base [do do-scheme])) ; backup original do
(include "while-do-when-unless.scm")
(include "SRFI-105.scm")
(define (test-blank-lines-or-comments li)
(or (not (non-empty-string? li)) ; empty line
(regexp-match #px"^[[:blank:]]*;+" li))) ; space, comments
(define (skip-comments-and-empty-lines in)
(define li '())
(define fpos '())
(define cpt -1)
(do
(set! cpt (+ 1 cpt))
(set! fpos (file-position in))
(set! li (read-line in))
while (test-blank-lines-or-comments li))
(file-position in fpos) ;; rewind to the code to parse after comments or spaces
(display "SRFI-105.rkt : skip-comments-and-empty-lines : number of skipped lines (comments, spaces) at beginning : ")
(display cpt)
(newline)
)
(define (literal-read-syntax src in)
(skip-comments-and-empty-lines in)
(define lst-code (process-input-code-tail-rec in))
lst-code)
note 'do' is defined this way:
;; > (define i 0)
;; > (do (display-nl "toto") (set! i (+ i 1)) while (< i 4))
;; toto
;; toto
;; toto
;; toto
;; Warning: this 'do' break the one of scheme !
(define-syntax do
(syntax-rules (do)
((do b1 ...
while pred)
(let loop () b1 ... (when pred (loop))))))
it works:
Welcome to DrRacket, version 8.12 [cs].
Language: reader "../Scheme-PLUS-for-Racket/main/Scheme-PLUS-for-Racket/src/SRFI-105.rkt", with debugging; memory limit: 8192 MB.
SRFI-105.rkt : skip-comments-and-empty-lines : number of skipped lines (comments, spaces) at beginning : 12
regards
damien