]> 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, 25 Jul 2012 18:07:28 +0000 (14:07 -0400)
source/lexer.scm
source/parse-utils.scm

index 7c616db1c0dd16a322f7611b7be4c96f3790eb3c..545a96fd12f64b7277168c9e64958790c6bf5cfa 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 7828996171e239737e2162a3d3177a4181c0c6dc..64904f928b8a755692a3ac5723af431ec925188d 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)