rules

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 2 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

This section is empty.

Variables

This section is empty.

Functions

func IsBlock

func IsBlock(nodeType string) bool

IsBlock reports whether nodeType is configured as a block in any language rule set.

func IsCall

func IsCall(nodeType string) bool

IsCall reports whether nodeType is configured as a call in any language rule set.

func IsClosure added in v0.8.0

func IsClosure(nodeType string) bool

IsClosure reports whether nodeType is configured as a closure in any language rule set.

func IsComment

func IsComment(nodeType string) bool

IsComment reports whether nodeType is configured as a comment in any language rule set.

func IsContainerDeclaration added in v0.8.0

func IsContainerDeclaration(nodeType string) bool

IsContainerDeclaration reports whether nodeType is configured as a container declaration in any language rule set.

func IsDeclaration

func IsDeclaration(nodeType string) bool

IsDeclaration reports whether nodeType is configured as a declaration in any language rule set.

func IsDelimiter

func IsDelimiter(nodeType, label string) bool

IsDelimiter reports whether nodeType or label is a delimiter token (semicolon or comma).

func IsFlattened

func IsFlattened(nodeType string) bool

IsFlattened reports whether nodeType is configured as flattened in any language rule set.

func IsFlattenedType

func IsFlattenedType(nodeType string) bool

IsFlattenedType reports whether nodeType is configured as flattened in any language rule set.

func IsIdentifier

func IsIdentifier(nodeType string) bool

IsIdentifier reports whether nodeType is configured as an identifier in any language rule set.

func IsIndexed added in v0.8.0

func IsIndexed(nodeType string) bool

IsIndexed reports whether nodeType is configured as an indexed container in any language rule set.

func IsKeyword

func IsKeyword(nodeType, label string) bool

IsKeyword reports whether nodeType or label is configured as a keyword in any language rule set.

func IsLocalVarDeclaration added in v0.8.0

func IsLocalVarDeclaration(nodeType string) bool

IsLocalVarDeclaration reports whether nodeType is configured as a local variable declaration in any language rule set.

func IsOperatorLiteral

func IsOperatorLiteral(nodeType string) bool

IsOperatorLiteral reports whether nodeType is configured as an operator literal in any language rule set.

func IsPunctuation added in v0.8.0

func IsPunctuation(token string) bool

IsPunctuation reports whether a string is a structural punctuation token in any language rule set.

func IsScaffolding

func IsScaffolding(nodeType string) bool

IsScaffolding reports whether nodeType is configured as scaffolding in any language rule set.

func IsType added in v0.8.0

func IsType(nodeType string) bool

IsType reports whether nodeType is a type annotation or type expression in any language rule set.

func IsWrapper added in v0.8.0

func IsWrapper(nodeType string) bool

IsWrapper reports whether nodeType is configured as a wrapper in any language rule set.

Types

type LanguageKind added in v0.8.0

type LanguageKind uint8

LanguageKind classifies grammars into high-level parsing and diffing categories.

const (
	// KindCode is for general programming languages (Go, Rust, Python, C++, etc.).
	KindCode LanguageKind = iota
	// KindData is for structured key-value formats (JSON, YAML, TOML).
	KindData
	// KindMarkup is for markup and styling languages (HTML, CSS).
	KindMarkup
)

type Rules

type Rules struct {
	Kind                  LanguageKind
	Flattened             []string
	Ignored               []string
	Aliased               map[string]string
	LabelIgnored          []string
	Scaffolding           []string
	Keywords              []string
	Declarations          []string
	Identifiers           []string
	Blocks                []string
	Wrappers              []string
	Pairs                 []string
	Unordered             []string
	EquivalentTypes       [][]string
	Comments              []string
	Calls                 []string
	ScopedDeclarations    []string
	Indexed               []string // Subscript nodes with prefix receivers (e.g. arr[i]).
	LocalVarDeclarations  []string
	ContainerDeclarations []string // Major declaration scope boundaries (functions, classes, structs, etc.).
	Closures              []string // Anonymous functions, lambdas, and callbacks.
	Types                 []string // Type annotations and type expressions.
	// contains filtered or unexported fields
}

Rules configures language-specific AST transformations and node matching.

func Get

func Get(lang string) *Rules

Get returns the compiled AST rules for a language, or a default empty rule set if none exist.

func (*Rules) Alias

func (r *Rules) Alias(nodeType, label string) (string, bool)

Alias returns the replacement node type if one exists for the label or node type.

func (*Rules) AreTypesEquivalent

func (r *Rules) AreTypesEquivalent(t1, t2 string) bool

