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-io.import.scm: $(UTIL-IO-SOURCES)
UTIL-PARSER-SOURCES=util-parser.scm testing.import.scm \ 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.o: util-parser.import.scm
util-parser.import.scm: $(UTIL-PARSER-SOURCES) util-parser.import.scm: $(UTIL-PARSER-SOURCES)

View file

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

View file

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