Documentation
¶
Index ¶
- func DumpTree(tree *sitter.Tree, source []byte, w io.Writer, format DumpFormat, ...) error
- func NodeToLispExpression(node *sitter.Node, content []byte, includeAnonymous bool) pm.Expression
- type Capture
- type DumpFormat
- type DumpOptions
- type Dumper
- type Match
- type QueryResults
- type Result
- type SitterQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DumpTree ¶
func DumpTree(tree *sitter.Tree, source []byte, w io.Writer, format DumpFormat, options DumpOptions) error
DumpTree dumps a tree to the specified writer using the given format and options
func NodeToLispExpression ¶
NodeToLispExpression converts a tree-sitter node into a Lisp-style S-expression represented using the patternmatcher Expression types.
The resulting expression has the structure:
(node_type [ (field_name child) | child ] ...)
- node_type is a pm.Symbol with the node's Type() - Fields are represented as 2-element lists: (field_name child) - Anonymous children without a field are included directly - Leaf nodes are represented as a single-element list: (node_type)
Types ¶
type Capture ¶
type Capture struct {
// Name if the capture name from the query
Name string
// Text is the actual text that was captured
Text string
// Type is the Treesitter type of the captured node
Type string
// TODO(manuel, 2023-04-23): Add more information about the capture
// for example: offset, line number, filename, query name, ...
StartByte uint32
EndByte uint32
StartPoint sitter.Point
EndPoint sitter.Point
}
type DumpFormat ¶
DumpFormat represents a tree output format type
const ( FormatText DumpFormat = dump.FormatText FormatXML DumpFormat = dump.FormatXML FormatJSON DumpFormat = dump.FormatJSON FormatYAML DumpFormat = dump.FormatYAML )
Format constants
type Dumper ¶
Dumper is the interface that all tree dumpers must implement
func NewDumper ¶
func NewDumper(format DumpFormat) Dumper
NewDumper creates a new tree dumper for the specified format
type QueryResults ¶
func ExecuteQueries ¶
func ExecuteQueries( lang *sitter.Language, tree *sitter.Node, queries []SitterQuery, sourceCode []byte, ) (QueryResults, error)
ExecuteQueries runs the given queries on the given tree and returns the results. Individual names are resolved using the sourceCode string, so as to provide full identifier names when matched.
TODO(manuel, 2023-06-19) We only need the language from oc here, right?
type SitterQuery ¶
type SitterQuery struct {
// Name of the resulting variable after parsing
Name string `yaml:"name"`
// Query contains the tree-sitter query that will be applied to the source code
Query string `yaml:"query"`
// Rendered keeps track if the Query was Rendered with RenderQueries.
// This is an ugly way of doing things, but at least we'll signal at runtime
// if the code tries to render a query multiple times.
// See the NOTEs in RenderQueries.
Rendered bool
}