AreTypesEquivalent reports whether t1 and t2 belong to the same equivalent_types group.

func (*Rules) CompileSets

func (r *Rules) CompileSets()

CompileSets builds the internal lookup sets for fast querying.

func (*Rules) DefaultRootType

func (r *Rules) DefaultRootType() string

DefaultRootType returns the top-level root AST node type for the language.

func (*Rules) GetKind added in v0.8.0

func (r *Rules) GetKind() LanguageKind

GetKind returns the language category (KindCode, KindData, or KindMarkup).

func (*Rules) IsBlock

func (r *Rules) IsBlock(nodeType string) bool

IsBlock checks if this node type is a code block.

func (*Rules) IsCall

func (r *Rules) IsCall(nodeType string) bool

IsCall reports whether nodeType is a function, method, or macro invocation.

func (*Rules) IsClosure added in v0.8.0

func (r *Rules) IsClosure(nodeType string) bool

IsClosure reports whether nodeType is an anonymous function, closure, or lambda callback.

func (*Rules) IsComment

func (r *Rules) IsComment(nodeType string) bool

IsComment reports whether nodeType is a comment in the language grammar.

func (*Rules) IsContainerDeclaration added in v0.8.0

func (r *Rules) IsContainerDeclaration(nodeType string) bool

IsContainerDeclaration reports whether nodeType is a major container declaration (such as a function, method, class, struct, interface, trait, or enum).

func (*Rules) IsDeclaration

func (r *Rules) IsDeclaration(nodeType string) bool

IsDeclaration reports whether nodeType is a declaration.

func (*Rules) IsDelimiter

func (r *Rules) IsDelimiter(nodeType, label string) bool

IsDelimiter reports whether nodeType or label is a delimiter token (semicolon or comma).

func (*Rules) IsFlattened

func (r *Rules) IsFlattened(nodeType string) bool

IsFlattened checks if intermediate nodes of this type should merge into their parent.

func (*Rules) IsIdentifier

func (r *Rules) IsIdentifier(nodeType string) bool

IsIdentifier reports whether nodeType is an identifier token.

func (*Rules) IsIgnored

func (r *Rules) IsIgnored(nodeType, label string) bool

IsIgnored checks if a node type or label is filtered out when building the AST.

func (*Rules) IsIndexed added in v0.8.0

func (r *Rules) IsIndexed(nodeType string) bool

IsIndexed reports whether nodeType is a subscript container with a prefix receiver.

func (*Rules) IsKeyword

func (r *Rules) IsKeyword(nodeType, label string) bool

IsKeyword checks if a node type or label is a language keyword.

func (*Rules) IsLabelIgnored

func (r *Rules) IsLabelIgnored(nodeType string) bool

IsLabelIgnored checks if node labels should be dropped for this type.

func (*Rules) IsLocalVarDeclaration added in v0.8.0

func (r *Rules) IsLocalVarDeclaration(nodeType string) bool

IsLocalVarDeclaration reports whether nodeType is a local variable declaration.

func (*Rules) IsOperatorLiteral

func (r *Rules) IsOperatorLiteral(nodeType string) bool

IsOperatorLiteral reports whether nodeType is an aliased operator literal.

func (*Rules) IsPair added in v0.8.0

func (r *Rules) IsPair(nodeType string) bool

IsPair checks if nodeType represents a key-value property pair.

func (*Rules) IsPunctuation added in v0.8.0

func (r *Rules) IsPunctuation(token string) bool

IsPunctuation reports whether a string is a structural punctuation token (braces, brackets, parentheses, delimiters).

func (*Rules) IsScaffolding

func (r *Rules) IsScaffolding(nodeType string) bool

IsScaffolding reports whether nodeType is scaffolding.

func (*Rules) IsScopedDeclaration

func (r *Rules) IsScopedDeclaration(nodeType string) bool

IsScopedDeclaration reports whether nodeType is a declaration with an explicit signature receiver or scope.

func (*Rules) IsType added in v0.8.0

func (r *Rules) IsType(nodeType string) bool

IsType reports whether nodeType is a type annotation or type expression in the language.

func (*Rules) IsUnordered

func (r *Rules) IsUnordered(nodeType string) bool

IsUnordered checks if child order doesn't matter for this container.

func (*Rules) IsWrapper added in v0.8.0

func (r *Rules) IsWrapper(nodeType string) bool

IsWrapper reports whether nodeType is a syntactic wrapper (e.g. parentheses, generics, subscripts).

Jump to

Keyboard shortcuts

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