All pastes #396686 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-15 22:40 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
	(cond
	 ((null? haystack)
	  (error "Ran out of text to process in string"))
	    
					;If it's an escape sequence
	 ((eqv? (s-car rest) "\\")
	  (token-content-add (loop delim
				   (s-cddr rest)
				   line)
					;TODO - escape sequences, currently ignored
			     (s-cadr rest)))

					;Or the end of the string
	 ((eqv? (s-car rest) delim)
					;Yup, construct a token
	  (token delim
		 (s-car rest)
		 linenum
		 (s-cdr rest)))
					;Regular character
	 (else (token-content-add (loop delim
					     (s-cdr rest)
					     linenum)
				       (s-car rest)))))
      #f))