Closed rain-1 closed 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"
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")
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.
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.
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
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
.
(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)
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.
You can also do raco pkg install https://github.com/mbutterick/brag.git?path=brag
if the package server isn’t going fast enough
thanks a lot that worked, I see that I can use "start" now but not "%start".
OK, fixed that
.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