Skip to content

heyitsanthony/grammars

Repository files navigation

Grammars

It's peg grammars for go plus even more.

Building

The grammar files must be generated by peg:

go get github.com/pointlander/peg
go generate github.com/heyitsanthony/grammars
go get github.com/heyitsanthony/grammars

Run the grammar binary to parse some go into an AST:

grammars <main.go

Parsing

The parse trees try to match specification BNF grammars. Each line is usually annotated with the original BNF. To ensure the PEG is well-formed, left recursion is regretfully eliminated.

Annotate these grammars with actions and compare against source grammars to ensure the parsing hasn't changed. Here pegcanon canonicalizes equivalent peg grammars by removing actions and whitespace:

go generate github.com/heyitsanthony/grammars/cmd/pegcanon
go get github.com/heyitsanthony/grammars/cmd/pegcanon
pegcanon <peg/peg.peg >1.peg
pegcanon <cmd/pegcanon/peg.peg >2.peg
diff 1.peg 2.peg

Contact

Use the issue tracker

License

grammars is under the AGPLv3 license. See LICENSE for details.

Releases

No releases published

Packages

No packages published