ast

package
v1.16.9 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 8 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(node Node) string

func Patch

func Patch(node *Node, newNode Node)

Patch replaces the node with a new one. Location information is preserved. Type information is lost.

func Walk

func Walk(node *Node, v Visitor)

Types

type ArrayNode

type ArrayNode struct {
	Nodes []Node // Nodes of the array.
	// contains filtered or unexported fields
}

ArrayNode represents an array.

func (*ArrayNode) Location

func (n *ArrayNode) Location() file.Location

Location returns the location of the node in the source code.

func (*ArrayNode) SetLocation

func (n *ArrayNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*ArrayNode) SetType

func (n *ArrayNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*ArrayNode) String

func (n *ArrayNode) String() string

func (*ArrayNode) Type

func (n *ArrayNode) Type() reflect.Type

Type returns the type of the node.

type BinaryNode

type BinaryNode struct {
	Operator string // Operator of the binary operator. Like "+" in "foo + bar" or "matches" in "foo matches bar".
	Left     Node   // Left node of the binary operator.
	Right    Node   // Right node of the binary operator.
	// contains filtered or unexported fields
}

BinaryNode represents a binary operator.

func (*BinaryNode) Location

func (n *BinaryNode) Location() file.Location

Location returns the location of the node in the source code.

func (*BinaryNode) SetLocation

func (n *BinaryNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*BinaryNode) SetType

func (n *BinaryNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*BinaryNode) String

func (n *BinaryNode) String() string

func (*BinaryNode) Type

func (n *BinaryNode) Type() reflect.Type

Type returns the type of the node.

type BoolNode

type BoolNode struct {
	Value bool // Value of the boolean.
	// contains filtered or unexported fields
}

BoolNode represents a boolean.

func (*BoolNode) Location

func (n *BoolNode) Location() file.Location

Location returns the location of the node in the source code.

func (*BoolNode) SetLocation

func (n *BoolNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*BoolNode) SetType

func (n *BoolNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*BoolNode) String

func (n *BoolNode) String() string

func (*BoolNode) Type

func (n *BoolNode) Type() reflect.Type

Type returns the type of the node.

type BuiltinNode

type BuiltinNode struct {
	Name      string // Name of the builtin function. Like "len" in "len(foo)".
	Arguments []Node // Arguments of the builtin function.
	Throws    bool   // If true then accessing a field or array index can throw an error. Used by optimizer.
	Map       Node   // Used by optimizer to fold filter() and map() builtins.
	// contains filtered or unexported fields
}

BuiltinNode represents a builtin function call.

func (*BuiltinNode) Location

func (n *BuiltinNode) Location() file.Location

Location returns the location of the node in the source code.

func (*BuiltinNode) SetLocation

func (n *BuiltinNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*BuiltinNode) SetType

func (n *BuiltinNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*BuiltinNode) String

func (n *BuiltinNode) String() string

func (*BuiltinNode) Type

func (n *BuiltinNode) Type() reflect.Type

Type returns the type of the node.

type CallNode

type CallNode struct {
	Callee    Node   // Node of the call. Like "foo" in "foo()".
	Arguments []Node // Arguments of the call.
	// contains filtered or unexported fields
}

CallNode represents a function or a method call.

func (*CallNode) Location

func (n *CallNode) Location() file.Location

Location returns the location of the node in the source code.

func (*CallNode) SetLocation

func (n *CallNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*CallNode) SetType

func (n *CallNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*CallNode) String

func (n *CallNode) String() string

func (*CallNode) Type

func (n *CallNode) Type() reflect.Type

Type returns the type of the node.

type ChainNode

type ChainNode struct {
	Node Node // Node of the chain.
	// contains filtered or unexported fields
}

ChainNode represents an optional chaining group. A few MemberNode nodes can be chained together, and will be wrapped in a ChainNode. Example:

foo.bar?.baz?.qux

The whole chain will be wrapped in a ChainNode.

func (*ChainNode) Location

func (n *ChainNode) Location() file.Location

Location returns the location of the node in the source code.

func (*ChainNode) SetLocation

func (n *ChainNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*ChainNode) SetType

func (n *ChainNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*ChainNode) String

func (n *ChainNode) String() string

func (*ChainNode) Type

func (n *ChainNode) Type() reflect.Type

Type returns the type of the node.

type ClosureNode

type ClosureNode struct {
	Node Node // Node of the predicate body.
	// contains filtered or unexported fields
}

ClosureNode represents a predicate. Example:

filter(foo, .bar == 1)

The predicate is ".bar == 1".

func (*ClosureNode) Location

func (n *ClosureNode) Location() file.Location

Location returns the location of the node in the source code.

func (*ClosureNode) SetLocation

func (n *ClosureNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*ClosureNode) SetType

func (n *ClosureNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*ClosureNode) String

func (n *ClosureNode) String() string

func (*ClosureNode) Type

