rts

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 11 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 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 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 ArgBlock

type ArgBlock struct {
	BaseNode
	Args []ArgDecl
	// ArgName -> Constraint
	EnumConstraints  map[string]*ArgEnumConstraint
	RegexConstraints map[string]*ArgRegexConstraint
	RangeConstraints map[string]*ArgRangeConstraint
	Requirements     []ArgRequirement
	Exclusions       []ArgExclusion
}

type ArgDecl

type ArgDecl struct {
	BaseNode
	Name       ArgDeclName
	Type       ArgDeclType
	Rename     *ArgDeclRename
	Shorthand  *ArgDeclShorthand
	Optional   *ArgDeclOptional
	Default    *ArgDeclDefault
	Comment    *ArgDeclComment
	IsVariadic bool
}

func (*ArgDecl) CommentStr

func (ad *ArgDecl) CommentStr() *string

func (*ArgDecl) ExternalName

func (ad *ArgDecl) ExternalName() string

func (*ArgDecl) ShorthandStr

func (ad *ArgDecl) ShorthandStr() *string

type ArgDeclComment

type ArgDeclComment struct {
	BaseNode
	Comment string
}

type ArgDeclDefault

type ArgDeclDefault struct {
	BaseNode
	DefaultString     *string
	DefaultInt        *int64
	DefaultFloat      *float64
	DefaultBool       *bool
	DefaultStringList *[]string
	DefaultIntList    *[]int64
	DefaultFloatList  *[]float64
	DefaultBoolList   *[]bool
}

type ArgDeclName

type ArgDeclName struct {
	BaseNode
	Name string
}

type ArgDeclOptional

type ArgDeclOptional struct {
	BaseNode
}

type ArgDeclRename

type ArgDeclRename struct {
	BaseNode
	ExternalName string
}

type ArgDeclShorthand

type ArgDeclShorthand struct {
	BaseNode
	Shorthand string // single char
}

type ArgDeclType

type ArgDeclType struct {
	BaseNode
	Type string // todo or enum?
}

type ArgEnumConstraint

type ArgEnumConstraint struct {
	BaseNode
	ArgName ArgName
	Values  ArgEnumValues
}

type ArgEnumValues

type ArgEnumValues struct {
	BaseNode
	Values []string
}

type ArgExclusion

type ArgExclusion struct {
	BaseNode
	Arg      ArgName
	IsMutual bool
	Excluded []ArgName
}

type ArgName

type ArgName struct {
	BaseNode
	Name string
}

type ArgRangeConstraint

type ArgRangeConstraint struct {
	BaseNode
	ArgName ArgName
	Range   ArgRangeValue
}

type ArgRangeMinMax

type ArgRangeMinMax struct {
	BaseNode
	Value float64
}

type ArgRangeOpenerCloser

type ArgRangeOpenerCloser struct {
	BaseNode
	Token string
}

type ArgRangeValue

type ArgRangeValue struct {
	Opener ArgRangeOpenerCloser
	Closer ArgRangeOpenerCloser
	Min    *ArgRangeMinMax
	Max    *ArgRangeMinMax
}

type ArgRegexConstraint

type ArgRegexConstraint struct {
	BaseNode
	ArgName ArgName
	Regex   ArgRegexValue
}

type ArgRegexValue

type ArgRegexValue struct {
	BaseNode
	Value string
}

type ArgRequirement

type ArgRequirement struct {
	BaseNode
	Arg      ArgName
	IsMutual bool
	Required []ArgName
}

type BaseNode

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

func (*BaseNode) CompleteSrc

func (n *BaseNode) CompleteSrc() string

func (*BaseNode) EndByte

func (n *BaseNode) EndByte() int

func (*BaseNode) EndPos

func (n *BaseNode) EndPos() Position

func (*BaseNode) Node

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

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
	NameNode *ts.Node
}

type CallbackType added in v0.6.16

type CallbackType int
const (
	CallbackIdentifier CallbackType = iota
	CallbackLambda
)

type CmdBlock added in v0.6.16

type CmdBlock struct {
	BaseNode
	Name        CmdName
	Description *CmdDescription
	Args        []ArgDecl
	// Constraints (reuse from ArgBlock)
	EnumConstraints  map[string]*ArgEnumConstraint
	RegexConstraints map[string]*ArgRegexConstraint
	RangeConstraints map[string]*ArgRangeConstraint
	Requirements     []ArgRequirement
	Exclusions       []ArgExclusion
	// Callback
	Callback CmdCallback
}

type CmdCallback added in v0.6.16

type CmdCallback struct {
	BaseNode
	Type           CallbackType
	IdentifierName *string  // For function reference callbacks (CallbackIdentifier)
	LambdaNode     *ts.Node // For inline lambda callbacks (CallbackLambda)
}

type CmdDescription added in v0.6.16

type CmdDescription struct {
	BaseNode
	Contents string
}

type CmdName added in v0.6.16

type CmdName struct {
	BaseNode
	Name string
}

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 {
	Node() *ts.Node
	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) FindArgBlock

func (rt *RadTree) FindArgBlock() (*ArgBlock, bool)

func (*RadTree) FindCalls

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

func (*RadTree) FindCmdBlocks added in v0.6.16

func (rt *RadTree) FindCmdBlocks() ([]*CmdBlock, bool)

func (*RadTree) FindFileHeader

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

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) 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
test
dumps command

Jump to

Keyboard shortcuts

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