pointlander / peg

Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator.
BSD 3-Clause "New" or "Revised" License
1.02k stars 120 forks source link

more doc? #100

Open kpixley opened 4 years ago

kpixley commented 4 years ago

Doc appears to be out of date. Notably, buffer[begin:end] doesn't work. Not very useful without it.

I'm also having trouble understanding how to build parse trees with peg. leg apparently has/had $$ = but when I try that, peg dumps core.

Also having trouble figuring out error handling. Like, how do I report an error up from embedded fragments?

Is the parser guaranteed to be "p"? It is used in examples, but not mentioned in doc.

Is there an equivalent to yyaccept or yyreject?

Is there a - operator as with leg?

theclapp commented 4 years ago

I am not the author, but I can help with a few of these.

Notably, buffer[begin:end] doesn't work

Use text in your Go code to refer to the text captured between < and >. See peg.peg for examples.

Is the parser guaranteed to be "p"?

Yes. In the template in tree/peg.go, p is hardcoded as the method receiver in all functions.

I don't know about the rest, sorry.

theclapp commented 4 years ago

Is there a - operator as with leg?

Not sure exactly what this means. Checking the manual for peg/leg, I see - used in two contexts: one is as the dash in a range

range =         char '-' char | char

which this package supports (see here), and one is as a regular part of the grammar

- =             ( space | comment )*

which just defines - as zero-or-more spaces-or-comments.

So I think the answer is: yes, Peg supports the - operator as with leg. Except of course that if you want - to mean (space / comment)* (using Peg syntax), you'll have to define it that way.

pointlander commented 4 years ago

added AST example: https://github.com/pointlander/peg/tree/master/grammars/calculator_ast