[plt-scheme] How to "unput" characters to a port during lexing?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Thu Mar 2 17:21:05 EST 2006

Jens Axel Søgaard wrote:
> The parser for CSS2.1 is now almost finished. The grammar
> used is the flex/yacc one from
> 
>     <http://www.w3.org/TR/CSS21/grammar.html>.
> 
> There is just one rule left, that I can't figure out
> how to port.
> 
> It is the line
> 
>   {s}+\/\*[^*]*\*+([^/*][^*]*\*+)*\/    {unput(' ');
> 
> which puts a space back in the input stream.
> 
> How do I "unput" a space in the parser-tools lexer?

I tried this rule unsuccesfully

   ((:seq (:+ s) "/*"
                 (:~ #\*) (:+ #\*)
                 (:* (:~ #\/ #\*) (:* (:~ #\*)) (:+ #\*))
                 "/")

    (token S lexeme))

however, the rule

   ((:: (:+ s) "/*" (complement (:: any-string "*/" any-string)) "*/")
    (token S lexeme))

does wonders.

Did I translate the original flex pattern incorrectly?


Anyways, the parser now passes the ~200 tests in the CSS2.1 testsuite.

-- 
Jens Axel Søgaard




Posted on the users mailing list.