syntax

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultManifestPath is the repository-relative grammar manifest path.
	DefaultManifestPath = "grammars/manifest.json"
)

Variables

View Source
var (
	// ErrParserManagerClosed indicates that no new parse can start.
	ErrParserManagerClosed = errors.New("parser manager is closed")
	// ErrUnsupportedLanguage indicates a language without a pinned grammar.
	ErrUnsupportedLanguage = errors.New("unsupported language")
	// ErrSyntaxTreeClosed indicates an operation on a released tree.
	ErrSyntaxTreeClosed = errors.New("syntax tree is closed")
)

Functions

This section is empty.

Types

type CandidateKind

type CandidateKind string

CandidateKind is a syntactic category, not semantic evidence.

const (
	CandidateDeclaration CandidateKind = "DECLARATION"
	CandidateImport      CandidateKind = "IMPORT"
	CandidateExport      CandidateKind = "EXPORT"
	CandidateCall        CandidateKind = "CALL"
	CandidateIdentifier  CandidateKind = "IDENTIFIER"
	CandidateClass       CandidateKind = "CLASS"
	CandidateInterface   CandidateKind = "INTERFACE"
	CandidateMethod      CandidateKind = "METHOD"
)

type ChangeClass

type ChangeClass string

ChangeClass is the conservative syntactic impact classification.

const (
	ChangeBodyOnly           ChangeClass = "BODY_ONLY"
	ChangeSignatureChanged   ChangeClass = "SIGNATURE_CHANGED"
	ChangeImportsChanged     ChangeClass = "IMPORTS_CHANGED"
	ChangeExportsChanged     ChangeClass = "EXPORTS_CHANGED"
	ChangeDeclarationAdded   ChangeClass = "DECLARATION_ADDED"
	ChangeDeclarationRemoved ChangeClass = "DECLARATION_REMOVED"
	ChangeUnknown            ChangeClass = "UNKNOWN"
)

type ChangeClassification

type ChangeClassification struct {
	Class         ChangeClass
	ChangedRanges []SyntaxRange
}

ChangeClassification combines one conservative class with the ranges that caused the comparison. It contains no semantic relationship or edge.

func ClassifyChanges

func ClassifyChanges(previous, current SyntaxInventory, changedRanges []SyntaxRange) ChangeClassification

ClassifyChanges compares two syntax inventories. Imports and exports take precedence; declaration additions/removals precede signature changes, and a change with no structural candidate difference is BODY_ONLY only when changed ranges provide evidence.

type GrammarManifest

type GrammarManifest struct {
	SchemaVersion int             `json:"schema_version"`
	ArchiveFormat string          `json:"archive_format"`
	Grammars      []GrammarSource `json:"grammars"`
}

GrammarManifest pins every grammar source used by Kivgraph.

func LoadManifest

func LoadManifest(manifestPath string) (GrammarManifest, error)

LoadManifest reads and validates a grammar manifest from path.

func (GrammarManifest) Validate

func (manifest GrammarManifest) Validate() error

Validate checks the schema and reproducibility fields of a grammar manifest.

type GrammarSource

type GrammarSource struct {
	Name       string `json:"name"`
	Repository string `json:"repository"`
	Version    string `json:"version"`
	Commit     string `json:"commit"`
	SourcePath string `json:"source_path"`
	ArchiveURL string `json:"archive_url"`
	SHA256     string `json:"sha256"`
	License    string `json:"license"`
	LicenseURL string `json:"license_url"`
}

GrammarSource identifies one language grammar inside a pinned source archive.

type InputEdit

type InputEdit struct {
	StartByte   uint
	OldEndByte  uint
	NewEndByte  uint
	StartPoint  InputPoint
	OldEndPoint InputPoint
	NewEndPoint InputPoint
}

InputEdit describes one source edit for incremental parsing.

type InputPoint

type InputPoint struct {
	Row    uint
	Column uint
}

InputPoint is a zero-based row and byte-column position in a source file.

type Language

type Language string

Language identifies one of the grammars pinned in grammars/manifest.json.

const (
	LanguageTypeScript Language = "typescript"
	LanguageTSX        Language = "tsx"
	LanguageJavaScript Language = "javascript"
	LanguageGo         Language = "go"
	LanguageRust       Language = "rust"
)

type ParserError

type ParserError struct {
	Kind     ParserErrorKind
	Language Language
	Err      error
}

ParserError describes a classified parser-manager failure.

func (*ParserError) Error

func (err *ParserError) Error() string

func (*ParserError) Unwrap

func (err *ParserError) Unwrap() error

type ParserErrorKind

type ParserErrorKind string

ParserErrorKind classifies manager and parser failures. Syntax errors remain in SyntaxTree and are intentionally not returned as ParserError values.

