multilang

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package multilang is the spike's tree-sitter-backed contract extractor. It answers question 5 of the spike: whether a wasm-backed extractor can honor the same contract as internal/contract — never return an error, treat an unparseable or oversized file as "no fingerprint", respect MaxSourceBytes, MaxSymbols and MaxSignatureRunes, and apply the deny wire-gate to every derived signature before it is published.

It deliberately reuses internal/contract for the hashing, normalization, sorting and gating so the spike measures the parser, not a reimplementation of the fingerprint format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

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

Extractor owns one wasm runtime per language, each created on first use.

Lazy per-language loading is the point (ADR-063): compiling every grammar up front costs startup time and resident memory proportional to how many languages Overgent supports, not to how many the member's repository actually contains. A Go and TypeScript repository never pays for the C# grammar.

It is not safe for concurrent use; callers serialize, and the underlying runtimes serialize anyway.

func New

func New(loader func(string) ([]byte, bool, error), interpreter bool) *Extractor

New prepares an extractor. It deliberately loads nothing: no wasm is compiled until a file of that language is actually fingerprinted, so constructing an extractor is free even on a platform where the runtime will later turn out to be unavailable.

loader resolves a tree-sitter language name to its module bytes. Its second result reports whether a module for that language exists at all, which is distinct from failing to load one that does.

func (*Extractor) Close

func (e *Extractor) Close(ctx context.Context) error

Close releases every runtime that was actually created. It reports the first failure but always attempts all of them, so one stuck runtime cannot leak the rest.

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, path string, source []byte, deny func(string) bool) (fingerprint.File, bool)

Extract mirrors fingerprint.Extract for a tree-sitter language. It never returns an error: a path with no grammar, a source over MaxSourceBytes, a parse containing ERROR or MISSING nodes, an unavailable runtime, and any wasm failure all yield (File{}, false), which callers read as "no fingerprint".

func (*Extractor) Fingerprintable

func (e *Extractor) Fingerprintable(path string) bool

Fingerprintable reports whether this extractor has rules for the path. It does not load anything, so it stays cheap and stays true on a platform where extraction will fail: a platform gap must never be reported as a language gap.

func (*Extractor) Loaded

func (e *Extractor) Loaded() []string

Loaded reports which languages have actually been compiled. It exists so the laziness can be asserted by a test rather than assumed.

Jump to

Keyboard shortcuts

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