rts

package
v0.5.57 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: Apache-2.0 Imports: 9 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 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)

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
}

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 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 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) 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