const (
	ParserErrorCanceled            ParserErrorKind = "CANCELED"
	ParserErrorManagerClosed       ParserErrorKind = "MANAGER_CLOSED"
	ParserErrorUnsupportedLanguage ParserErrorKind = "UNSUPPORTED_LANGUAGE"
	ParserErrorInitialization      ParserErrorKind = "PARSER_INITIALIZATION"
	ParserErrorParse               ParserErrorKind = "PARSE"
	ParserErrorInvalidInput        ParserErrorKind = "INVALID_INPUT"
	ParserErrorTreeClosed          ParserErrorKind = "TREE_CLOSED"
)

type ParserManager

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

ParserManager owns reusable parsers and bounds native parser concurrency.

func NewParserManager

func NewParserManager(maxConcurrent int) (*ParserManager, error)

NewParserManager creates a manager with at most maxConcurrent parse calls in flight. Parsers are created lazily and reused by language.

func (*ParserManager) Close

func (manager *ParserManager) Close() error

Close waits for in-flight parses, closes every native parser, and prevents new work. It is safe to call more than once.

func (*ParserManager) Parse

func (manager *ParserManager) Parse(ctx context.Context, language Language, source []byte) (*SyntaxTree, error)

Parse parses source and returns a tree even when the source has syntax errors. Syntax errors are observable through SyntaxTree.HasError.

func (*ParserManager) ParseIncremental

func (manager *ParserManager) ParseIncremental(ctx context.Context, language Language, source []byte, previous *SyntaxTree, edit InputEdit) (*SyntaxTree, error)

ParseIncremental applies edit to a private clone of previous and parses the new source. The caller's previous tree remains usable and unchanged.

func (*ParserManager) ParseIncrementalWithRanges

func (manager *ParserManager) ParseIncrementalWithRanges(ctx context.Context, language Language, source []byte, previous *SyntaxTree, edit InputEdit) (*SyntaxTree, []SyntaxRange, error)

ParseIncrementalWithRanges is ParseIncremental plus the structural ranges that Tree-sitter changed between the previous and new trees.

func (*ParserManager) Stats

func (manager *ParserManager) Stats() ParserManagerStats

Stats reports parser reuse and concurrency state.

type ParserManagerStats

type ParserManagerStats struct {
	ActiveParsers int
	IdleParsers   int
	TotalParsers  int
	MaxConcurrent int
}

ParserManagerStats is a point-in-time view of native parser ownership.

type SyntaxCandidate

type SyntaxCandidate struct {
	Kind       CandidateKind
	Name       string
	NodeKind   string
	Signature  string
	StartByte  uint
	EndByte    uint
	StartPoint InputPoint
	EndPoint   InputPoint
}

SyntaxCandidate records one syntax node classified as a candidate. It never represents an exact symbol, provider, or semantic edge.

func SortCandidates

func SortCandidates(candidates []SyntaxCandidate) []SyntaxCandidate

SortCandidates returns a stable source-order copy for callers that combine inventories from multiple trees.

type SyntaxInventory

type SyntaxInventory struct {
	Language   Language
	HasErrors  bool
	Candidates []SyntaxCandidate
}

SyntaxInventory is the deterministic syntactic output for one source tree.

func BuildInventory

func BuildInventory(tree *SyntaxTree, source []byte) (SyntaxInventory, error)

BuildInventory extracts syntactic candidates from a parsed source tree. Candidate classifications are intentionally independent of semantic APIs.

func (SyntaxInventory) List

func (inventory SyntaxInventory) List() []SyntaxCandidate

List returns a copy of the inventory candidates.

type SyntaxRange

type SyntaxRange struct {
	StartByte  uint
	EndByte    uint
	StartPoint InputPoint
	EndPoint   InputPoint
}

SyntaxRange is a changed structural range returned by incremental parsing.

func SortChangedRanges

func SortChangedRanges(ranges []SyntaxRange) []SyntaxRange

SortChangedRanges returns an independent source-order copy for downstream invalidation code.

type SyntaxTree

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

SyntaxTree owns one Tree-sitter tree. Call Close when the tree is no longer needed; a closed tree cannot be used for inventory or incremental parsing.

func (*SyntaxTree) ChangedRanges

func (tree *SyntaxTree) ChangedRanges(other *SyntaxTree) ([]SyntaxRange, error)

ChangedRanges compares this tree as the old tree against other.

func (*SyntaxTree) Close

func (tree *SyntaxTree) Close()

Close releases the native tree. Close is idempotent.

func (*SyntaxTree) Edit

func (tree *SyntaxTree) Edit(edit InputEdit) error

Edit updates this tree's byte and point coordinates for a later parse.

func (*SyntaxTree) HasError

func (tree *SyntaxTree) HasError() (bool, error)

HasError reports whether Tree-sitter found syntax errors in the tree.

func (*SyntaxTree) Language

func (tree *SyntaxTree) Language() Language

Language returns the grammar used to build the tree.

func (*SyntaxTree) RootNode

func (tree *SyntaxTree) RootNode() (*tree_sitter.Node, error)

RootNode returns the root node while the tree remains open.

func (*SyntaxTree) SExpression

func (tree *SyntaxTree) SExpression() (string, error)

SExpression returns the native S-expression representation of the tree.

Jump to

Keyboard shortcuts

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