1 (import (chicken irregex))
3 (define (string->instr str)
5 (l (string-length str))
6 (whitespace-irx (irregex "[ \t]*"))
7 (newline-irx (irregex "\n"))
8 (comment-irx (irregex ";[^\n]*")))
9 (define (accept-token irx mandatory)
10 (let ((wsmatch (irregex-match whitespace-irx (substr str idx))))
11 (set! idx (+ idx (irregex-match-end-index wsmatch)))) ;Skip leading whitespace
12 (let ((res (irregex-match irx (substring str idx))))
15 (set! idx (+ idx (irregex-match-end-index res)))
16 (irregex-match-substring res))
18 (error "Unexpected token at input string index" idx)
20 (define (accept-token-string token-str mandatory)
21 (accept-token (irregex token-str) mandatory))
27 (or (accept-token comment-irx #f)
28 (accept-token newline-irx #f)
29 (and(accept-token newline-irx #t))))
32 (accept-token period-irx #t)