rules

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 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 IsAssignment added in v0.12.0

func IsAssignment(nodeType string) bool

IsAssignment reports whether nodeType is configured as an assignment in any language rule set.

func IsAttribute added in v0.16.0

func IsAttribute(nodeType string) bool

IsAttribute reports whether nodeType is configured as an attribute or decorator in any language rule set.

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 IsCaseClause added in v0.10.0

func IsCaseClause(nodeType string) bool

IsCaseClause reports whether nodeType is configured as a case clause in any language rule set.

func IsClosingDelimiter added in v0.12.0

func IsClosingDelimiter(token string) bool

IsClosingDelimiter checks if token closes a container under any registered language rules.

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 IsContainer added in v0.12.0

func IsContainer(nodeType string) bool

IsContainer reports whether any registered language treats nodeType as a container.

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 IsDeclarator added in v0.16.0

func IsDeclarator(nodeType string) bool

IsDeclarator reports whether nodeType is configured as a declarator in any language rule set.

func IsDelimitedContainer added in v0.9.0

func IsDelimitedContainer(nodeType string) bool

IsDelimitedContainer reports whether nodeType is a delimited container in any registered language.

func IsDelimiter

func IsDelimiter(nodeType, label string) bool

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

func IsExpression added in v0.10.0

func IsExpression(nodeType string) bool

IsExpression reports whether nodeType is configured as an expression in any language rule set.

func IsExpressionStatement added in v0.10.0

func IsExpressionStatement(nodeType string) bool

IsExpressionStatement reports whether nodeType represents an expression statement.

func IsFlattened

func IsFlattened(nodeType string) bool

IsFlattened 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 IsImport added in v0.16.0

func IsImport(nodeType string) bool

IsImport reports whether nodeType is configured as an import 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 IsJumpStatement added in v0.9.0

func IsJumpStatement(nodeType string) bool

IsJumpStatement reports whether nodeType is configured as a jump statement 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 IsOpeningDelimiter added in v0.12.0

func IsOpeningDelimiter(token string) bool

IsOpeningDelimiter checks if token opens a container under any registered language rules.

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 IsSelector added in v0.17.0

func IsSelector(nodeType string) bool

IsSelector reports whether nodeType is a selector/field access in any registered language.

func IsSentinel added in v0.11.0

func IsSentinel(label string) bool

IsSentinel reports whether label is a sentinel in any language rule set.

func IsStatement added in v0.12.0

func IsStatement(nodeType string) bool

IsStatement reports whether nodeType represents a statement in any language rule set.

func IsTrailingSeparator added in v0.12.0

func IsTrailingSeparator(token string) bool

IsTrailingSeparator checks if token is an item separator in any registered language.

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 Rules

