diff --git a/src/util-parser.scm b/src/util-parser.scm index 72bcf09..09408d8 100644 --- a/src/util-parser.scm +++ b/src/util-parser.scm @@ -35,7 +35,6 @@ (import scheme (chicken base) - (chicken irregex) testing) ;; Pass 0: Removes any comments and removes any leading and trailing @@ -69,17 +68,29 @@ ;; one token was there and pair of symbol and string if both key and ;; the value were present. (define (parser-parse-line line) - (if (= (string-length line) 0) - #f - (let ((dm (irregex-search (irregex "[ \\t]" 'u) line))) - (if dm - (let* ((sep-idx (irregex-match-start-index dm)) - (key-str (substring line 0 sep-idx)) - (key (string->symbol key-str)) - (sep+val (substring line sep-idx)) - (val (irregex-replace (irregex "^[ \\t]*" 'u) sep+val ""))) - (cons key val)) - (string->symbol line))))) + (let* ((llen (string-length line)) + (spos (let sloop ((sidx 0)) + (if (or (= sidx llen) + (let ((ch (string-ref line sidx))) + (or (eq? ch #\space) + (eq? ch #\tab)))) + sidx + (sloop (add1 sidx))))) + (vpos (let vloop ((vidx spos)) + (if (or (= vidx llen) + (not (let ((ch (string-ref line vidx))) + (or (eq? ch #\space) + (eq? ch #\tab))))) + vidx + (vloop (add1 vidx)))))) + (if (= llen 0) + #f + (if (< vpos llen) + (cons (string->symbol + (substring line 0 spos)) + (substring line vpos)) + (string->symbol + (substring line 0 spos)))))) ;; Self-tests (define (parser-tests!)