]> git.mdlowis.com Git - archive/dlang-scm.git/commitdiff
Added port wrapper that holds file/string location metadata
authorMike D. Lowis <mike@mdlowis.com>
Wed, 25 Jul 2012 18:07:28 +0000 (14:07 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Wed, 1 Aug 2012 14:21:21 +0000 (10:21 -0400)
source/lexer.scm
source/parse-utils.scm

index 3173b3d01796d84ff3b8d62309bbaf12509e3ed0..83fdffce636d7b61916e1413d839d0aa427023eb 100644 (file)
@@ -1,7 +1,7 @@
 (declare (unit lexer) (uses parse-utils))
 
 (define (dlang/lexer input)
-  (buf (buf input read-char) dlang/tokenize))
+  (buf (buf (charport input) charport-read) dlang/tokenize))
 
 (define (dlang/tokenize in)
   (let ((ch (buf-lookahead! in 1)))
index 85ac9d071f97402fd4095cd7860d29b4a0fe3da5..8c600cf3a0ef70cc791e7b1b592aa755a2f9baa5 100644 (file)
         (syntree=? (car ch1) (car ch2))
         (syntree-children=? (cdr ch1) (cdr ch2))))))
 
+(define-record charport port line column)
+(define (charport port) (make-charport port 0 0))
+
+(define (charport-read chprt)
+  (define ch (read-char (charport-port chprt)))
+  (if (char=? ch #\newline)
+    (begin
+      (charport-line-set! chprt (+ 1 (charport-line chprt)))
+      (charport-column-set! chprt 0))
+    (charport-column-set! chprt (+ 1 (charport-column chprt))))
+  ch)
+
 (define (char-match buf expect)
   (define actual (buf-lookahead! buf 1))
   (if (eof-object? actual)