⻰OGoPEGo
A PEG parser generator in Go.
⻰OGoPEGo is the Go sibling of 竜TatSu (Python) and 铁修TieXiu (Rust). It is functionally complete and passes the same test suite as its siblings.
Refer to the 竜TatSu documentation for grammar syntax, semantics, and usage. The local SYNTAX.md describes the grammar format.
The CLI tool is a great way to explored the features offered by the library:
$ ogo --help
Usage: ogo <command> [flags]
ogopego: A PEG parser generator in Go
Flags:
-h, --help Show context-sensitive help.
-o, --output=STRING Output to a file instead of stdout
-C, --color="auto" Control colorized output for API results
-t, --trace Display a detailed trace of the parsing process
-v, --version Print version information
Commands:
run <grammar> <inputs> ... [flags]
Execute a grammar against one or more input files
boot [flags]
The internal boot grammar
grammar <grammar> [flags]
Grammar transformations
Run "ogo <command> --help" for more information on a command.
Installation
go install github.com/neogeny/ogopego/cmd/ogo@latest
Python
There's a Python package that provides an out-of-process integration with ⻰OGoPEGo. The package provides a Python API that allows you to compile grammars and parse input using the Go implementation of the PEG parser generator. The package is available on PyPI as ogopego and can be installed with:
pip install ogopego
After installation the command-line executable becomes available as ogo.
ogo --help
For the Python API please take a look at the documentation in the docs directory.
Library API
import "github.com/neogeny/ogopego/api"
// Compile a grammar string into a Grammar object.
g, err := api.Compile(grammar, cfg)
// Parse input with a compiled Grammar.
tree, err := api.ParseInput(g, input, cfg)
// Compile and parse in one step.
tree, err := api.ParseGrammar(grammar, cfg)
// Compile to JSON-compatible output.
json, err := api.CompileToJSON(grammar, cfg)
// Parse input to JSON-compatible output.
json, err := api.ParseInputToJSON(g, input, cfg)
// JSON roundtrip via peg package.
jsonStr := peg.SerializeGrammar(g)
g2, err := peg.ParseGrammar([]byte(jsonStr))
Grammar object
import "github.com/neogeny/ogopego/peg"
// A compiled grammar. Create one with api.Compile.
type Grammar struct {
Name string // grammar name
Directives *asjson.OrderedMap // @@directives
Keywords []string // @@keyword declarations
Rules []*Rule // grammar rules
Analyzed bool // true after Initialize()
}
// Parse input text with this grammar (use api.ParseInput).
result, err := api.ParseInput(g, text, cfg)
// Prepare grammar for parsing (link rules, detect left recursion).
err := g.Initialize()
// Serialize.
jsonStr := g.AsJSONStr() // indented JSON
jsonStr := peg.SerializeGrammar(g) // clean JSON (recommended)
data, err := peg.ParseGrammar([]byte(jsonStr)) // deserialize
// Display.
fmt.Println(g.PrettyPrint()) // EBNF pretty-print
fmt.Println(g.Railroads()) // railroad diagram
Features
- Out-of-process integration for Python is complete.
- Generation of source code with an object model for deifinitions in the grammar is complete. The model generator defines the types specified in the input grammar and creates the transformation from the
Treeresult of a call toParse()to the object model. - Code generation of a parser recently moved in 竜TatSu to the loading of a model of the Grammar and using it as parser. ⻰OGoPEGo is cabable of generating a model of the
Grammarconstructor for a grammar that can be compiled by Go for blazing boot times. - ⻰OGoPEGo also knows how to load fast a
Grammarmodel from 竜TatSu-format JSON. - Semantic actions (transformations) during parse are implemented through a
SemanticsFunc(Tree) Treeconfiguration entry. Transformations are limited toTree->Tree, so a walker must be used as post-processor if a different AST type is desidred. The AST model generation available through the CLI tool generates such a walker. - Interpolation and evaluation of `constant` expressions hasn't had any known use cases with 竜TatSu. They will not be implemented in ⻰OGoPEGo until a use case appears.
License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion in the work, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.
Metadata
Release files for ogopego 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ogopego-1.2.0.tar.gz | 152.1 kB | With provenance | Details for ogopego-1.2.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ogopego-1.2.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for ogopego-1.2.0-py3-none-win_amd64.whl |
| ogopego-1.2.0-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for ogopego-1.2.0-py3-none-manylinux_2_28_x86_64.whl |
| ogopego-1.2.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for ogopego-1.2.0-py3-none-macosx_11_0_arm64.whl |
Total release size: 6.9 MB
Release files / ogopego-1.2.0.tar.gz
| Download URL | ogopego-1.2.0.tar.gz |
|---|---|
| Size | 152.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76d5466685eae9826abf186105a86fe6f860cdb1aedbc89d6fc5bb95d5c1862b
|
|
BLAKE2b-256 checksum How to use checksums |
4a0e2cd1804e6fc02bd62999ac7b4045937ed4fe455af23843ad5ec252928ea0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.
Transparency logRelease files / ogopego-1.2.0-py3-none-win_amd64.whl
| Download URL | ogopego-1.2.0-py3-none-win_amd64.whl |
|---|---|
| Size | 15.1 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
11fd29d110a39386862be332bcc0f8a8c019d1f41a35b29c3726d2c12212514e
|
|
BLAKE2b-256 checksum How to use checksums |
6802fb1a14a1201bff6e2bcd9f422617f1a682984564142b6f923eaa7cd5b194
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.
Transparency logRelease files / ogopego-1.2.0-py3-none-manylinux_2_28_x86_64.whl
| Download URL | ogopego-1.2.0-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
a98ea597daa014fdb12feec2ecce0ab1216b9464cf4b23d8db46adb78d7b5337
|
|
BLAKE2b-256 checksum How to use checksums |
43bbfc2992f685e74513d2ba1346db554b8324e1147136f191869f916f0bece4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.
Transparency logRelease files / ogopego-1.2.0-py3-none-macosx_11_0_arm64.whl
| Download URL | ogopego-1.2.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0d2e603cf55f834d589ea9f211f5eaf07f2275794b8b7dd7943c37fd93acc561
|
|
BLAKE2b-256 checksum How to use checksums |
f0b4e0ef9f8e175b4618c06c53f9e270f159f5defe1b8850e66ff05966691b15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.
Transparency logSecurity for ogopego 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for ogopego-1.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.