rts

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

README

RTS: RSL Tree Sitter

A Go library wrapping the Go bindings for Rad's tree sitter implementation.

Installation

go get -u github.com/amterp/rad/rts

Git blame ignore revs

This repo has a .git-blame-ignore-revs file. Add it to your git with:

git config blame.ignoreRevsFile .git-blame-ignore-revs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FnSignaturesByName map[string]FnSignature

Functions

func ConvertCST added in v0.9.0

func ConvertCST(root *ts.Node, src string, file string) *rl.SourceFile

ConvertCST converts a tree-sitter CST into a Go-native AST. The input CST must be valid (no ERROR/MISSING nodes) - if the converter encounters an unexpected node kind, it panics.

func ConvertExpr added in v0.9.0

func ConvertExpr(node *ts.Node, src string, file string) rl.Node

ConvertExpr converts a single CST expression node into an AST expression. Used to pre-convert built-in function defaults in signatures.go init() and by the converter for user-defined function parameter defaults.

func NodeName

func NodeName[T Node]() string

func NormalizeIndentedText added in v0.6.18

func NormalizeIndentedText(text string) string

NormalizeIndentedText removes common leading whitespace from all lines. Handles trailing newlines from tree-sitter, expands tabs to spaces (4-char width), and uses rune-aware slicing for UTF-8 safety. Preserves relative indentation.

func ParseFloat

func ParseFloat(src string) (float64, error)

func ParseInt

func ParseInt(src string) (int64, error)

func QueryNodes

func QueryNodes[T Node](rt *RadTree) ([]T, error)

func SpanFromNode added in v0.9.0

func SpanFromNode(node *ts.Node, file string) rl.Span

SpanFromNode creates an rl.Span from a tree-sitter node and file path.

func ToExternalName added in v0.5.59

func ToExternalName(internalName string) string

ToExternalName converts internal argument names to external CLI flag names. This is the single source of truth for name transformations in Rad.

Types

type BaseNode

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

func (*BaseNode) CompleteSrc

func (n *BaseNode) CompleteSrc() string

func (*BaseNode) CstNode added in v0.9.0

func (n *BaseNode) CstNode() *ts.Node

func (*BaseNode) EndByte

func (n *BaseNode) EndByte() int

func (*BaseNode) EndPos

func (n *BaseNode) EndPos() Position

func (*BaseNode) Src

func (n *BaseNode) Src() string

func (*BaseNode) StartByte

func (n *BaseNode) StartByte() int

func (*BaseNode) StartPos

func (n *BaseNode) StartPos() Position

type CallNode

type CallNode struct {
	BaseNode
	Name     string
	NameSpan rl.Span
}

type FileHeader

type FileHeader struct {
	BaseNode
	Contents        string
	MetadataEntries map[string]string
}

type FnSignature

type FnSignature struct {
	Name      string
	Signature string
	Typing    *rl.TypingFnT
}

func GetSignature

func GetSignature(name string) *FnSignature

type FunctionSet added in v0.6.15

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

func GetBuiltInFunctions added in v0.6.15

func GetBuiltInFunctions() *FunctionSet

GetBuiltInFunctions returns the singleton instance of built-in functions. This is thread-safe and loads the functions only once.

func (*FunctionSet) Contains added in v0.6.15

func (fs *FunctionSet) Contains(name string) bool

type Node

type Node interface {
	CompleteSrc() string
	Src() string
	// Indexes in the original source code.
	// Zero indexed, so add +1 to get human readable values.
	// todo wrap in own Range object instead?
	StartByte() int
	EndByte() int // inclusive
	StartPos() Position
	EndPos() Position // inclusive
}

type Position

type Position struct {
	Row int
	Col int
}

func NewPosition

func NewPosition(p ts.Point) Position

type RadParser

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

func NewRadParser

func NewRadParser() (rts *RadParser, err error)

func (*RadParser) Close

func (rts *RadParser) Close()

func (*RadParser) Parse

func (rts *RadParser) Parse(src string) *RadTree

type RadTree

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

func (*RadTree) Close

func (rt *RadTree) Close()

func (*RadTree) Dump

func (rt *RadTree) Dump() string

func (*RadTree) FindCalls

func (rt *RadTree) FindCalls() []*CallNode

func (*RadTree) FindFileHeader

func (rt *RadTree) FindFileHeader() (*FileHeader, bool)

func (*RadTree) FindInvalidNodeSpans added in v0.9.0

func (rt *RadTree) FindInvalidNodeSpans(file string) []rl.Span

FindInvalidNodeSpans returns spans for all invalid/missing nodes.

func (*RadTree) FindInvalidNodes

func (rt *RadTree) FindInvalidNodes() []*ts.Node

func (*RadTree) FindNodes

func (rt *RadTree) FindNodes(nodeKind string) []*ts.Node

todo should take an ID instead of string for kind

func (*RadTree) FindShebang

func (rt *RadTree) FindShebang() (*Shebang, bool)

func (*RadTree) HasInvalidNodes added in v0.9.0

func (rt *RadTree) HasInvalidNodes() bool

HasInvalidNodes returns true if the tree contains any error/missing nodes.

func (*RadTree) Root

func (rt *RadTree) Root() *ts.Node

func (*RadTree) Sexp

func (rt *RadTree) Sexp() string

func (*RadTree) String

func (rt *RadTree) String() string

func (*RadTree) Update

func (rt *RadTree) Update(src string)

type Shebang

type Shebang struct {
	BaseNode
}

type StringNode

type StringNode struct {
	BaseNode
	RawLexeme string // Literal src, excluding delimiters, ws, comments, etc
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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