type Rules struct {
	Flattened             []string
	Ignored               []string
	Aliased               map[string]string
	Scaffolding           []string
	Keywords              []string
	Declarations          []string
	Identifiers           []string
	Blocks                []string
	Wrappers              []string
	Pairs                 []string
	Unordered             []string
	EquivalentTypes       [][]string
	Comments              []string
	Calls                 []string
	Indexed               []string // Subscript nodes with prefix receivers (e.g. arr[i]).
	LocalVarDeclarations  []string
	Assignments           []string // Assignment expressions or statements (e.g. assignment_expression, assignment_statement).
	ContainerDeclarations []string // Major declaration scope boundaries (functions, classes, structs, etc.).
	Closures              []string // Anonymous functions, lambdas, and callbacks.
	Types                 []string // Type annotations and type expressions.
	JumpStatements        []string // Control-flow exit statements (return, break, continue, goto, throw, raise).
	TerminalCalls         []string // Dotted callee paths for execution-terminating calls (os.Exit, sys.exit, panic, etc.).
	DelimitedContainers   []string // Containers whose elements are separated by delimiters (like commas).
	Selectors             []string // Member or field access expressions (e.g. selector_expression, field_expression, member_expression, attribute, field_access).
	Expressions           []string // Expression container node types.
	CaseClauses           []string // Arms that hold statements directly without curly braces (case, default, when, match_arm).
	Tags                  []string // Markup elements and tags (e.g. element, start_tag, jsx_element, jsx_opening_element).
	Sentinels             []string // Built-in nil, null, and boolean identifiers (e.g. NULL, None, undefined).
	Statements            []string // Standalone statement and statement-level declaration node types.
	Imports               []string // Import and include declaration node types.
	Attributes            []string // Decorators, attributes, and annotations on declarations (e.g. attribute_item).
	Declarators           []string // Declarator node types holding declaration identifiers and parameters (e.g. function_declarator).
	OpeningDelimiters     []string // Container openers; defaults to standard brackets, braces, and angles unless overridden per language.
	ClosingDelimiters     []string // Matching container closers used to locate headers and closing delimiter spans.
	Separators            []string // Punctuation between sibling elements (commas, match arrows, colons) absorbed as trailing trivia.

	// SignificantWhitespace reports whether indentation defines blocks and scope (as in Python).
	SignificantWhitespace bool
	// 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) IsAssignment added in v0.12.0

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

IsAssignment reports whether nodeType is an assignment expression or statement.

func (*Rules) IsAttribute added in v0.16.0

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

IsAttribute reports whether nodeType is an attribute or decorator in the language.

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) IsCaseClause added in v0.10.0

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

IsCaseClause reports whether nodeType is a branch or pattern arm in a switch/match/select statement.

func (*Rules) IsClosingDelimiter added in v0.12.0

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

IsClosingDelimiter checks if token marks the end of an enclosed body or argument list.

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) IsContainer added in v0.12.0

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

IsContainer reports whether nodeType wraps children (block, wrapper, unordered, or indexed).

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) IsDeclarator added in v0.16.0

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

IsDeclarator reports whether nodeType is a declarator holding declaration identifiers and parameters.

func (*Rules) IsDelimitedContainer added in v0.9.0

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

IsDelimitedContainer reports whether nodeType is a comma-delimited container (like an argument list or array).

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) IsExpression added in v0.10.0

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

IsExpression reports whether nodeType represents an expression node.

func (*Rules) IsExpressionStatement added in v0.10.0

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

IsExpressionStatement reports whether nodeType represents an expression statement.

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) IsImport added in v0.16.0

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

IsImport reports whether nodeType is an import or include declaration.

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) IsJumpStatement added in v0.9.0

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

IsJumpStatement reports whether nodeType is an early-exit jump statement (such as return, break, continue, goto, throw, raise, yield).

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) IsLocalVarDeclaration added in v0.8.0

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

IsLocalVarDeclaration reports whether nodeType is a local variable declaration.

func (*Rules) IsOpeningDelimiter added in v0.12.0

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

IsOpeningDelimiter checks if token marks the start of a block, wrapper, or parameter list.

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) IsSelector added in v0.17.0

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

IsSelector reports whether nodeType is a member or field access expression.

func (*Rules) IsSentinel added in v0.11.0

func (r *Rules) IsSentinel(label string) bool

IsSentinel reports whether label is a built-in sentinel identifier (like NULL, None, or undefined).

func (*Rules) IsStatement added in v0.12.0

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

IsStatement reports whether nodeType represents a statement or statement-level declaration.

func (*Rules) IsTag added in v0.10.0

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

IsTag reports whether nodeType represents a markup element or tag.

func (*Rules) IsTerminalCallPath added in v0.9.0

func (r *Rules) IsTerminalCallPath(calleePath string) bool

IsTerminalCallPath reports whether calleePath matches an execution-terminating call. The path is a dot-joined identifier (e.g. "os.Exit", "sys.exit", "panic").

func (*Rules) IsTrailingSeparator added in v0.12.0

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

IsTrailingSeparator checks if token acts as a delimiter between sibling items in lists or match arms.

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