ast

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: Zlib Imports: 5 Imported by: 8

Documentation

Index

Constants

View Source
const (
	OpAdd opTyp = iota
	OpSub
	OpMul
	OpMod
	OpPow
	OpDiv
	OpIDiv
	OpBinAND
	OpBinOR
	OpBinXOR
	OpBinShiftL
	OpBinShiftR
	OpUMinus
	OpBinNot
	OpNot
	OpLength
	OpConcat

	OpEqual
	OpNotEqual
	OpLessThan
	OpGreaterThan
	OpLessOrEqual
	OpGreaterOrEqual

	OpAnd
	OpOr
)

Operator type for use with the Operator Expr Node.

Variables

This section is empty.

Functions

func Inspect

func Inspect(node Node, f func(Node) bool)

Inspect is exactly like Walk, except f is called for each node only if a call to f returns true for that node's parent (f is always called for the root node).

func Walk

func Walk(v Visitor, n Node)

Walk traverses the given AST node and it's children in depth-first order. For each node it calls the visitor for that level and then uses the returned visitor for the child nodes (if any). If the visitor for a given node returns nil that node's children will not be visited. Once all of a node's children are visited the visitor for that level is called one final time with nil as its argument.

Types

type Assign

type Assign struct {

	// Is this a local variable declaration statement?
	LocalDecl bool

	// Special case handling for "local function f() end", this should be treated like "local f; f = function() end".
	LocalFunc bool

	Targets []Expr
	Values  []Expr // If len == 0 no values were given, if len == 1 then the value may be a multi-return function call.
	// contains filtered or unexported fields
}

Assign represents an assignment statement.

type ConstBool

type ConstBool struct {
	Value bool
	// contains filtered or unexported fields
}

ConstBool represents a boolean constant.

type ConstFloat

type ConstFloat struct {
	Value string
	// contains filtered or unexported fields
}

ConstFloat stores a floating point constant.

type ConstIdent

type ConstIdent struct {
	Value string
	// contains filtered or unexported fields
}

ConstIdent stores an identifier constant.

type ConstInt

type ConstInt struct {
	Value string
	// contains filtered or unexported fields
}

ConstInt stores an integer constant.

type ConstNil

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

ConstNil represents the constant "nil".

type ConstString

type ConstString struct {
	Value string
	// contains filtered or unexported fields
}

ConstString stores a string constant.

type ConstVariadic

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

ConstVariadic represents the variadic expression element (...).

type DoBlock

type DoBlock struct {
	Block []Stmt
	// contains filtered or unexported fields
}

DoBlock represents a do block (do ... end).

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr represents an expression element Node.

type ForLoopGeneric

type ForLoopGeneric struct {
	Locals []string
	Init   []Expr // This will always be adjusted to three return results, but AFAIK there is no actual limit on expression count.

	Block []Stmt
	// contains filtered or unexported fields
}

ForLoopGeneric represents a generic for loop.

type ForLoopNumeric

type ForLoopNumeric struct {
	Counter string

	Init  Expr
	Limit Expr
	Step  Expr

	Block []Stmt
	// contains filtered or unexported fields
}

ForLoopNumeric represents a numeric for loop.

type FuncCall

type FuncCall struct {
	Receiver Expr // The call receiver if any (the part before the ':')
	Function Expr // The function value itself, if Receiver is provided this is the part *after* the colon, else it is the whole name.
	Args     []Expr
	// contains filtered or unexported fields
}

FuncCall represents a function call. This has the unique property of being both a Stmt and an Expr.

type FuncDecl

type FuncDecl struct {
	Params     []string
	IsVariadic bool

	Source string

	Block []Stmt
	// contains filtered or unexported fields
}

FuncDecl represents a function declaration.

type Goto

type Goto struct {

	// True if this Goto is actually a break statement. There is no matching label.
	// If Label is not "break" then this is actually a continue statement (a custom
	// extension that the default lexer/parser does not use).
	IsBreak bool
	Label   string
	// contains filtered or unexported fields
}

type If

type If struct {
	Cond Expr
	Then []Stmt
	Else []Stmt
	// contains filtered or unexported fields
}

If represents an if statement. 'elseif' statements are encoded as nested if statements.

type Label

type Label struct {
	Label string
	// contains filtered or unexported fields
}

type Node

type Node interface {
	Line() int
	// contains filtered or unexported methods
}

Node represents an item in the AST.

type Operator

type Operator struct {
	Op    opTyp
	Left  Expr // Nil if operator is unary
	Right Expr
	// contains filtered or unexported fields
}

Operator represents an operator and it's operands.

type Parens

type Parens struct {
	Inner Expr
	// contains filtered or unexported fields
}

Parens represents a pair of parenthesis and the expression inside of them.

type RepeatUntilLoop

type RepeatUntilLoop struct {
	Cond  Expr
	Block []Stmt
	// contains filtered or unexported fields
}

RepeatUntilLoop represents a repeat-until loop.

type Return

type Return struct {
	Items []Expr
	// contains filtered or unexported fields
}

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt represents a statement Node.

func Parse

func Parse(source string, line int) (block []Stmt, err error)

Parse reads Lua source into an AST using the types in this package.

type TableAccessor

type TableAccessor struct {
	Obj Expr
	Key Expr
	// contains filtered or unexported fields
}

TableAccessor represents a table access expression, one of `a.b` or `a[b]`.

type TableConstructor

type TableConstructor struct {
	Keys []Expr // A nil key for a particular position means that no key was given.
	Vals []Expr
	// contains filtered or unexported fields
}

TableConstructor represents a table constructor.

type Visitor

type Visitor interface {
	Visit(n Node) Visitor
}

Visitor is used with Walk.

func NewVisitor

func NewVisitor(f func(n Node) Visitor) Visitor

NewVisitor takes a simple function and turns it into a basic Visitor, ready to use with Walk.

type WhileLoop

type WhileLoop struct {
	Cond  Expr
	Block []Stmt
	// contains filtered or unexported fields
}

WhileLoop represents a while loop.

Jump to

Keyboard shortcuts

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