rodrigo.ribeiro
2022-1-19 12:17:07

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:


rodrigo.ribeiro
2022-1-19 12:17:10

(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))))))


rodrigo.ribeiro
2022-1-19 12:17:50

and racket returns the following error whenever I try to process a program in #lang peg language


rodrigo.ribeiro
2022-1-19 12:18:18

default-load-handler: expected a `module’ declaration, but found something else


rodrigo.ribeiro
2022-1-19 12:18:36

Can someone help me with this mistake?


rodrigo.ribeiro
2022-1-19 12:18:47

the complete project is at the following github repo:


rodrigo.ribeiro
2022-1-19 12:18:57

rodrigo.ribeiro
2022-1-19 12:18:58

thanks


ben.knoble
2022-1-19 13:13:56

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.


ben.knoble
2022-1-19 13:15:53

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


rodrigo.ribeiro
2022-1-19 13:25:28

Hi! So, the best option to include the definitions in tree.rkt is to use something like peg/tree ?


ben.knoble
2022-1-19 14:01:54

Yes, correct! And you’ll have to require it in order to provide it


rodrigo.ribeiro
2022-1-19 14:02:11

I manage to make it work


rodrigo.ribeiro
2022-1-19 14:02:27

using language peg/tree to require and provide make it all work


rodrigo.ribeiro
2022-1-19 14:02:42

together with your suggestion to eliminate the module reader


rodrigo.ribeiro
2022-1-19 14:02:52

Thank you so much!


rodrigo.ribeiro
2022-1-19 14:03:10

I really struggled with this matter!


zac
2022-1-19 19:02:26

@zac has joined the channel


sschwarzer
2022-1-19 23:05:29

I’m frequently surprised what some posters consider a #beginner question. :wink: