Allow parsing config lines without comments.

This commit is contained in:
Dominik Pantůček 2024-01-16 22:10:56 +01:00
parent 2674f08674
commit ba2c753109
3 changed files with 6 additions and 5 deletions

View file

@ -291,7 +291,7 @@ util-io.o: util-io.import.scm
util-io.import.scm: $(UTIL-IO-SOURCES)
UTIL-PARSER-SOURCES=util-parser.scm testing.import.scm \
duck.import.scm
duck.import.scm racket-kwargs.import.scm
util-parser.o: util-parser.import.scm
util-parser.import.scm: $(UTIL-PARSER-SOURCES)

View file

@ -54,8 +54,7 @@
(users '()))
(if (null? lines)
users
(let ((line (parser-preprocess-line (car lines))))
(print line)
(let ((line (parser-preprocess-line (car lines) #:strip-comments? #f)))
(if (equal? line "")
(loop (cdr lines)
users)

View file

@ -39,11 +39,12 @@ member file parsers. All functions are UTF-8 aware.")
(import scheme
(chicken base)
racket-kwargs
testing)
;; Pass 0: Removes any comments and removes any leading and trailing
;; whitespace.
(define/doc (parser-preprocess-line line)
(define*/doc (parser-preprocess-line line #:strip-comments? (strip-comments? #t))
("* ```line``` - a string with contents of one source line
If the input ```line``` contains the ```#``` character, the rest of
@ -62,7 +63,8 @@ Returns a string representing the preprocessed line.")
(ploop (add1 pidx)))))
(hpos (let hloop ((hidx ppos))
(if (or (= hidx llen)
(eq? (string-ref line hidx) #\#))
(and strip-comments?
(eq? (string-ref line hidx) #\#)))
hidx
(hloop (add1 hidx)))))
(spos (let sloop ((sidx (sub1 hpos)))