[plt-scheme] Re: Parsing not ignoring \n

From: YC (yinso.chen at gmail.com)
Date: Fri Jun 19 14:40:06 EDT 2009

On Fri, Jun 19, 2009 at 11:18 AM, Paulo J. Matos <pocmatos at gmail.com> wrote:

> Still on this, is it not possible to re-insert a char in an input-port?
> This way, once the lexer recognizes a one-line comment I could
> re-insert the \n into the port and keep lexing...

If you are reading from either a file or string port, then you can use
file-position to rewind the port to the correct position so the next lex
will start from the correct place.


Another approach is to use lexer to only handle the start of the comment,
e.g., // and then write your own custom reader to read until it hits newline
(but preserving it), and then hand the control back to the lexer.

(define (custom-comment-reader in)
  (read-until-new-line ...)) ;; defined elsewhere

(define eb-lexer
   ("//" (custom-comment-reader input-port)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090619/d48f49e3/attachment.html>

Posted on the users mailing list.