[plt-scheme] help with parser-tools collection

From: Scott Owens (sowens at cs.utah.edu)
Date: Fri Aug 6 17:59:23 EDT 2004

The lexer doesn't have built-in support for case-insensitivity.
The best you can do is:
(define-lex-abbrevs (z (: "Z" "z")) (o (: "O" "o")) (n (: "N" "n")) (e 
(: "E" "e")))
(lexer
  ...
  ((@ z o n e) ...)
  ...)

which is what I do in the Scheme lexer in 
collects/syntax-color/scheme-lexer.ss

-Scott


On Aug 6, 2004, at 3:44 PM, Bob McCormick wrote:

>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> I'm having some problems figuring out how to use the Parser-Tools 
> collection, and I'm hoping someone here can help me.   The answer 
> might very well be quite simple, but I'm a newbie to Scheme, and I 
> haven't had much exposure to other parsers/lexers before either.  I'm 
> trying to figure out how to match a case-insensitive string with the 
> lexer.   Does anyone know how to do this?
>
> More specifically, I'm trying to parse a named.conf file (the 
> configuration file for the Unix name server daemon "bind").  The data 
> I'm trying to parse looks like this:
>
> zone "web-wide.net"{
>         type slave;
>         masters {
>         67.176.28.44;
>         };
>         file "web-wide.net";
> };
>
>
> And here's what I have so far as a lexer:
>
> (require (lib "yacc.ss" "parser-tools")
>          (lib "lex.ss" "parser-tools")
>          (lib "readerr.ss" "syntax"))
>
> (define-tokens value-tokens (STRING))
> (define-empty-tokens stanza-tokens (newline ZONE OB CB EOF QUOTE))
>
> (define-lex-abbrevs
>  (lower-letter (- "a" "z"))
>
>  (upper-letter (- #\A #\Z))
>
>  ;; (- 0 9) would not work because the lexer does not understand 
> numbers.  (- #\0 #\9) is ok too.
>  (digit (- "0" "9")))
>
> (define zonel
>   (lexer
>    ((eof) 'EOF)
>    (#\newline 'newline)
>    ((: #\tab #\space) (zonel input-port))
>    ("{" 'OB)
>    ("}" 'CB)
>    ("\"" 'QUOTE)
>    ("zone" 'ZONE)
>    ((+ (: lower-letter upper-letter)) (token-STRING (string->symbol 
> lexeme)))))
>
>
> This will match the string "zone" in lowercase, but the named.conf 
> file is case-insensitive, so I need to also be able to match "ZONE", 
> "zOne", etc.
>
> Does anyone have some guidance on how to go about doing this?



Posted on the users mailing list.