|
|
@ -85,47 +85,47 @@
|
|
|
|
(not (andmap (lambda (x) (>= x 0)) offsets)))
|
|
|
|
(not (andmap (lambda (x) (>= x 0)) offsets)))
|
|
|
|
(raise-type-error 'make-lex-buf "list of 3 non-negative exact integers" 1 ip offsets))
|
|
|
|
(raise-type-error 'make-lex-buf "list of 3 non-negative exact integers" 1 ip offsets))
|
|
|
|
(else
|
|
|
|
(else
|
|
|
|
(make-lex-buffer ip null null (add1 (caddr offsets)) (add1 (car offsets)) (add1 (cadr offsets)) null null))))))
|
|
|
|
(make-lex-buffer ip null null (caddr offsets) (car offsets) (cadr offsets) null null))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (get-next lb)
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
((null? (lex-buffer-from lb))
|
|
|
|
|
|
|
|
(read-char (lex-buffer-ip lb)))
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
(begin0
|
|
|
|
|
|
|
|
(car (lex-buffer-from lb))
|
|
|
|
|
|
|
|
(set-lex-buffer-from! lb (cdr (lex-buffer-from lb)))))))
|
|
|
|
|
|
|
|
|
|
|
|
;; next-char: lex-buf -> c
|
|
|
|
;; next-char: lex-buf -> c
|
|
|
|
;; gets the next character from the buffer
|
|
|
|
;; gets the next character from the buffer
|
|
|
|
(define (next-char lb)
|
|
|
|
(define (next-char lb)
|
|
|
|
(let ((get-next
|
|
|
|
(let ((char-in
|
|
|
|
(lambda ()
|
|
|
|
(let ((real-char (get-next lb)))
|
|
|
|
(cond
|
|
|
|
(if (eq? #\return real-char)
|
|
|
|
((null? (lex-buffer-from lb))
|
|
|
|
(let ((second-char (get-next)))
|
|
|
|
(read-char (lex-buffer-ip lb)))
|
|
|
|
(if (not (eq? second-char #\newline))
|
|
|
|
(else
|
|
|
|
(set-lex-buffer-from!
|
|
|
|
(begin0
|
|
|
|
lb
|
|
|
|
(car (lex-buffer-from lb))
|
|
|
|
(cons second-char (lex-buffer-from lb))))
|
|
|
|
(set-lex-buffer-from! lb (cdr (lex-buffer-from lb)))))))))
|
|
|
|
#\newline)
|
|
|
|
(let ((char-in
|
|
|
|
real-char))))
|
|
|
|
(let ((real-char (get-next)))
|
|
|
|
(set-lex-buffer-to! lb (cons char-in (lex-buffer-to lb)))
|
|
|
|
(if (eq? #\return real-char)
|
|
|
|
(cond
|
|
|
|
(let ((second-char (get-next)))
|
|
|
|
((eq? #\tab char-in)
|
|
|
|
(if (not (eq? second-char #\newline))
|
|
|
|
(let ((skip-amt (- 8 (modulo (lex-buffer-col lb) 8))))
|
|
|
|
(set-lex-buffer-from!
|
|
|
|
(set-lex-buffer-tab-skips! lb (cons skip-amt (lex-buffer-tab-skips lb)))
|
|
|
|
lb
|
|
|
|
(set-lex-buffer-col! lb (+ skip-amt (lex-buffer-col lb)))))
|
|
|
|
(cons second-char (lex-buffer-from lb))))
|
|
|
|
((eq? #\newline char-in)
|
|
|
|
#\newline)
|
|
|
|
(set-lex-buffer-line-lengths!
|
|
|
|
real-char))))
|
|
|
|
lb
|
|
|
|
(set-lex-buffer-to! lb (cons char-in (lex-buffer-to lb)))
|
|
|
|
(cons (lex-buffer-col lb)
|
|
|
|
(cond
|
|
|
|
(lex-buffer-line-lengths lb)))
|
|
|
|
((eq? #\tab char-in)
|
|
|
|
(set-lex-buffer-line! lb (add1 (lex-buffer-line lb)))
|
|
|
|
(let ((skip-amt (- 8 (modulo (lex-buffer-col lb) 8))))
|
|
|
|
(set-lex-buffer-col! lb 1))
|
|
|
|
(set-lex-buffer-tab-skips! lb (cons skip-amt (lex-buffer-tab-skips lb)))
|
|
|
|
(else
|
|
|
|
(set-lex-buffer-col! lb (+ skip-amt (lex-buffer-col lb)))))
|
|
|
|
(set-lex-buffer-col! lb (add1 (lex-buffer-col lb)))))
|
|
|
|
((eq? #\newline char-in)
|
|
|
|
(set-lex-buffer-offset! lb (add1 (lex-buffer-offset lb)))
|
|
|
|
(set-lex-buffer-line-lengths!
|
|
|
|
char-in))
|
|
|
|
lb
|
|
|
|
|
|
|
|
(cons (lex-buffer-col lb)
|
|
|
|
|
|
|
|
(lex-buffer-line-lengths lb)))
|
|
|
|
|
|
|
|
(set-lex-buffer-line! lb (add1 (lex-buffer-line lb)))
|
|
|
|
|
|
|
|
(set-lex-buffer-col! lb 1))
|
|
|
|
|
|
|
|
(else
|
|
|
|
|
|
|
|
(set-lex-buffer-col! lb (add1 (lex-buffer-col lb)))))
|
|
|
|
|
|
|
|
(set-lex-buffer-offset! lb (add1 (lex-buffer-offset lb)))
|
|
|
|
|
|
|
|
char-in)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; push-back: lex-buf * int -> c list
|
|
|
|
;; push-back: lex-buf * int -> c list
|
|
|
|
;; pushes the last read i characters back to be read again
|
|
|
|
;; pushes the last read i characters back to be read again
|
|
|
|