parser

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

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

Converter converts tree-sitter AST to our IR format

func NewConverter

func NewConverter(language string, source []byte) *Converter

NewConverter creates a new AST to IR converter

func (*Converter) ConvertTree

func (c *Converter) ConvertTree(ctx context.Context, tree *Tree) (*ir.DistilledFile, error)

ConvertTree converts a tree-sitter tree to our IR format

type Node

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

Node represents a node in the syntax tree

func (*Node) Child

func (n *Node) Child(index uint32) (*Node, error)

Child returns the child at the given index

func (*Node) ChildCount

func (n *Node) ChildCount() (uint32, error)

ChildCount returns the number of children

func (*Node) EndByte

func (n *Node) EndByte() (uint32, error)

EndByte returns the end byte offset of the node

func (*Node) IsError

func (n *Node) IsError() (bool, error)

IsError returns whether the node is an error node

func (*Node) IsNamed

func (n *Node) IsNamed() (bool, error)

IsNamed returns whether the node is named (not anonymous)

func (*Node) StartByte

func (n *Node) StartByte() (uint32, error)

StartByte returns the start byte offset of the node

func (*Node) Type

func (n *Node) Type() (string, error)

Type returns the type of the node

type Parser

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

Parser represents a tree-sitter parser instance

func NewParser

func NewParser(module *WASMModule) (*Parser, error)

NewParser creates a new parser for the given WASM module

func (*Parser) Delete

func (p *Parser) Delete() error

Delete frees the parser resources

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, source []byte) (*Tree, error)

Parse parses the given source code

func (*Parser) SetLanguage

func (p *Parser) SetLanguage() error

SetLanguage sets the language for the parser

type Point

type Point struct {
	Row    uint32
	Column uint32
}

Point represents a position in the source code

type Tree

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

Tree represents a parsed syntax tree

func (*Tree) Delete

func (t *Tree) Delete() error

Delete frees the tree resources

func (*Tree) RootNode

func (t *Tree) RootNode() (*Node, error)

RootNode returns the root node of the tree

type WASMModule

type WASMModule struct {
	Name     string
	Language string
	Module   api.Module
	Compiled wazero.CompiledModule

	// Function references
	TreeSitterLanguage    api.Function
	ParserNew             api.Function
	ParserDelete          api.Function
	ParserParse           api.Function
	ParserSetLanguage     api.Function
	TreeDelete            api.Function
	TreeRootNode          api.Function
	NodeString            api.Function
	NodeChildCount        api.Function
	NodeChild             api.Function
	NodeType              api.Function
	NodeStartByte         api.Function
	NodeEndByte           api.Function
	NodeStartPoint        api.Function
	NodeEndPoint          api.Function
	NodeIsNamed           api.Function
	NodeIsError           api.Function
	NodeFieldNameForChild api.Function
	NodeChildByFieldName  api.Function
}

WASMModule represents a loaded tree-sitter WASM module

type WASMRuntime

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

WASMRuntime manages WASM modules for tree-sitter parsers

func NewWASMRuntime

func NewWASMRuntime(ctx context.Context) (*WASMRuntime, error)

NewWASMRuntime creates a new WASM runtime for tree-sitter parsers

func (*WASMRuntime) Close

func (w *WASMRuntime) Close() error

Close shuts down the WASM runtime

func (*WASMRuntime) GetModule

func (w *WASMRuntime) GetModule(name string) (*WASMModule, error)

GetModule returns a loaded WASM module

func (*WASMRuntime) LoadModule

func (w *WASMRuntime) LoadModule(name string, wasmBytes []byte) error

LoadModule loads a tree-sitter WASM module

Jump to

Keyboard shortcuts

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