Help us shape the future of Go! Take the 2026 Go Developer Survey

cgo

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package cgo implements the production CGo tree-sitter backend (Option A) for the parser.Parser interface, covering the two spike-partner languages (D-05): Go (LANG-01) and Python (carries a real external C scanner). If the Plan 01-07 spike selects Option A, this is the single documented CGo exception feeding DIST-05.

Index

Constants

This section is empty.

Variables

View Source
var ErrParseFailed = errors.New("cgo: tree-sitter parse returned no tree")

ErrParseFailed is returned when the underlying tree-sitter C call returns no tree (a NULL *TSTree), so callers never receive a non-nil *parser.Tree wrapping a nil native tree.

Functions

This section is empty.

Types

type CGoParser

type CGoParser struct {
	// contains filtered or unexported fields
}

CGoParser implements parser.Parser using the CGo tree-sitter bindings for a single language grammar.

func NewCParser

func NewCParser() (*CGoParser, error)

NewCParser returns a CGoParser configured for the C grammar (mainstream-tier, LANG-06). Carries no external C scanner.

func NewCSharpParser

func NewCSharpParser() (*CGoParser, error)

NewCSharpParser returns a CGoParser configured for the C# grammar (priority-4, LANG-03). C#'s grammar carries an external C scanner — see parser.Parser's crash-isolation contract.

func NewCppParser

func NewCppParser() (*CGoParser, error)

NewCppParser returns a CGoParser configured for the C++ grammar (mainstream-tier, LANG-06). Carries an external C scanner.

func NewGoParser

func NewGoParser() (*CGoParser, error)

NewGoParser returns a CGoParser configured for the Go grammar.

func NewJavaParser

func NewJavaParser() (*CGoParser, error)

NewJavaParser returns a CGoParser configured for the Java grammar (priority-4, LANG-02). Java's grammar carries no external C scanner.

func NewJavaScriptParser

func NewJavaScriptParser() (*CGoParser, error)

NewJavaScriptParser returns a CGoParser configured for the JavaScript grammar (priority-4, LANG-05). Carries an external C scanner.

func NewKotlinParser

func NewKotlinParser() (*CGoParser, error)

NewKotlinParser returns a CGoParser configured for the Kotlin grammar (mainstream-tier, LANG-06). This is a [SUS] community-maintained grammar (T-05-SC), pinned at the tree-sitter-grammars/tree-sitter-kotlin v1.1.0 proper semver tag (root module, not a bindings/go subpath) after human-verify approval — replaces the originally-approved fwcd source, which does not build. Carries an external C scanner.

func NewPHPParser

func NewPHPParser() (*CGoParser, error)

NewPHPParser returns a CGoParser configured for the PHP grammar (mainstream-tier, LANG-06). Uses the `php/src` grammar accessor (LanguagePHP), not the sibling `php_only/src` grammar (LanguagePHPOnly) — the tree-sitter-php module ships both in the same bindings/go package. Carries an external C scanner (PHP tag-switching).

func NewPythonParser

func NewPythonParser() (*CGoParser, error)

NewPythonParser returns a CGoParser configured for the Python grammar. Python exercises the external C scanner path (its INDENT/DEDENT tokenizer), the crash-isolation dimension the Plan 01-07 spike measures.

func NewRubyParser

func NewRubyParser() (*CGoParser, error)

NewRubyParser returns a CGoParser configured for the Ruby grammar (mainstream-tier, LANG-06). Carries an external C scanner (heredocs).

func NewRustParser

func NewRustParser() (*CGoParser, error)

NewRustParser returns a CGoParser configured for the Rust grammar (mainstream-tier, LANG-06). Carries an external C scanner (raw strings).

func NewSwiftParser

func NewSwiftParser() (*CGoParser, error)

NewSwiftParser returns a CGoParser configured for the Swift grammar (mainstream-tier, LANG-06). This is a [SUS] community-maintained grammar (T-05-SC) pinned by exact commit pseudo-version after human-verify approval — never @latest. Carries an external C scanner.

func NewTSXParser

func NewTSXParser() (*CGoParser, error)

NewTSXParser returns a CGoParser configured for the TSX grammar (priority-4, LANG-05) — the JSX-aware sibling of NewTypeScriptParser, both bindings shipped by the same tree-sitter-typescript module.

func NewTypeScriptParser

func NewTypeScriptParser() (*CGoParser, error)

NewTypeScriptParser returns a CGoParser configured for the TypeScript grammar (priority-4, LANG-05). Carries an external C scanner. The tree-sitter-typescript module ships two grammars in one repo (typescript/ and tsx/ subdirs) — this constructor uses the typescript accessor; see NewTSXParser for the sibling .tsx grammar.

func (*CGoParser) Close

func (p *CGoParser) Close() error

Close frees the underlying C parser's allocations. Safe to call once or concurrently; repeat calls are a no-op.

func (*CGoParser) Parse

func (p *CGoParser) Parse(source []byte, oldTree *parser.Tree) (*parser.Tree, error)

Parse enforces the shared size ceiling (parser.MaxSourceBytes) before handing bytes to the underlying C parser (Security Domain V5 / threat T-01-03), then performs an incremental reparse via the tree-sitter bindings if oldTree is non-nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL