diff --git a/src/util-parser.scm b/src/util-parser.scm index 84d9d1c..72bcf09 100644 --- a/src/util-parser.scm +++ b/src/util-parser.scm @@ -41,11 +41,28 @@ ;; Pass 0: Removes any comments and removes any leading and trailing ;; whitespace. (define (parser-preprocess-line line) - (irregex-replace (irregex "[ \\t]*$" 'u) - (irregex-replace (irregex "^[ \\t]*" 'u) - (irregex-replace (irregex "#.*$" 'u) line "") - "") - "")) + (let* ((llen (string-length line)) + (ppos (let ploop ((pidx 0)) + (if (or (= pidx llen) + (not (let ((ch (string-ref line pidx))) + (or (eq? ch #\space) + (eq? ch #\tab))))) + pidx + (ploop (add1 pidx))))) + (hpos (let hloop ((hidx ppos)) + (if (or (= hidx llen) + (eq? (string-ref line hidx) #\#)) + hidx + (hloop (add1 hidx))))) + (spos (let sloop ((sidx (sub1 hpos))) + (if (< sidx ppos) + ppos + (let ((ch (string-ref line sidx))) + (if (or (eq? ch #\space) + (eq? ch #\tab)) + (sloop (sub1 sidx)) + (add1 sidx))))))) + (substring line ppos spos))) ;; Pass 1: Expects line with comments and surrounding whitespace ;; removed, returns either #f if nothing was parsed, symbol if only