Hello all! I’m learning racket and as a way to consolidate my knowledge I’m trying to build a library for parser expression grammars (PEG). My intention is to build a language to express PEGs and the module should export a function parser that receives a string and tries to parse it using the grammar defined in the language. However, I’m struggling with building this module using the following read function:
(define (peg-read-syntax path port) (define grammar (parse port)) (datum->syntax #f `(module peg-mod racket (provide parser pretty (all-from-out “tree.rkt”)) (define (parser s) (peg-parse ,grammar s)) (define (pretty t) (peg-pretty ,grammar t))))))
and racket returns the following error whenever I try to process a program in #lang peg language
default-load-handler: expected a `module’ declaration, but found something else
Can someone help me with this mistake?
the complete project is at the following github repo:
thanks
Probably unrelated, but providing “tree.rkt” from the expanded module would refer to a locally required file of the same name, not the module in your collection.
The reader file also probably shouldn’t be wrapped in another module, so your reader.rkt should just put things at the top-level of that file
Hi! So, the best option to include the definitions in tree.rkt is to use something like peg/tree ?
Yes, correct! And you’ll have to require it in order to provide it
I manage to make it work
using language peg/tree to require and provide make it all work
together with your suggestion to eliminate the module reader
Thank you so much!
I really struggled with this matter!
@zac has joined the channel
I’m frequently surprised what some posters consider a #beginner question. :wink: