mna / pigeon

Command pigeon generates parsers in Go from a PEG grammar.
BSD 3-Clause "New" or "Revised" License
835 stars 66 forks source link

Include a variable in the parser state #136

Open alexflint opened 11 months ago

alexflint commented 11 months ago

Is there any way that I can pass a variable into each of the bits of Go code that handle parse results in my grammar file? I would like to pass an io.Writer and write to it from inside the handlers in my grammar file. I don't want it to be a global variable, though.

breml commented 11 months ago

Hi @alexflint

There is a feature called globalStore which does provide what you are looking for. Search the documentation on https://pkg.go.dev/github.com/mna/pigeon for this keyword or have a look at the example in https://github.com/mna/pigeon/tree/master/test/global_store.

I hope this helps.