All pastes #387023 Raw Edit

Something

public text v1 · immutable
·published 2007-03-09 00:48 UTC
rendered paste body
;Returns a string token or #f
(define (collect-string-token haystack line)
  (if (string-delim? (s-cdr haystack))
      (let loop ((delim (s-car haystack))
		 (rest (s-cdr haystack))
		 (linenum line))
					;If we're out of text
	(if (null? s-car haystack)
	    (error "Ran out of text to process in string")

					;If it's an escape sequence
	    (if (eqv? (s-car rest) "\\")
		(cons (string-append (s-car rest)
				     (car (loop (s-cdr rest))))
		      (cdr (loop (s-cdr rest))))

					;Or the end of the string
		(if (eqv? (s-car rest) delim)
		    (cons (s-car rest)
			  (s-cddr rest))
					;Regular character
		    (cons (string-append (s-car rest)
					 (car (loop (s-cdr rest))))
			  (cdr (loop (s-cdr rest))))))))
      #f))