racket / parser-tools

11 stars 20 forks source link

cfg-parser binds production names in scope of their expressions #2

Open rntz opened 7 years ago

rntz commented 7 years ago

The following file should fail to compile because foo should be unbound. However, foo is bound, to some value internal to the parser:

#lang racket

(require parser-tools/lex parser-tools/cfg-parser)

(define-empty-tokens my-tokens (eof BLAH))

(define x
  (cfg-parser
   (start foo)
   (tokens my-tokens)
   (end eof)
   (grammar
    (foo ((BLAH)
          ;; this should be unbound but it isn't.
          foo)))))

For an example of how this might be harmful, consider:

(define (foo x) ...)
(define my-parser (cfg-parser ... (grammar ... (foo ((bar) (foo $1))))))