[plt-scheme] help with parser-tools collection

From: Bob McCormick (bobm at adt.com)
Date: Fri Aug 6 17:44:32 EDT 2004

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 {;
         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))

  (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
    ((eof) 'EOF)
    (#\newline 'newline)
    ((: #\tab #\space) (zonel input-port))
    ("{" 'OB)
    ("}" 'CB)
    ("\"" 'QUOTE)
    ("zone" 'ZONE)
    ((+ (: lower-letter upper-letter)) (token-STRING (string->symbol 

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", 

Does anyone have some guidance on how to go about doing this?

Posted on the users mailing list.