func (n *ClosureNode) Type() reflect.Type

Type returns the type of the node.

type ConditionalNode

type ConditionalNode struct {
	Cond Node // Condition of the ternary operator. Like "foo" in "foo ? bar : baz".
	Exp1 Node // Expression 1 of the ternary operator. Like "bar" in "foo ? bar : baz".
	Exp2 Node // Expression 2 of the ternary operator. Like "baz" in "foo ? bar : baz".
	// contains filtered or unexported fields
}

ConditionalNode represents a ternary operator.

func (*ConditionalNode) Location

func (n *ConditionalNode) Location() file.Location

Location returns the location of the node in the source code.

func (*ConditionalNode) SetLocation

func (n *ConditionalNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*ConditionalNode) SetType

func (n *ConditionalNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*ConditionalNode) String

func (n *ConditionalNode) String() string

func (*ConditionalNode) Type

func (n *ConditionalNode) Type() reflect.Type

Type returns the type of the node.

type ConstantNode

type ConstantNode struct {
	Value any // Value of the constant.
	// contains filtered or unexported fields
}

ConstantNode represents a constant. Constants are predefined values like nil, true, false, array, map, etc. The parser.Parse will never generate ConstantNode, it is only generated by the optimizer.

func (*ConstantNode) Location

func (n *ConstantNode) Location() file.Location

Location returns the location of the node in the source code.

func (*ConstantNode) SetLocation

func (n *ConstantNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*ConstantNode) SetType

func (n *ConstantNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*ConstantNode) String

func (n *ConstantNode) String() string

func (*ConstantNode) Type

func (n *ConstantNode) Type() reflect.Type

Type returns the type of the node.

type FloatNode

type FloatNode struct {
	Value float64 // Value of the float.
	// contains filtered or unexported fields
}

FloatNode represents a float.

func (*FloatNode) Location

func (n *FloatNode) Location() file.Location

Location returns the location of the node in the source code.

func (*FloatNode) SetLocation

func (n *FloatNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*FloatNode) SetType

func (n *FloatNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*FloatNode) String

func (n *FloatNode) String() string

func (*FloatNode) Type

func (n *FloatNode) Type() reflect.Type

Type returns the type of the node.

type IdentifierNode

type IdentifierNode struct {
	Value string // Name of the identifier. Like "foo" in "foo.bar".
	// contains filtered or unexported fields
}

IdentifierNode represents an identifier.

func (*IdentifierNode) Location

func (n *IdentifierNode) Location() file.Location

Location returns the location of the node in the source code.

func (*IdentifierNode) SetLocation

func (n *IdentifierNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*IdentifierNode) SetType

func (n *IdentifierNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*IdentifierNode) String

func (n *IdentifierNode) String() string

func (*IdentifierNode) Type

func (n *IdentifierNode) Type() reflect.Type

Type returns the type of the node.

type IntegerNode

type IntegerNode struct {
	Value int // Value of the integer.
	// contains filtered or unexported fields
}

IntegerNode represents an integer.

func (*IntegerNode) Location

func (n *IntegerNode) Location() file.Location

Location returns the location of the node in the source code.

func (*IntegerNode) SetLocation

func (n *IntegerNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*IntegerNode) SetType

func (n *IntegerNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*IntegerNode) String

func (n *IntegerNode) String() string

func (*IntegerNode) Type

func (n *IntegerNode) Type() reflect.Type

Type returns the type of the node.

type MapNode

type MapNode struct {
	Pairs []Node // PairNode nodes.
	// contains filtered or unexported fields
}

MapNode represents a map.

func (*MapNode) Location

func (n *MapNode) Location() file.Location

Location returns the location of the node in the source code.

func (*MapNode) SetLocation

func (n *MapNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*MapNode) SetType

func (n *MapNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*MapNode) String

func (n *MapNode) String() string

func (*MapNode) Type

func (n *MapNode) Type() reflect.Type

Type returns the type of the node.

type MemberNode

type MemberNode struct {
	Node     Node // Node of the member access. Like "foo" in "foo.bar".
	Property Node // Property of the member access. For property access it is a StringNode.
	Optional bool // If true then the member access is optional. Like "foo?.bar".
	Method   bool
	// contains filtered or unexported fields
}

MemberNode represents a member access. It can be a field access, a method call, or an array element access. Example:

foo.bar or foo["bar"]
foo.bar()
array[0]

func (*MemberNode) Location

func (n *MemberNode) Location() file.Location

Location returns the location of the node in the source code.

func (*MemberNode) SetLocation

func (n *MemberNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*MemberNode) SetType

func (n *MemberNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*MemberNode) String

func (n *MemberNode) String() string

func (*MemberNode) Type

func (n *MemberNode) Type() reflect.Type

Type returns the type of the node.

type NilNode

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

NilNode represents nil.

func (*NilNode) Location

func (n *NilNode) Location() file.Location

