A PEG Parser generator in Go
Project description
⻰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
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
- 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ogopego-0.1.7.tar.gz.
File metadata
- Download URL: ogopego-0.1.7.tar.gz
- Upload date:
- Size: 119.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53211ceb9f750bea40a20adbc6983d72492996e918f464da9493f4a5e1c10fc5
|
|
| MD5 |
1f7a9b8f45c2e640f24b900123071d28
|
|
| BLAKE2b-256 |
1d2bc53245581d3aab433fcb1e028cb84f6b1b66642e6c215cd5338d8b602414
|
Provenance
The following attestation bundles were made for ogopego-0.1.7.tar.gz:
Publisher:
publish.yml on neogeny/ogopego
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ogopego-0.1.7.tar.gz -
Subject digest:
53211ceb9f750bea40a20adbc6983d72492996e918f464da9493f4a5e1c10fc5 - Sigstore transparency entry: 1676157263
- Sigstore integration time:
-
Permalink:
neogeny/ogopego@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/neogeny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ogopego-0.1.7-py3-none-win_amd64.whl.
File metadata
- Download URL: ogopego-0.1.7-py3-none-win_amd64.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2513fa52e3f43f5d8a96ee52a5b1d759650dfcf807fe419727736167806cc9d1
|
|
| MD5 |
c2783191edca4b530514f2994ab5fd6b
|
|
| BLAKE2b-256 |
47bd56de3b84d73b14af875f6cf5c3a1e924dc6f3c36e99ad449e962c2a3d701
|
Provenance
The following attestation bundles were made for ogopego-0.1.7-py3-none-win_amd64.whl:
Publisher:
publish.yml on neogeny/ogopego
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ogopego-0.1.7-py3-none-win_amd64.whl -
Subject digest:
2513fa52e3f43f5d8a96ee52a5b1d759650dfcf807fe419727736167806cc9d1 - Sigstore transparency entry: 1676157331
- Sigstore integration time:
-
Permalink:
neogeny/ogopego@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/neogeny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ogopego-0.1.7-py3-none-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ogopego-0.1.7-py3-none-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdb221beea4d73d3a94f2d2585ac440555833329f5d4ff769555f3d1f8a6d8b9
|
|
| MD5 |
b928b715aa52f30817ed60a12ed2a3d2
|
|
| BLAKE2b-256 |
a6e50e09aae06f63bd10414e4e77a3021accf1821f2824afbdee58c31cdc5788
|
Provenance
The following attestation bundles were made for ogopego-0.1.7-py3-none-manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on neogeny/ogopego
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ogopego-0.1.7-py3-none-manylinux_2_28_x86_64.whl -
Subject digest:
bdb221beea4d73d3a94f2d2585ac440555833329f5d4ff769555f3d1f8a6d8b9 - Sigstore transparency entry: 1676157366
- Sigstore integration time:
-
Permalink:
neogeny/ogopego@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/neogeny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ogopego-0.1.7-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: ogopego-0.1.7-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f6a47dace5414943c9a263fda2419af62a81a7e44b279c6ffddbc6d4fb426df
|
|
| MD5 |
5723caf32d082f7f123a35525eb94c08
|
|
| BLAKE2b-256 |
925bffea5a2227d67035eded082ea7a7c9fa943cf60ba7f4070aded745b0cbf7
|
Provenance
The following attestation bundles were made for ogopego-0.1.7-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish.yml on neogeny/ogopego
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ogopego-0.1.7-py3-none-macosx_11_0_arm64.whl -
Subject digest:
7f6a47dace5414943c9a263fda2419af62a81a7e44b279c6ffddbc6d4fb426df - Sigstore transparency entry: 1676157406
- Sigstore integration time:
-
Permalink:
neogeny/ogopego@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/neogeny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@001101d2234de2ed1ea9a767002fb7c1e5cc9ca7 -
Trigger Event:
workflow_dispatch
-
Statement type: