From a7313156d8568551f41c777d1fed193962d1b790 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Wed, 15 Aug 2012 13:44:18 -0400 Subject: [PATCH] Changed charport to return a stream of charobjs that contain position data along with the real char --- source/charport.scm | 19 +++++++++++++++++++ source/parse-utils.scm | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 source/charport.scm diff --git a/source/charport.scm b/source/charport.scm new file mode 100644 index 0000000..fc4c975 --- /dev/null +++ b/source/charport.scm @@ -0,0 +1,19 @@ +(declare (unit charport)) +;(define (charport-read chprt) +; (define ch (read-char (charport-port chprt))) +; (cond +; ((eof-object? ch)) ; Do nothing for EOFs +; ((char=? ch #\newline) +; (charport-line-set! chprt (+ 1 (charport-line chprt))) +; (charport-column-set! chprt 1)) +; (else +; (charport-column-set! chprt (+ 1 (charport-column chprt))))) +; (charobj ch (charport-posdata chprt)) +; +;(define (charport-posdata chprt) +; (posdata +; (port-name (charport-port chprt)) +; (charport-line chprt) +; (charport-column chprt))) + + diff --git a/source/parse-utils.scm b/source/parse-utils.scm index 0d82c91..3ee3d51 100644 --- a/source/parse-utils.scm +++ b/source/parse-utils.scm @@ -38,6 +38,9 @@ (syntree=? (car ch1) (car ch2)) (syntree-children=? (cdr ch1) (cdr ch2)))))) +(define-record charobj char pos) +(define charobj make-charobj) + (define (charport-read chprt) (define ch (read-char (charport-port chprt))) (cond @@ -47,7 +50,7 @@ (charport-column-set! chprt 1)) (else (charport-column-set! chprt (+ 1 (charport-column chprt))))) - ch) + (if (eof-object? ch) ch (charobj ch (charport-posdata chprt)))) (define (charport-posdata chprt) (posdata -- 2.52.0