query

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AncestorsOfType added in v0.6.3

func AncestorsOfType(node *sitter.Node, aType string) []*sitter.Node

func Collect

func Collect[T any](f NextFunc[T]) []T

func FirstAncestorOfType

func FirstAncestorOfType(node *sitter.Node, ptype string) *sitter.Node

func FirstChildOfType added in v0.6.3

func FirstChildOfType(node *sitter.Node, ctype string) *sitter.Node

func NodeContentEquals

func NodeContentEquals(node *sitter.Node, s string) bool

func NodeContentOrEmpty added in v0.6.3

func NodeContentOrEmpty(node *sitter.Node) string

func NodeContentRegex

func NodeContentRegex(node *sitter.Node, regex *regexp.Regexp) bool

func NodeContentStartWith

func NodeContentStartWith(node *sitter.Node, s string) bool

Types

type AllOf

type AllOf[T any] []Predicate[T]

func (AllOf[T]) Test

func (a AllOf[T]) Test(input T) bool

type Cache

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

Cache stores queries by language ID in a threadsafe manner

func (*Cache) AddQuery

func (m *Cache) AddQuery(lang core.LanguageId, name string, query *sitter.Query)

AddQuery adds a new query to the cache

func (*Cache) GetQuery

func (m *Cache) GetQuery(lang core.LanguageId, name string) (*sitter.Query, bool)

GetQuery gets the *sitter.Query instance associated with the provided language ID and name combination

type HasContent

type HasContent string

func (HasContent) Test

func (hc HasContent) Test(node *sitter.Node) bool

type HasParent

type HasParent struct {
	With Predicate[*sitter.Node]
}

func (HasParent) Test

func (hp HasParent) Test(node *sitter.Node) bool

type Is

type Is[T any] bool

func (Is[T]) Test

func (a Is[T]) Test(_ T) bool

type MatchNodes

type MatchNodes = map[string]*sitter.Node

type NextFunc

type NextFunc[T any] func() (T, bool)

func Select

func Select[T any](query NextFunc[MatchNodes], selector Selector[T]) NextFunc[T]

func SelectIf

func SelectIf[T any](query NextFunc[MatchNodes], selector Selector[T], predicate Predicate[MatchNodes]) NextFunc[T]

type NextMatchFunc

type NextMatchFunc = NextFunc[MatchNodes]

func Exec

Exec returns a function that acts as an iterator, each call will loop over the next match lazily and populate the results map with a mapping of field name as defined in the query to mapped node.

type Param

type Param struct {
	Named   string
	Matches Predicate[*sitter.Node]
}

func (Param) Test

func (wp Param) Test(nodes MatchNodes) bool

type Predicate

type Predicate[T any] interface {
	Test(input T) bool
}

Predicate takes some value and the program source, and returns a bool.

type Reference

type Reference struct {
	File        *core.SourceFile
	QueryResult map[string]*sitter.Node
}

func FindReferencesInFile

func FindReferencesInFile(
	file *core.SourceFile,
	matchRefQuery string,
	validate func(map[string]*sitter.Node, *core.SourceFile) bool,
) []Reference

func FindReferencesInUnit

func FindReferencesInUnit(
	lang *core.SourceLanguage,
	unit *core.ExecutionUnit,
	matchRefQuery string,
	validate func(map[string]*sitter.Node, *core.SourceFile) bool,
) []Reference

type Selector

type Selector[T any] func(MatchNodes) (T, bool)

Selector takes a MatchNodes and the program source, and optionally returns some value.

func ContentOf

func ContentOf(filter Selector[*sitter.Node]) Selector[string]

func ParamNamed

func ParamNamed(paramName string) Selector[*sitter.Node]

ParamNamed is a Selector that returns a param from the MatchNodes by name, if such a param exists.

type Type

type Type string

func (Type) Test

func (ot Type) Test(node *sitter.Node) bool

Jump to

Keyboard shortcuts

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