*** empty log message ***

original commit: 0913b67e5f88cfd754cbf7abeb09b0d854fe413f
tokens
Scott Owens 23 years ago
parent b8d4718d9b
commit 6529029f20

@ -20,8 +20,16 @@
(let ((match (let ((match
(push-back lb (- length longest-match-length)))) (push-back lb (- length longest-match-length))))
(if (not longest-match-action) (if (not longest-match-action)
(error 'lexer (format "No match found in input starting with: ~a" (raise (make-exn:read
(list->string (lex-buffer-from lb))))) (format "lexer: No match found in input starting with: ~a"
(list->string (lex-buffer-from lb)))
(current-continuation-marks)
(lex-buffer-ip lb)
#f
(position-line first-pos)
(position-col first-pos)
(position-offset first-pos)
(- (position-offset end-pos) (position-offset first-pos)))))
(longest-match-action (longest-match-action
(lambda () (lambda ()
first-pos) first-pos)
@ -142,7 +150,7 @@
;; c = char | eof ;; c = char | eof
;; lex-buf = ;; lex-buf =
;; (make-lex-buffer input-port (c list) (c list) int int int (int list)) ;; (make-lex-buffer input-port (c list) (c list) int int int (int list))
(define-struct lex-buffer (ip from to offset line col line-lengths)) (define-struct lex-buffer (ip from to offset line col line-lengths tab-skips))
;; make-lex-buf: input-port -> lex-buf ;; make-lex-buf: input-port -> lex-buf
(define make-lex-buf (define make-lex-buf
@ -152,7 +160,7 @@
((not (input-port? ip)) ((not (input-port? ip))
(raise-type-error 'make-lex-buf "input-port" 0 ip)) (raise-type-error 'make-lex-buf "input-port" 0 ip))
(else (else
(make-lex-buffer ip null null 1 1 1 null)))) (make-lex-buffer ip null null 1 1 1 null null))))
((ip offsets) ((ip offsets)
(cond (cond
((not (input-port? ip)) ((not (input-port? ip))
@ -163,7 +171,7 @@
(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)))))) (make-lex-buffer ip null null (add1 (caddr offsets)) (add1 (car offsets)) (add1 (cadr offsets)) null null))))))
;; next-char: lex-buf -> c ;; next-char: lex-buf -> c
;; gets the next character from the buffer ;; gets the next character from the buffer
@ -190,7 +198,8 @@
(set-lex-buffer-to! lb (cons char-in (lex-buffer-to lb))) (set-lex-buffer-to! lb (cons char-in (lex-buffer-to lb)))
(cond (cond
((eq? #\tab char-in) ((eq? #\tab char-in)
(let ((skip-amt 1));(- 8 (modulo (lex-buffer-col lb) 8)))) (let ((skip-amt (- 8 (modulo (lex-buffer-col lb) 8))))
(set-lex-buffer-tab-skips! lb (cons skip-amt (lex-buffer-tab-skips lb)))
(set-lex-buffer-col! lb (+ skip-amt (lex-buffer-col lb))) (set-lex-buffer-col! lb (+ skip-amt (lex-buffer-col lb)))
(set-lex-buffer-offset! lb (+ skip-amt (lex-buffer-col lb))))) (set-lex-buffer-offset! lb (+ skip-amt (lex-buffer-col lb)))))
((eq? #\newline char-in) ((eq? #\newline char-in)
@ -225,19 +234,17 @@
(else (else
(cond (cond
((eq? #\newline (car from)) ((eq? #\newline (car from))
(set-lex-buffer-line! (set-lex-buffer-line! lb (sub1 (lex-buffer-line lb)))
lb (set-lex-buffer-col! lb (car (lex-buffer-line-lengths lb)))
(sub1 (lex-buffer-line lb))) (set-lex-buffer-line-lengths! lb (cdr (lex-buffer-line-lengths lb))))
(set-lex-buffer-col! ((eq? #\tab (car from))
lb (set-lex-buffer-col! lb (- (lex-buffer-col lb)
(car (lex-buffer-line-lengths lb))) (car (lex-buffer-tab-skips lb))))
(set-lex-buffer-line-lengths! (set-lex-buffer-offset! lb (- (add1 (lex-buffer-offset lb))
lb (car (lex-buffer-tab-skips lb))))
(cdr (lex-buffer-line-lengths lb)))) (set-lex-buffer-tab-skips! lb (cdr (lex-buffer-tab-skips lb))))
(else (else
(set-lex-buffer-col! (set-lex-buffer-col! lb (sub1 (lex-buffer-col lb)))))
lb
(sub1 (lex-buffer-col lb)))))
(switch-buffers (cdr from) (switch-buffers (cdr from)
(cons (car from) to) (cons (car from) to)
(sub1 num-to-add))))))) (sub1 num-to-add)))))))
@ -249,6 +256,7 @@
(set-lex-buffer-to! lb null) (set-lex-buffer-to! lb null)
(set-lex-buffer-offset! lb (- (lex-buffer-offset lb) i)) (set-lex-buffer-offset! lb (- (lex-buffer-offset lb) i))
(set-lex-buffer-line-lengths! lb null) (set-lex-buffer-line-lengths! lb null)
(set-lex-buffer-tab-skips! lb null)
ret))) ret)))
(define-struct position (offset line col)) (define-struct position (offset line col))

Loading…
Cancel
Save