ast

package
v0.0.0-...-66342f7 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Nop              = Op("nop")
	Or               = Op("||")
	And              = Op("&&")
	Equal            = Op("==")
	NotEqual         = Op("!=")
	LessThan         = Op("<")
	LessThanEqual    = Op("<=")
	GreaterThan      = Op(">")
	GreaterThanEqual = Op(">=")
	Add              = Op("+")
	Subtract         = Op("-")
	Multiply         = Op("*")
	Divide           = Op("/")
	Modulo           = Op("%")
	Not              = Op("!")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Position
	Items []Expr
}

Array represents an array constructor [expr, expr, ...].

func (*Array) Walk

func (expr *Array) Walk(v Visitor) (Expr, error)

type Binary

type Binary struct {
	Position
	LHS Expr
	Op  Op
	RHS Expr
}

Binary represents a binary operation.

func (*Binary) Walk

func (expr *Binary) Walk(v Visitor) (Expr, error)

type Call

type Call struct {
	Position
	From      Expr
	Arguments []Expr
}

Call represents a function call.

func (*Call) Walk

func (expr *Call) Walk(v Visitor) (Expr, error)

type Expr

type Expr interface {
	Offset() int64
	Length() int64
	Walk(Visitor) (Expr, error)
}

Expr represents a node in the AST.

type Ident

type Ident struct {
	Position
	Name string
}

Ident represents an identifier reference.

func (*Ident) Walk

func (expr *Ident) Walk(v Visitor) (Expr, error)

type Index

type Index struct {
	Position
	From  Expr
	Index Expr
}

Index represents index access (arr[0]).

func (*Index) Walk

func (expr *Index) Walk(v Visitor) (Expr, error)

type Literal

type Literal struct {
	Position
	value.Value
}

Literal represents a literal value.

func (*Literal) Walk

func (expr *Literal) Walk(v Visitor) (Expr, error)

type Object

type Object struct {
	Position
	Items []ObjectItem
}

Object represents an object constructor {expr: expr, ...}.

func (*Object) Walk

func (expr *Object) Walk(v Visitor) (Expr, error)

type ObjectItem

type ObjectItem struct {
	Key, Value Expr
}

type Op

type Op string

func (Op) Precedence

func (o Op) Precedence() int

type Parentheses

type Parentheses struct {
	Position
	Expr Expr
}

Parentheses represents a parenthesized expression.

func (*Parentheses) Walk

func (expr *Parentheses) Walk(v Visitor) (Expr, error)

type Position

type Position struct {
	Off int64
	Len int64
}

Position stores token position information.

func (Position) Length

func (p Position) Length() int64

Length returns the length of the associated token.

func (Position) Offset

func (p Position) Offset() int64

Offset returns the offset of the associated token.

type Selector

type Selector struct {
	Position
	From   Expr
	Select Expr
}

Selector represents property access (obj.prop).

func (*Selector) Walk

func (expr *Selector) Walk(v Visitor) (Expr, error)

type Template

type Template struct {
	Position
	Exprs []Expr
}

Template represents a string template.

func (*Template) Walk

func (expr *Template) Walk(v Visitor) (Expr, error)

type Unary

type Unary struct {
	Position
	Op  Op
	RHS Expr
}

Unary represents a unary operation.

func (*Unary) Walk

func (expr *Unary) Walk(v Visitor) (Expr, error)

type Visitor

type Visitor interface {
	// Enter is called before visiting children.
	// Return nil to skip visiting this node's children.
	// Return a visitor (typically self) to continue traversal.
	Enter(Expr) (Visitor, error)

	// Exit is called after visiting children.
	// Return the (possibly transformed) node.
	Exit(Expr) (Expr, error)
}

Visitor processes AST nodes with pre-order and post-order hooks.

Jump to

Keyboard shortcuts

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