pointlander/peg has 1,120 GitHub stars and 124 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-09 09:37 UTC. Last push 2026-10-12.
Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator.
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalPEG, an Implementation of a Packrat Parsing Expression Grammar in Go
A Parsing Expression Grammar ( hence peg) is a way to create grammars similar in principle to regular expressions but which allow better code integration. Specifically, peg is an implementation of the Packrat parser generator originally implemented as peg/leg by Ian Piumarta in C. A Packrat parser is a "descent recursive parser" capable of backtracking and negative look-ahead assertions which are problematic for regular expression engines.
PEG file syntax
See peg-file-syntax.md for creating your own *.peg file.
Usage
Add
pegas a tool dependencygo get -tool github.com/pointlander/peg@mainCreate your
mygrammar.pegAdd a
//go:generateline in a Go source of your package//go:generate go tool peg mygrammar.peg
Widespread community design pattern: Add lines like this in
doc.go.Generate
mygrammar.peg.gofrommygrammar.peggo generate
Example
This creates the file peg.peg.go
go tool peg -inline -switch peg.peg
Help
go tool peg -h
Development
Requirements
- Golang, see go.mod for version
- golangci-lint latest version (v2 or later)
- Bash 3.2.x or higher
Generate
Bootstrap and generate grammar *.peg.go. This commands should initially be executed once before other commands.
go generate
Build
go build
(go generate required once beforehand)
Set version
Use the version from the tag if the current commit has a tag. If not use the current commit hash.
go build -ldflags "-X main.Version=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)"
Additionally, since Go 1.18 the go command embeds version control information. Read the information:
go version -m peg
Test
go test -short ./...
(go generate required once beforehand)
Lint
golangci-lint run
(go generate required once beforehand)
Format
golangci-lint fmt
Benchmark
go test -benchmem -bench .
(go generate required once beforehand)
Author
Andrew Snodgrass
Explore related projects
codecrafters-io/build-your-own-x
Master programming by recreating your favorite technologies from scratch.
561,294 starspublic-apis/public-apis
A collective list of free APIs
497,547 starsmorluto/rea
Reverse engineer anything with agents, from app behavior down to native binaries.
446,266 starsopenclaw/openclaw
The AI that really does things. Any OS. Any Platform. The lobster way. 🦞
394,241 stars