<br><div class="gmail_quote">On Fri, Jun 19, 2009 at 11:18 AM, Paulo J. Matos <span dir="ltr">&lt;<a href="mailto:pocmatos@gmail.com">pocmatos@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Still on this, is it not possible to re-insert a char in an input-port?<br>
This way, once the lexer recognizes a one-line comment I could<br>
re-insert the \n into the port and keep lexing...<br>
<div></div></blockquote><div><br>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. <br><br>
<a href="http://docs.plt-scheme.org/reference/port-buffers.html#(def._((quote._~23~25kernel)._file-position))">http://docs.plt-scheme.org/reference/port-buffers.html#(def._((quote._~23~25kernel)._file-position))</a><br><br>
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. <br>
<br><span style="font-family: courier new,monospace;">(define (custom-comment-reader in)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  (read-until-new-line ...)) ;; defined elsewhere</span>  <br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(define eb-lexer</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  (lexer</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">   (&quot;//&quot; (custom-comment-reader input-port)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">         ...)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">   ...))</span><br style="font-family: courier new,monospace;"><br>Cheers,<br>yc<br> <br></div></div><br>