mbutterick / brag

Racket DSL for generating parsers from BNF grammars [moved to https://git.matthewbutterick.com/mbutterick/brag]
https://git.matthewbutterick.com/mbutterick/brag
MIT License
61 stars 12 forks source link

cannot parse words "start", "error", "atok" #3

Closed rain-1 closed 6 years ago

rain-1 commented 6 years ago
#lang brag
foo   : "start"

.racket/6.12/pkgs/brag/brag/cfg-parser/cfg-parser.rkt:708:55: parser-non-terminals: start used as both token and non-terminal in: start

mbutterick commented 6 years ago

I see what you mean. This is a bug in the underlying ragg code (which I didn’t write) so it will take me some time to figure it out. In the meantime, you can probably work around by specifying the rule like so?

#lang brag
foo : "star" "t"
mbutterick commented 6 years ago

Actually, that won’t work.

Here’s a better idea (this time I’m trying it before writing it). Instead of passing the raw string "start" (or "error" or "atok") as a token, edit your lexer to package each into a named token structure, e.g., (token 'START "start"). Then you can change the grammar to refer to this named token:

;; parse.rkt
#lang brag
foo   : START

This will parse the same way, and the underlying string will end up the parse tree:

#lang br
(require "parse.rkt" brag/support)
(parse-to-datum (list (token 'START "start")))
'(foo "start")
mbutterick commented 6 years ago

Note to self: check if this is an insurmountable restriction of the underlying cfg-parser function. If so, the only “fix” is to amend the docs with a list of reserved words.

mbutterick commented 6 years ago

I was able to rehabilitate "start" and "atok" as literal tokens. But according to the br-parser-tools docs, “A token cannot be named error, since error it has special use in the parser.” I’ve also updated the brag docs to note this.

rain-1 commented 6 years ago

Thanks for looking into this.

I git cloned the latest and tried cd brag ; raco pkg install but I got a lot of errors. If I cd brag and do raco test . i get some files running then brag/brag/brag.scrbl:6:21: cannot open module file module path: brag/support failure.

How should I test this latest commit?


raco setup: error: during making for <pkgs>/brag/brag/brag/test
raco setup:   brag/brag/test/test-parser.rkt:6:9: collection not found
raco setup:     for module path: brag/rules/parser
raco setup:     collection: "brag/rules"

standard-module-name-resolver: collection not found
  for module path: brag/rules/rule-structs
  collection: "brag/rules"
  in collection directories:
   /home/ivy/.racket/6.12/collects
   /usr/share/racket/collects
mbutterick commented 6 years ago

I’m not sure a direct git clone will work, because this repo holds a multi-collection package. Better to use raco pkg update brag.

mbutterick commented 6 years ago

(BTW I can’t reproduce these errors locally, nor do they show up on Travis, which heightens my suspicion that the git clone technique is the problem)

rain-1 commented 6 years ago

I tried raco pkg update brag but it got me the latest release from racket pkgs which seems to be before this latest git commit with the "start" fix.

mbutterick commented 6 years ago

You can also do raco pkg install https://github.com/mbutterick/brag.git?path=brag if the package server isn’t going fast enough

rain-1 commented 6 years ago

thanks a lot that worked, I see that I can use "start" now but not "%start".

mbutterick commented 6 years ago

OK, fixed that