Skip to content

Target Overview ​

pegtool uses one shared set of PEG structural semantics, while the initializer, actions, predicates, and public invocation belong to the target language. Choose the deployment target before writing host-language code.

Support matrix ​

TargetCLI valuesPrimary generated APIAction valueRuntime memoization
GogoInitializer wraps package-private parseanySupported
Haxehx, haxenew Parser(...).parse(...)AnySupported, but mutually exclusive with -optimize-parser
TypeScriptts, typescriptparse, ParseranyNot supported
C#cs, csharp, c#PTParser.Parseobject?Not supported
C99c, c99pegtool_parse*PegtoolValueNot supported
RustrustPTParser::parse*ValueNot supported

Each complete generated parser depends only on the target language's standard library by default. Haxe requires hxUnicode only when -haxe-use-hxunicode is explicitly selected and the grammar contains Unicode classes.

Distinguishing targets in one grammar ​

Initializers and actions are rendered through Go text/template first. The stable template variables are .Target and .GrammarOnly:

text
{
{{ if eq .Target "go" }}
package parser
type ParserCustomData struct{}
{{ else if eq .Target "ts" }}
export interface AstNode { kind: string }
{{ else if eq .Target "cs" }}
private sealed record AstNode(string Kind);
{{ else if eq .Target "c" }}
/* C helper declarations */
{{ else if eq .Target "rust" }}
// Rust helper declarations
{{ end }}
}

Use the canonical values go, hx, ts, cs, c, and rust in templates, not command-line aliases.

Choosing a target ​

  • For an existing Go service or highly customized wrappers, choose Go.
  • To compile to both JavaScript and HashLink, choose Haxe.
  • For small generated output that compiles directly in strict Web or Node projects, choose TypeScript.
  • For a .NET project, choose C#.
  • For a portable C ABI without a VM, choose C99.
  • For an explicit Value enum in a Rust project, choose Rust.

Target rankings depend on grammar shape, actions, and input and cannot be inferred from one microbenchmark. Haxe/JavaScript can outperform direct TypeScript on long linear input, while TypeScript generally has lower fixed cost and smaller generated output. Backtracking-heavy Haxe grammars can also use named-rule memoization.

Released under the BSD 3-Clause License