[plt-scheme] eopl's sllgen functions don't like scanner/parser definitions in other modules?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Sat Jun 18 20:13:57 EDT 2005

Hi everyone,


I've been running into curious behavior with the EOPL collection, as I was
breaking up a large monolithic program into parts.  I originally started
with something that looked like this:


;;;;;;
(module monolith (lib "eopl.ss" "eopl")
  (provide (all-defined))

  (define scanner-spec
    '((white-sp
       (whitespace) skip)
      (comment
       ("%" (arbno (not #\newline))) skip)
      (identifier
       (letter (arbno (or letter digit "?" "_"))) symbol)
      (number
       (digit (arbno digit)) number)))

  (define grammar-spec
    '((program
       (expression)
       a-program)
      (expression (number)
                  lit-exp)))

  (sllgen:make-define-datatypes scanner-spec grammar-spec)
;;;;;;



(The real program is a bit longer.)  I thought that it would be fine if I
broke this out into two separate modules:

;;;;;;
(module some-defs (lib "eopl.ss" "eopl")
  (provide (all-defined))

  (define scanner-spec
    '((white-sp
       (whitespace) skip)
      (comment
       ("%" (arbno (not #\newline))) skip)
      (identifier
       (letter (arbno (or letter digit "?" "_"))) symbol)
      (number
       (digit (arbno digit)) number)))
  (define grammar-spec
    '((program
       (expression)
       a-program)
      (expression (number)
                  lit-exp))))


(module test-building-scanner (lib "eopl.ss" "eopl")
  (provide (all-defined))
  (require some-defs)
  (sllgen:make-define-datatypes scanner-spec grammar-spec)
;;;;;;



However, by breaking my module apart like this, I got the following
cryptic error message:

;;;;;;
test-eopl.ss:51:32: sllgen:make-define-datatypes: bad scanner
specification at: scanner-spec in: (sllgen:make-define-datatypes
scanner-spec grammar-spec)
;;;;;;


I sorta understand the error message a little bit, after reading through
the GET-TABLE function in eopl/private/sllgen.ss and reading the
documentation more closely.  I think the error message needs major
rewording, though.  The error message makes it sounds like there's
something wrong with the content of the specification itself, when the
error really is about the values not being bound as toplevel table values.


I assume that I'm running into some subtle behavior with the way SLLGEN's
macro expansion deals with modules and the toplevel, since the doc.txt
documentation to SLLGEN:MAKE-DEFINE-DATATYPES says:

    [...] the arguments must be either quoted literal tables or
    identifiers that are defined (at the top level) to quoted literal
    tables.

so it must be doing something magical to force that kind of unusual
syntactic requirement.


I was hoping that, in my test-building-scanner module, by REQUIREing the
some-defs module, I'd bring those definitions into the toplevel and make
sllgen happy.  Guess not.  I think I can easily work around this: I can
just move my calls to SLLGEN builders into the same module as my
scanner/parser definitions, so this is not really a practical problem.

But I still would like to know if there's another way to satisfy sllgen's
requirements, and yet to have scanner-spec and grammar-spec to be in a
different module.  The situation just feels non-uniform and unsatisfying
to me, especially because I know I don't know what's exactly going on.
*grin*


Thanks for any help!



Posted on the users mailing list.