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

From: Paulo J. Matos (pocmatos at gmail.com)
Date: Fri Jun 19 14:18:38 EDT 2009

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...

On Thu, Jun 18, 2009 at 7:08 PM, Paulo J. Matos<pocmatos at gmail.com> wrote:
> Hi,
>
> I have a question regarding on how to user parser tools to handle the
> following. My language has C style comments which means I have
> something like:
> (define-lex-abbrevs
>  (line-comment (:: "//" (complement (:: any-string "\n" any-string)) "\n"))
>  (c-style-comment (:: "/*" (complement (:: any-string "*/" any-string)) "*/")))
>
> In the lexer:
> (define eb-lexer
>  (lexer-src-pos
>   ;; Ignore Comments
>   ((:or whitespace c-style-comment line-comment) (return-without-pos
> (eb-lexer input-port)))
> ...
> ...)
>
> In the parser I then don't worry about newline... it's as if
> everything could be in the same line.
> Now, I want to change the language a bit, so that new lines _ending
> statements_ become important.
> However, the issue is that by stripping the line-comment, I am
> stripping the last new line. Is there a way to remove the line comment
> in the lexer but still maintaining the new line?
>
> So, if I have :
> TOKEN1 // comment \n TOKEN2
> I could get
> TOKEN1 \n TOKEN2
> ?
>
> Cheers,
> --
> Paulo Jorge Matos - pocmatos at gmail.com
> http://www.pmatos.net
>



-- 
Paulo Jorge Matos - pocmatos at gmail.com
http://www.pmatos.net


Posted on the users mailing list.