Location returns the location of the node in the source code.

func (*NilNode) SetLocation

func (n *NilNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*NilNode) SetType

func (n *NilNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*NilNode) String

func (n *NilNode) String() string

func (*NilNode) Type

func (n *NilNode) Type() reflect.Type

Type returns the type of the node.

type Node

type Node interface {
	Location() file.Location
	SetLocation(file.Location)
	Type() reflect.Type
	SetType(reflect.Type)
	String() string
}

Node represents items of abstract syntax tree.

type PairNode

type PairNode struct {
	Key   Node // Key of the pair.
	Value Node // Value of the pair.
	// contains filtered or unexported fields
}

PairNode represents a key-value pair of a map.

func (*PairNode) Location

func (n *PairNode) Location() file.Location

Location returns the location of the node in the source code.

func (*PairNode) SetLocation

func (n *PairNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*PairNode) SetType

func (n *PairNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*PairNode) String

func (n *PairNode) String() string

func (*PairNode) Type

func (n *PairNode) Type() reflect.Type

Type returns the type of the node.

type PointerNode

type PointerNode struct {
	Name string // Name of the pointer. Like "index" in "#index".
	// contains filtered or unexported fields
}

PointerNode represents a pointer to a current value in predicate.

func (*PointerNode) Location

func (n *PointerNode) Location() file.Location

Location returns the location of the node in the source code.

func (*PointerNode) SetLocation

func (n *PointerNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*PointerNode) SetType

func (n *PointerNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*PointerNode) String

func (n *PointerNode) String() string

func (*PointerNode) Type

func (n *PointerNode) Type() reflect.Type

Type returns the type of the node.

type SliceNode

type SliceNode struct {
	Node Node // Node of the slice. Like "array" in "array[1:4]".
	From Node // From an index of the array. Like "1" in "array[1:4]".
	To   Node // To an index of the array. Like "4" in "array[1:4]".
	// contains filtered or unexported fields
}

SliceNode represents access to a slice of an array. Example:

array[1:4]

func (*SliceNode) Location

func (n *SliceNode) Location() file.Location

Location returns the location of the node in the source code.

func (*SliceNode) SetLocation

func (n *SliceNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*SliceNode) SetType

func (n *SliceNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*SliceNode) String

func (n *SliceNode) String() string

func (*SliceNode) Type

func (n *SliceNode) Type() reflect.Type

Type returns the type of the node.

type StringNode

type StringNode struct {
	Value string // Value of the string.
	// contains filtered or unexported fields
}

StringNode represents a string.

func (*StringNode) Location

func (n *StringNode) Location() file.Location

Location returns the location of the node in the source code.

func (*StringNode) SetLocation

func (n *StringNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*StringNode) SetType

func (n *StringNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*StringNode) String

func (n *StringNode) String() string

func (*StringNode) Type

func (n *StringNode) Type() reflect.Type

Type returns the type of the node.

type UnaryNode

type UnaryNode struct {
	Operator string // Operator of the unary operator. Like "!" in "!foo" or "not" in "not foo".
	Node     Node   // Node of the unary operator. Like "foo" in "!foo".
	// contains filtered or unexported fields
}

UnaryNode represents a unary operator.

func (*UnaryNode) Location

func (n *UnaryNode) Location() file.Location

Location returns the location of the node in the source code.

func (*UnaryNode) SetLocation

func (n *UnaryNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*UnaryNode) SetType

func (n *UnaryNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*UnaryNode) String

func (n *UnaryNode) String() string

func (*UnaryNode) Type

func (n *UnaryNode) Type() reflect.Type

Type returns the type of the node.

type VariableDeclaratorNode

type VariableDeclaratorNode struct {
	Name  string // Name of the variable. Like "foo" in "let foo = 1; foo + 1".
	Value Node   // Value of the variable. Like "1" in "let foo = 1; foo + 1".
	Expr  Node   // Expression of the variable. Like "foo + 1" in "let foo = 1; foo + 1".
	// contains filtered or unexported fields
}

VariableDeclaratorNode represents a variable declaration.

func (*VariableDeclaratorNode) Location

func (n *VariableDeclaratorNode) Location() file.Location

Location returns the location of the node in the source code.

func (*VariableDeclaratorNode) SetLocation

func (n *VariableDeclaratorNode) SetLocation(loc file.Location)

SetLocation sets the location of the node in the source code.

func (*VariableDeclaratorNode) SetType

func (n *VariableDeclaratorNode) SetType(t reflect.Type)

SetType sets the type of the node.

func (*VariableDeclaratorNode) String

func (n *VariableDeclaratorNode) String() string

func (*VariableDeclaratorNode) Type

func (n *VariableDeclaratorNode) Type() reflect.Type

Type returns the type of the node.

type Visitor

type Visitor interface {
	Visit(node *Node)
}

Jump to

Keyboard shortcuts

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