scsh-checkins
[Top] [All Lists]

[Scsh-checkins] CVS: scsh-0.6/scheme/rts read.scm,1.3,1.4

To: scsh-checkins@sourceforge.net
Subject: [Scsh-checkins] CVS: scsh-0.6/scheme/rts read.scm,1.3,1.4
From: Martin Gasbichler <mainzelm@users.sourceforge.net>
Date: Fri, 12 Jan 2001 10:16:45 -0800
List-id: <scsh-checkins.lists.sourceforge.net>
Sender: scsh-checkins-admin@lists.sourceforge.net
Update of /cvsroot/scsh/scsh-0.6/scheme/rts
In directory usw-pr-cvs1:/tmp/cvs-serv18131

Modified Files:
        read.scm 
Log Message:
Added nested multi-line comments. The implementation has two
drawbacks: 
1.) Since # and | may be part of an identifier, a#|bla|# is
read as a#|bla|# not as a.  

2.) The REPL won't read a comment for its own, it will wait for
another value: 
>#|bla|#

3
3
>


Index: read.scm
===================================================================
RCS file: /cvsroot/scsh/scsh-0.6/scheme/rts/read.scm,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** read.scm    1999/09/23 14:36:19     1.3
--- read.scm    2001/01/12 18:16:42     1.4
***************
*** 42,45 ****
--- 42,69 ----
  
  
+ (define (multi-line-comment-skip c port)
+   (read-char port)
+   (let lp ((state 0) (nested? #f))
+     (let* ((advance-one-of-two 
+           (lambda (look-for1 state1 look-for2 state2 nested?)
+                         (let ((c (read-char port)))
+                           (if (eof-object? c)
+                               (error 
+                        "EOF inside block comment -- #| missing a closing |#")
+                               (lp (cond ((char=? c look-for1) state1)
+                                         ((char=? c look-for2) state2)
+                                         (else 0)) nested?)))))
+          (advance-if (lambda (look-for state nested?)
+                        (advance-one-of-two look-for state 
+                                            look-for state 
+                                            nested?))))
+       (case state
+       ((0) (advance-one-of-two #\| 1 #\# 5 nested?))
+       ((1) (advance-if #\# 2 nested?))
+       ((2) (if nested? #f (sub-read port)))
+       ((5) (advance-if #\| 6 nested?))
+       ((6) (lp 0 #t) (lp 0 nested?))))))
+     
+ 
  ; scsh stop
  
***************
*** 259,262 ****
--- 283,288 ----
  
  (define-sharp-macro #\! script-skip)
+ 
+ (define-sharp-macro #\| multi-line-comment-skip)
  
  ; Tokens



<Prev in Thread] Current Thread [Next in Thread>
  • [Scsh-checkins] CVS: scsh-0.6/scheme/rts read.scm,1.3,1.4, Martin Gasbichler <=