syntaxfacts

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package syntaxfacts projects opt-in signature and argument facts from grammar-owned rows. It depends on node readers, rather than the parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidCallArgumentRule

func ValidCallArgumentRule(g declarationfacts.Grammar, rule CallArgumentRule) bool

ValidCallArgumentRule checks all referenced grammar data.

func ValidSignatureRule

func ValidSignatureRule(g declarationfacts.Grammar, rule SignatureRule) bool

ValidSignatureRule checks all referenced grammar data.

Types

type Arguments

type Arguments[N comparable] struct {
	// contains filtered or unexported fields
}

Arguments holds immutable call-argument instructions.

func CompileArguments

func CompileArguments[N comparable](g declarationfacts.Grammar, r declarationfacts.Reader[N], rules []CallArgumentRule) *Arguments[N]

CompileArguments owns rows. No valid rows returns nil.

func (*Arguments[N]) Extract

func (p *Arguments[N]) Extract(root N, source []byte, accept func(N, []byte) bool, dst *[]CallArgumentFact)

Extract appends arguments when accept recognizes the same call as CallRef, or when the row is Standalone. It visits nested calls independently; each call's arguments are in source order.

type CallArgumentFact

type CallArgumentFact struct {
	CallStartByte, CallEndByte uint32
	Index                      int
	Kind, NodeType             string
	StartByte, EndByte         uint32
	Spread                     bool
}

CallArgumentFact projects a direct call argument. Ordinary call ranges join CallRef. JavaScript, TypeScript and TSX new_expression arguments are standalone: their call range is the new expression range and joins no CallRef. Spread keeps the wrapper's real NodeType and full range, including the ellipsis; Kind classifies the wrapped operand. Zero-argument calls produce no entries.

type CallArgumentRule

type CallArgumentRule struct {
	NodeType, ArgumentsField, ListNodeType, SpreadNodeType string
	Kinds                                                  []ExpressionKindRule
	SpreadNodeTypes                                        []string
	// Standalone emits arguments with the matched node range and no CallRef join.
	Standalone bool
}

CallArgumentRule selects direct named children of a call's argument list. Comments are excluded. SpreadNodeType and SpreadNodeTypes wrap one operand.

type ExpressionKindRule

type ExpressionKindRule struct{ NodeType, Kind string }

ExpressionKindRule maps a grammar node type to a normalized expression kind. Unmapped named nodes are "other".

type ParameterFact

type ParameterFact struct {
	Name, Type                 string
	NameStartByte, NameEndByte uint32
	TypeStartByte, TypeEndByte uint32
	Variadic, Pointer          bool
	StartByte, EndByte         uint32
	Optional                   bool `json:",omitempty"`
}

ParameterFact preserves one parameter name and its exact source type. Unnamed entries have empty Name and zero name ranges. Type excludes the variadic ellipsis; the declaration range includes it. Pointer is receivers only. A parameter without a written type has empty Type and zero type ranges. Optional marks a parameter that the source declares optional with "?"; it is not set for defaults.

type ParameterRule

type ParameterRule struct {
	NodeType, NameField, NameNodeType, TypeField string
	Variadic                                     bool
	TypeOptional, Optional                       bool
	VariadicNodeTypes                            []string
	UnwrapVariadic                               bool
	NameSelf                                     bool
	NameNodeTypes                                []string
	AnonymousPatterns                            []string
}

ParameterRule describes one direct, possibly grouped parameter declaration.

NameSelf uses the declaration as its name; other name/type selectors must be empty. Otherwise NameField selects direct children; an empty field selects NameNodeType and NameNodeTypes children. AnonymousPatterns preserve unnamed positions. Missing names stay unnamed when a type selector is configured. TypeField may be empty; TypeOptional also permits an absent configured field. Variadic marks the whole row. VariadicNodeTypes marks selected name wrappers; UnwrapVariadic strips their wrapper for the name (rest patterns), otherwise the name retains its spelling (Python stars). Optional is for TypeScript "?".

type SignatureFact

type SignatureFact struct {
	Lang, Kind, Name, Container, NodeType          string
	StartByte, EndByte, NameStartByte, NameEndByte uint32
	Receiver, TypeParameters, Parameters, Results  []ParameterFact
}

SignatureFact describes a declared function or method. Parameter slices are independently allocated for each extraction, including ExtractInto.

type SignatureRule

type SignatureRule struct {
	NodeType, Kind, NameField, NameNodeType                           string
	ReceiverField, TypeParametersField, ParametersField, ResultsField string
	PointerNodeType                                                   string
	ListNodeTypes, Ancestors                                          []string
	Parameters                                                        []ParameterRule
	TypeNames                                                         []declarationfacts.TypeNameRule
	ContainerPath                                                     []declarationfacts.ContainerRule
	TypeWrapperNodeTypes                                              []string
	DelegateField                                                     string
	DelegateNodeTypes                                                 []string
	SingleParameterField                                              string
	RequireContainer                                                  bool
	ParentChildField, ParentChildNodeType                             string
}

SignatureRule selects a declaration and its direct signature fields. ListNodeTypes distinguish parameter lists from a single unnamed result type. TypeNames strip receiver wrappers; ContainerPath names interface owners. TypeWrapperNodeTypes lists node types, such as a type annotation, that wrap a type: the fact keeps the wrapper's single named child as the type. DelegateField and DelegateNodeTypes, set together, read the type parameters, parameters and results from the child in DelegateField (for example the function value bound by a variable declarator) while the fact still names and spans the matched node. SingleParameterField names a field holding one bare parameter name instead of a list. ParentChildField and ParentChildNodeType, set together, require the direct parent to have a direct child in that field with that node type. RequireContainer skips a match unless ContainerPath resolves an owner. All referenced grammar data must resolve or the entire row is dropped.

type Signatures

type Signatures[N comparable] struct {
	// contains filtered or unexported fields
}

Signatures holds immutable compiled instructions for declarations.

func CompileSignatures

func CompileSignatures[N comparable](g declarationfacts.Grammar, r declarationfacts.Reader[N], rules []SignatureRule) *Signatures[N]

CompileSignatures resolves and owns rows. An empty valid set returns nil.

func (*Signatures[N]) Extract

func (p *Signatures[N]) Extract(root N, source []byte, dst *[]SignatureFact)

Extract appends signatures in source-tree order.

Jump to

Keyboard shortcuts

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