tree

package
v0.0.0-...-d522da9 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

The tree package declares the types used to represent parse trees for the Lua syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjoinSeparator

func AdjoinSeparator(left, right Token) rune

AdjoinSeparator calls left.Type.AdjoinSeparator(right.Type) to get a separating character that allows the left token to precede the right.

Returns -1 if the two tokens are allowed to be adjacent.

When a CONCAT precedes a NUMBERFLOAT, -1 is returned if the bytes of the number token do not start with a '.' character, and a space is returned otherwise.

When a keyword precedes a NUMBERFLOAT, -1 is returned if the bytes of the number token starts with a '.' character, and a space is returned otherwise.

func FixAdjoinedTokens

func FixAdjoinedTokens(node Node)

FixAdjoinedTokens walks through a parse tree and ensures that adjacent tokens have the minimum amount of spacing required to prevent them from being parsed incorrectly.

func FixTokenOffsets

func FixTokenOffsets(node Node, offset int)

FixTokenOffsets walks through a parse tree, adjusting the offset of each token so that it is correct for the current bytes of the token. The offset argument specifies the starting offset.

If the node is a File, then the file's line information will be rewritten.

func Walk

func Walk(v Visitor, node Node)

Walk traverses a tree in depth-first, lexical order. It starts by calling v.Visit(node); node must not be nil. If the returned visitor w is not nil, then Walk is called recursively with w for each non-nil child of the node, followed by a call of w.Visit(nil).

If w implements a TokenVisitor, then w.VisitToken(node, n, token) will be called with each token of the node.

Note that a node or token will be traversed even if it is not valid.

Types

type Args

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

Args is the interface that all function call argument nodes implement.

type AssignStmt

type AssignStmt struct {
	// Left is the left side of the assignment, comprised of one or more
	// expressions.
	Left ExprList
	// AssignToken is the ASSIGN token separating the values.
	AssignToken Token
	// Right is the right side of the assignment, comprised of one or more
	// expressions.
	Right ExprList
}

AssignStmt represents the assignment of one or more variables with a number of values.

func (*AssignStmt) FirstToken

func (s *AssignStmt) FirstToken() *Token

func (*AssignStmt) IsValid

func (s *AssignStmt) IsValid() bool

func (*AssignStmt) LastToken

func (s *AssignStmt) LastToken() *Token

func (*AssignStmt) WriteTo

func (s *AssignStmt) WriteTo(w io.Writer) (n int64, err error)

type BinopExpr

type BinopExpr struct {
	// Left is the left side of the operation.
	Left Expr
	// BinopToken is the binary operator token.
	BinopToken Token
	// Right is the right side of the binary operation.
	Right Expr
}

BinopExpr represents a binary operation.

func (*BinopExpr) FirstToken

func (e *BinopExpr) FirstToken() *Token

func (*BinopExpr) IsValid

func (e *BinopExpr) IsValid() bool

func (*BinopExpr) LastToken

func (e *BinopExpr) LastToken() *Token

func (*BinopExpr) WriteTo

func (e *BinopExpr) WriteTo(w io.Writer) (n int64, err error)

type Block

type Block struct {
	// Items is a list of 0 or more Lua statements.
	Items []Stmt
	// Seps indicates whether a statement is followed by a semi-colon. The
	// length of Seps is the same as Stmts. Tokens will either be a SEMICOLON,
	// or INVALID when no semicolon is present.
	Seps []Token
}

Block represents a Lua block.

func (*Block) FirstToken

func (b *Block) FirstToken() *Token

func (*Block) IsValid

func (b *Block) IsValid() bool

func (*Block) LastToken

func (b *Block) LastToken() *Token

func (*Block) Len

func (b *Block) Len() int

Len returns the combined length of Stmts and Seps.

func (*Block) WriteTo

func (b *Block) WriteTo(w io.Writer) (n int64, err error)

type BoolExpr

type BoolExpr struct {
	// BoolToken is the bool token holding the content the expression.
	BoolToken Token
}

BoolExpr represents a Lua boolean expression.

func (*BoolExpr) FirstToken

func (e *BoolExpr) FirstToken() *Token

func (*BoolExpr) FormatValue

func (e *BoolExpr) FormatValue(v bool)

FormatValue receives a boolean and formats it, setting the type and bytes of the token.

func (*BoolExpr) IsValid

func (e *BoolExpr) IsValid() bool

func (*BoolExpr) LastToken

func (e *BoolExpr) LastToken() *Token

func (*BoolExpr) ParseValue

func (e *BoolExpr) ParseValue() (v bool, err error)

ParseValue parses the content of the boolean token and returns the resulting value, or an error explaining why the value could not be parsed.

func (*BoolExpr) WriteTo

func (e *BoolExpr) WriteTo(w io.Writer) (n int64, err error)

type BreakStmt

type BreakStmt struct {
	// BreakToken is the BREAK token of the break statement.
	BreakToken Token
}

BreakStmt represents a `break` statement.

func (*BreakStmt) FirstToken

func (s *BreakStmt) FirstToken() *Token

func (*BreakStmt) IsValid

func (s *BreakStmt) IsValid() bool

func (*BreakStmt) LastToken

func (s *BreakStmt) LastToken() *Token

func (*BreakStmt) WriteTo

func (s *BreakStmt) WriteTo(w io.Writer) (n int64, err error)

type Call

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

Call is the interface that all function call expressions implement.

type CallExpr

type CallExpr struct {
	// Value is the expression being operated on.
	Value Expr
	// Args holds the arguments of the function call.
	Args Args
}

CallExpr represents an expression that calls another expression as a function.

func (*CallExpr) FirstToken

func (e *CallExpr) FirstToken() *Token

func (*CallExpr) IsValid

func (e *CallExpr) IsValid() bool

func (*CallExpr) LastToken

func (e *CallExpr) LastToken() *Token

func (*CallExpr) WriteTo

func (e *CallExpr) WriteTo(w io.Writer) (n int64, err error)

type CallStmt

type CallStmt struct {
	// Call is the call expression.
	Call Call
}

CallStmt represents a call expression as a statement.

func (*CallStmt) FirstToken

func (s *CallStmt) FirstToken() *Token

func (*CallStmt) IsValid

func (s *CallStmt) IsValid() bool

func (*CallStmt) LastToken

func (s *CallStmt) LastToken() *Token

func (*CallStmt) WriteTo

func (s *CallStmt) WriteTo(w io.Writer) (n int64, err error)

type DoStmt

type DoStmt struct {
	// DoToken is the DO token that begins the do statement.
	DoToken Token
	// Body is the body of the do statement.
	Body Block
	// EndToken is the END token that ends the do statement.
	EndToken Token
}

DoStmt represents a `do ... end` Lua statement.

func (*DoStmt) FirstToken

func (s *DoStmt) FirstToken() *Token

func (*DoStmt) IsValid

func (s *DoStmt) IsValid() bool

func (*DoStmt) LastToken

func (s *DoStmt) LastToken() *Token

func (*DoStmt) WriteTo

func (s *DoStmt) WriteTo(w io.Writer) (n int64, err error)

type ElseClause

type ElseClause struct {
	// ElseToken is the ELSE token that begins the body of the else clause.
	ElseToken Token
	// Body is the body of the else clause.
	Body Block
}

ElseClause represents an `else` clause within an `if` statement.

func (*ElseClause) FirstToken

func (c *ElseClause) FirstToken() *Token

func (*ElseClause) IsValid

func (c *ElseClause) IsValid() bool

func (*ElseClause) LastToken

func (c *ElseClause) LastToken() *Token

func (*ElseClause) WriteTo

func (cl *ElseClause) WriteTo(w io.Writer) (n int64, err error)

type ElseIfClause

type ElseIfClause struct {
	// ElseIfToken is the ELSEIF token that begins the elseif clause.
	ElseIfToken Token
	// Cond is the condition of the elseif clause.
	Cond Expr
	// ThenToken is the THEN token that begins the body of the elseif clause.
	ThenToken Token
	// Body is the body of the elseif clause.
	Body Block
}

ElseIfClause represents an `elseif .. then` clause within an `if` statement.

func (*ElseIfClause) FirstToken

func (c *ElseIfClause) FirstToken() *Token

func (*ElseIfClause) IsValid

func (c *ElseIfClause) IsValid() bool

func (*ElseIfClause) LastToken

func (c *ElseIfClause) LastToken() *Token

func (*ElseIfClause) WriteTo

func (cl *ElseIfClause) WriteTo(w io.Writer) (n int64, err error)

type Entry

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

Entry is the interface that all table entry nodes implement.

type EntryList

type EntryList struct {
	// Items contains each entry in the list.
	Items []Entry
	// Seps contains each separator between entries, which will be either a
	// COMMA or SEMICOLON. The length of Seps is equal to or one less than the
	// length of Entries.
	Seps []Token
}

EntryList represents a list of entries in a table.

func (*EntryList) FirstToken

func (l *EntryList) FirstToken() *Token

func (*EntryList) IsValid

func (l *EntryList) IsValid() bool

func (*EntryList) LastToken

func (l *EntryList) LastToken() *Token

func (*EntryList) Len

func (l *EntryList) Len() int

Len returns the combined length of Entries and Seps.

func (*EntryList) WriteTo

func (l *EntryList) WriteTo(w io.Writer) (n int64, err error)

type Expr

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

Expr is the interface that all Lua expressions implement.

type ExprList

type ExprList struct {
	// Items contains each expression in the list.
	Items []Expr
	// Seps contains each COMMA between expressions. The length of Seps is one
	// less than the length of Exprs.
	Seps []Token
}

ExprList represents a list of one or more Lua expressions.

func (*ExprList) FirstToken

func (l *ExprList) FirstToken() *Token

func (*ExprList) IsValid

func (l *ExprList) IsValid() bool

func (*ExprList) LastToken

func (l *ExprList) LastToken() *Token

func (*ExprList) Len

func (l *ExprList) Len() int

Len returns the combined length of Exprs and Seps.

func (*ExprList) WriteTo

func (l *ExprList) WriteTo(w io.Writer) (n int64, err error)

type FieldEntry

type FieldEntry struct {
	// NameToken is the name of the field, evaluating to the key of the entry.
	NameToken Token
	// AssignToken is the ASSIGN token that begins the entry value.
	AssignToken Token
	// Value is the expression evaluating to the value of the entry.
	Value Expr
}

FieldEntry represents a table entry defining a value with a field as the key.

func (*FieldEntry) FirstToken

func (e *FieldEntry) FirstToken() *Token

func (*FieldEntry) IsValid

func (e *FieldEntry) IsValid() bool

func (*FieldEntry) LastToken

func (e *FieldEntry) LastToken() *Token

func (*FieldEntry) WriteTo

func (e *FieldEntry) WriteTo(w io.Writer) (n int64, err error)

type FieldExpr

type FieldExpr struct {
	// Value is the expression being operated on.
	Value Expr
	// DotToken is the DOT token that separates the field.
	DotToken Token
	// NameToken is the name of the field.
	NameToken Token
}

FieldExpr represents an expression that indexes a value from another expression, by field.

func (*FieldExpr) FirstToken

func (e *FieldExpr) FirstToken() *Token

func (*FieldExpr) IsValid

func (e *FieldExpr) IsValid() bool

func (*FieldExpr) LastToken

func (e *FieldExpr) LastToken() *Token

func (*FieldExpr) WriteTo

func (e *FieldExpr) WriteTo(w io.Writer) (n int64, err error)

type File

type File struct {
	// Info contains information about the file, such as the name, and line
	// offsets.
	Info *token.File
	// Body is the top-level block of the file.
	Body Block
	// EOFToken is the EOF token at the end of the file.
	EOFToken Token
}

File is a Node representing an entire file.

func (*File) FirstToken

func (f *File) FirstToken() *Token

func (*File) IsValid

func (f *File) IsValid() bool

func (*File) LastToken

func (f *File) LastToken() *Token

func (*File) WriteTo

func (f *File) WriteTo(w io.Writer) (n int64, err error)

type FuncNameList

type FuncNameList struct {
	// Items contains the chain of one or more NAME tokens, indicating the name
	// of a function statement. Each successive name is a field of the previous
	// value.
	Items []Token
	// Seps contains each DOT between names. The length of Seps is one less than
	// the length of Exprs.
	Seps []Token
	// ColonToken is the COLON token following the last Name in Items, and
	// preceding Method. It is INVALID if the method is not present.
	ColonToken Token
	// MethodToken is a NAME token indicating the method part of the function
	// name. It is INVALID if the method is not present.
	MethodToken Token
}

FuncNameList represents a list of dot-separated names in a function statement. The list may optionally be followed by a method name, indicating that the function is a method.

func (*FuncNameList) FirstToken

func (l *FuncNameList) FirstToken() *Token

func (*FuncNameList) IsValid

func (l *FuncNameList) IsValid() bool

func (*FuncNameList) LastToken

func (l *FuncNameList) LastToken() *Token

func (*FuncNameList) Len

func (l *FuncNameList) Len() int

Len returns the combined length of Names and Seps, and ColonToken and Method, if present.

func (*FuncNameList) WriteTo

func (l *FuncNameList) WriteTo(w io.Writer) (n int64, err error)

type FunctionExpr

type FunctionExpr struct {
	// FuncToken is the FUNCTION token that begins the function.
	FuncToken Token
	// LParenToken is the LPAREN token that opens the function's parameters.
	LParenToken Token
	// Params is a list of named parameters of the function. It will be nil if
	// the function has no named parameters.
	Params *NameList
	// VarArgSepToken is the token preceding a variable-argument token. This
	// will be a COMMA when a vararg parameter follows a named parameter, and
	// INVALID otherwise.
	VarArgSepToken Token
	// VarArgToken is the VARARG token following the named parameters of the
	// function. It will be INVALID if the vararg parameter is not present.
	VarArgToken Token
	// RParenToken is the RPAREN token that closes the function's parameters.
	RParenToken Token
	// Body is the body of the function.
	Body Block
	// EndToken is the END token that ends the function.
	EndToken Token
}

FunctionExpr represents a Lua function, primarily an anonymous function expression. It is also used by other nodes for other representations of functions.

func (*FunctionExpr) FirstToken

func (s *FunctionExpr) FirstToken() *Token

func (*FunctionExpr) IsValid

func (e *FunctionExpr) IsValid() bool

func (*FunctionExpr) LastToken

func (s *FunctionExpr) LastToken() *Token

func (*FunctionExpr) WriteTo

func (e *FunctionExpr) WriteTo(w io.Writer) (n int64, err error)

type FunctionStmt

type FunctionStmt struct {
	// Name contains the name of the function. Note that tokens within this are
	// located after the FuncToken of the FunctionExpr.
	Name FuncNameList
	// Func defines the parameters and body of the function.
	Func FunctionExpr
}

FunctionStmt represents the statement that assigns a function.

func (*FunctionStmt) FirstToken

func (s *FunctionStmt) FirstToken() *Token

func (*FunctionStmt) IsValid

func (s *FunctionStmt) IsValid() bool

func (*FunctionStmt) LastToken

func (s *FunctionStmt) LastToken() *Token

func (*FunctionStmt) WriteTo

func (s *FunctionStmt) WriteTo(w io.Writer) (n int64, err error)

type GenericForStmt

type GenericForStmt struct {
	// ForToken is the FOR token that begins the for statement.
	ForToken Token
	// Names is the list of names of variables that will be assigned to by the
	// iterator.
	Names NameList
	// InToken is the IN token that separates the variables from the iterator
	// expressions.
	InToken Token
	// Iterator is the list of expressions that evaluate to the iterator of the
	// for statement.
	Iterator ExprList
	// DoToken is the DO token that begins the body of the for statement.
	DoToken Token
	// Body is the body of the for statement.
	Body Block
	// EndToken is the END token that ends the for statement.
	EndToken Token
}

GenericForStmt represents a generic `for` statement.

func (*GenericForStmt) FirstToken

func (s *GenericForStmt) FirstToken() *Token

func (*GenericForStmt) IsValid

func (s *GenericForStmt) IsValid() bool

func (*GenericForStmt) LastToken

func (s *GenericForStmt) LastToken() *Token

func (*GenericForStmt) WriteTo

func (s *GenericForStmt) WriteTo(w io.Writer) (n int64, err error)

type IfStmt

type IfStmt struct {
	// IfToken is the IF token that begins the if statement.
	IfToken Token
	// Cond is the condition of the if statement.
	Cond Expr
	// ThenToken is the THEN token that begins the body of the if statement.
	ThenToken Token
	// Body is the body of the if statement.
	Body Block
	// ElseIf is a list of zero or more elseif clauses of the if statement.
	ElseIf []ElseIfClause
	// Else is the else clause of the if statement. It is nil if not present.
	Else *ElseClause
	// EndToken is the END token that ends the if statement.
	EndToken Token
}

IfStmt represents a `if .. then .. end` statement.

func (*IfStmt) FirstToken

func (s *IfStmt) FirstToken() *Token

func (*IfStmt) IsValid

func (s *IfStmt) IsValid() bool

func (*IfStmt) LastToken

func (s *IfStmt) LastToken() *Token

func (*IfStmt) WriteTo

func (s *IfStmt) WriteTo(w io.Writer) (n int64, err error)

type IndexEntry

type IndexEntry struct {
	// LBrackToken is the LBRACK token that begins the entry key.
	LBrackToken Token
	// Key is the expression evaluating to the key of the entry.
	Key Expr
	// RBrackToken is the RBRACK token that ends the entry key.
	RBrackToken Token
	// AssignToken is the ASSIGN token that begins the entry value.
	AssignToken Token
	// Value is the expression evaluating to the value of the entry.
	Value Expr
}

IndexEntry represents a table entry defining a key-value pair.

func (*IndexEntry) FirstToken

func (e *IndexEntry) FirstToken() *Token

func (*IndexEntry) IsValid

func (e *IndexEntry) IsValid() bool

func (*IndexEntry) LastToken

func (e *IndexEntry) LastToken() *Token

func (*IndexEntry) WriteTo

func (e *IndexEntry) WriteTo(w io.Writer) (n int64, err error)

type IndexExpr

type IndexExpr struct {
	// Value is the expression being operated on.
	Value Expr
	// LBrackToken is the LBRACK token opening the key expression.
	LBrackToken Token
	// Index is the expression evaluating to the key.
	Index Expr
	// RBrackToken is the RBRACK token closing the key expression.
	RBrackToken Token
}

IndexExpr represents an expression that indexes a value from another expression, by key.

func (*IndexExpr) FirstToken

func (e *IndexExpr) FirstToken() *Token

func (*IndexExpr) IsValid

func (e *IndexExpr) IsValid() bool

func (*IndexExpr) LastToken

func (e *IndexExpr) LastToken() *Token

func (*IndexExpr) WriteTo

func (e *IndexExpr) WriteTo(w io.Writer) (n int64, err error)

type ListArgs

type ListArgs struct {
	// LParenToken is the LPAREN token that opens the argument list.
	LParenToken Token
	// Values contains each argument of the call. It is nil if the call has no
	// arguments.
	Values *ExprList
	// RParenToken is the RPAREN token that closes the argument list.
	RParenToken Token
}

ListArgs represents the arguments of a function call, in the form of a list of expressions.

func (*ListArgs) FirstToken

func (c *ListArgs) FirstToken() *Token

func (*ListArgs) IsValid

func (c *ListArgs) IsValid() bool

func (*ListArgs) LastToken

func (c *ListArgs) LastToken() *Token

func (*ListArgs) WriteTo

func (ac *ListArgs) WriteTo(w io.Writer) (n int64, err error)

type LocalFunctionStmt

type LocalFunctionStmt struct {
	// LocalToken is the LOCAL token that begins the local statement.
	LocalToken Token
	// NameToken is the name of the function. Note that this token is located
	// after the FuncToken of the FunctionExpr.
	NameToken Token
	// Func defines the parameters and body of the function.
	Func FunctionExpr
}

LocalFunctionStmt represents the statement that assigns a function to a local variable.

func (*LocalFunctionStmt) FirstToken

func (s *LocalFunctionStmt) FirstToken() *Token

func (*LocalFunctionStmt) IsValid

func (s *LocalFunctionStmt) IsValid() bool

func (*LocalFunctionStmt) LastToken

func (s *LocalFunctionStmt) LastToken() *Token

func (*LocalFunctionStmt) WriteTo

func (s *LocalFunctionStmt) WriteTo(w io.Writer) (n int64, err error)

type LocalVarStmt

type LocalVarStmt struct {
	// LocalToken is the LOCAL token that begins the local statement.
	LocalToken Token
	// Names contains the name of each variable in the local statement.
	Names NameList
	// AssignToken is the ASSIGN token that separates the variables from the
	// values. It is INVALID if not present.
	AssignToken Token
	// Values is the list of expressions that are assigned to each variable. It
	// is nil if not present.
	Values *ExprList
}

LocalVarStmt represents the statement that assigns local variables.

func (*LocalVarStmt) FirstToken

func (s *LocalVarStmt) FirstToken() *Token

func (*LocalVarStmt) IsValid

func (s *LocalVarStmt) IsValid() bool

func (*LocalVarStmt) LastToken

func (s *LocalVarStmt) LastToken() *Token

func (*LocalVarStmt) WriteTo

func (s *LocalVarStmt) WriteTo(w io.Writer) (n int64, err error)

type MethodExpr

type MethodExpr struct {
	// Value is the expression being operated on.
	Value Expr
	// ColonToken is the COLON token that separates the method name.
	ColonToken Token
	// NameToken is the name of the method.
	NameToken Token
	// Args holds the arguments of the method call.
	Args Args
}

MethodExpr represents an expression that gets and calls a method on another expression.

func (*MethodExpr) FirstToken

func (e *MethodExpr) FirstToken() *Token

func (*MethodExpr) IsValid

func (e *MethodExpr) IsValid() bool

func (*MethodExpr) LastToken

func (e *MethodExpr) LastToken() *Token

func (*MethodExpr) WriteTo

func (e *MethodExpr) WriteTo(w io.Writer) (n int64, err error)

type NameList

type NameList struct {
	// Items contains each NAME in the list.
	Items []Token
	// Seps contains each COMMA between names. The length of Seps is one less
	// then the length of Names.
	Seps []Token
}

NameList represents a list of one or more name expressions.

func (*NameList) FirstToken

func (l *NameList) FirstToken() *Token

func (*NameList) IsValid

func (l *NameList) IsValid() bool

func (*NameList) LastToken

func (l *NameList) LastToken() *Token

func (*NameList) Len

func (l *NameList) Len() int

Len returns the combined length of Names and Seps.

func (*NameList) WriteTo

func (l *NameList) WriteTo(w io.Writer) (n int64, err error)

type NilExpr

type NilExpr struct {
	// NilToken is the NIL token holding the content the expression.
	NilToken Token
}

NilExpr represents a Lua nil expression.

func (*NilExpr) FirstToken

func (e *NilExpr) FirstToken() *Token

func (*NilExpr) IsValid

func (e *NilExpr) IsValid() bool

func (*NilExpr) LastToken

func (e *NilExpr) LastToken() *Token

func (*NilExpr) WriteTo

func (e *NilExpr) WriteTo(w io.Writer) (n int64, err error)

type Node

type Node interface {
	// IsValid returns whether the node is well-formed (child nodes excluded).
	IsValid() bool
	// FirstToken returns the first Token in the node. Assumes that the node is
	// valid.
	FirstToken() *Token
	// LastToken returns the last Token in the node. Assumes that the node is
	// valid.
	LastToken() *Token
	// Implements the io.WriterTo interface by writing the source-code
	// equivalent of the node. Assumes that the node is valid.
	io.WriterTo
}

Node is the interface that all tree nodes implement.

type NumberExpr

type NumberExpr struct {
	// NumberToken is the number token holding the content of the expression.
	NumberToken Token
}

NumberExpr represents a Lua number expression.

func (*NumberExpr) FirstToken

func (e *NumberExpr) FirstToken() *Token

func (*NumberExpr) FormatValue

func (e *NumberExpr) FormatValue(v float64, fmt byte, prec int)

FormatValue formats the absolute value of a given number, setting the result to the bytes of the token.

When fmt is 'e', 'E', 'f', 'g', or 'G', the number is formatted as a float with the NUMBERFLOAT type, and fmt and prec follow the same rules as in strconv.ParseFloat.

When fmt is 'd', 'i', or 'u', the number is formatted as a base-10 integer with the NUMBERFLOAT type. The prec argument is unused.

When fmt is 'x' or 'X', the number is formatted as a base-16 number with the NUMBERHEX type. The prec argument is unused.

When fmt is 0, the format is determined by the current token type, and uses the shortest representation of the number. The prec argument is unused.

func (*NumberExpr) IsValid

func (e *NumberExpr) IsValid() bool

func (*NumberExpr) LastToken

func (e *NumberExpr) LastToken() *Token

func (*NumberExpr) ParseValue

func (e *NumberExpr) ParseValue() (v float64, err error)

ParseValue parses the content of the number token and returns the resulting value, or an error explaining why the value could not be parsed.

func (*NumberExpr) WriteTo

func (e *NumberExpr) WriteTo(w io.Writer) (n int64, err error)

type NumericForStmt

type NumericForStmt struct {
	// ForToken is the FOR token that begins the for statement.
	ForToken Token
	// NameToken is the name of the control variable.
	NameToken Token
	// AssignToken is the ASSIGN token that begins the control expressions.
	AssignToken Token
	// Min is the expression indicating the lower bound of the control variable.
	Min Expr
	// MaxSepToken is the COMMA token that separates the lower and upper bound.
	MaxSepToken Token
	// Max is the expression indicating the upper bound of the control variable.
	Max Expr
	// StepSepToken is the separator token between the upper bound and the step
	// expressions. It is a COMMA if the step is present, and INVALID otherwise.
	StepSepToken Token
	// Step is the expression indicating the step of the control variable. It is
	// nil if not present.
	Step Expr
	// DoToken is the DO token that begins the body of the for statement.
	DoToken Token
	// Body is the body of the for statement.
	Body Block
	// EndToken is the END token that ends the for statement.
	EndToken Token
}

NumericForStmt represents a numeric `for` statement.

func (*NumericForStmt) FirstToken

func (s *NumericForStmt) FirstToken() *Token

func (*NumericForStmt) IsValid

func (s *NumericForStmt) IsValid() bool

func (*NumericForStmt) LastToken

func (s *NumericForStmt) LastToken() *Token

func (*NumericForStmt) WriteTo

func (s *NumericForStmt) WriteTo(w io.Writer) (n int64, err error)

type ParenExpr

type ParenExpr struct {
	// LParenToken is the LPAREN token that opens the expression.
	LParenToken Token
	// Value is the enclosed expression.
	Value Expr
	// RParenToken is the RPAREN token that closes the expression.
	RParenToken Token
}

ParenExpr represents an expression enclosed in parentheses.

func (*ParenExpr) FirstToken

func (e *ParenExpr) FirstToken() *Token

func (*ParenExpr) IsValid

func (e *ParenExpr) IsValid() bool

func (*ParenExpr) LastToken

func (e *ParenExpr) LastToken() *Token

func (*ParenExpr) WriteTo

func (e *ParenExpr) WriteTo(w io.Writer) (n int64, err error)

type Prefix

type Prefix struct {
	Type  token.Type
	Bytes []byte
}

Prefix represents a token that precedes a Token. A token.Type is a prefix when Type.IsPrefix returns true.

type RepeatStmt

type RepeatStmt struct {
	// RepeatToken is the REPEAT token that begins the repeat statement.
	RepeatToken Token
	// Body is the body of the repeat statement.
	Body Block
	// UntilToken is the UNTIL token that ends the body of the repeat statement.
	UntilToken Token
	// Cond is the condition of the repeat statement.
	Cond Expr
}

RepeatStmt represents a `repeat .. until ..` statement.

func (*RepeatStmt) FirstToken

func (s *RepeatStmt) FirstToken() *Token

func (*RepeatStmt) IsValid

func (s *RepeatStmt) IsValid() bool

func (*RepeatStmt) LastToken

func (s *RepeatStmt) LastToken() *Token

func (*RepeatStmt) WriteTo

func (s *RepeatStmt) WriteTo(w io.Writer) (n int64, err error)

type ReturnStmt

type ReturnStmt struct {
	// ReturnToken is the RETURN token of the return statement.
	ReturnToken Token
	// Values is the list of expressions that evaluate to the values being
	// returned. Will be nil if there are no values.
	Values *ExprList
}

ReturnStmt represents a `return` statement.

func (*ReturnStmt) FirstToken

func (s *ReturnStmt) FirstToken() *Token

func (*ReturnStmt) IsValid

func (s *ReturnStmt) IsValid() bool

func (*ReturnStmt) LastToken

func (s *ReturnStmt) LastToken() *Token

func (*ReturnStmt) WriteTo

func (s *ReturnStmt) WriteTo(w io.Writer) (n int64, err error)

type Stmt

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

Stmt is the interface that all statement nodes implement.

type StringArg

type StringArg struct {
	// Value is the string expression.
	Value StringExpr
}

StringArg represents the arguments of a function call, in the form of a single string expression.

func (*StringArg) FirstToken

func (c *StringArg) FirstToken() *Token

func (*StringArg) IsValid

func (c *StringArg) IsValid() bool

func (*StringArg) LastToken

func (c *StringArg) LastToken() *Token

func (*StringArg) WriteTo

func (sc *StringArg) WriteTo(w io.Writer) (n int64, err error)

type StringExpr

type StringExpr struct {
	// StringToken is the string token holding the content the expression.
	StringToken Token
}

StringExpr represents a Lua string expression.

func (*StringExpr) FirstToken

func (e *StringExpr) FirstToken() *Token

func (*StringExpr) FormatValue

func (e *StringExpr) FormatValue(v string, newline bool)

FormatValue receives a string and formats it, setting it to the bytes of the token. The format is determined by the current token type.

When the token is a STRING, the result is the same as the "%q" verb in Lua's string.format.

When the token is a LONGSTRING, the result is enclosed in the shortest possible set of long brackets. If the newline argument is true, then the result will be formatted with a newline at the start, which is ignored by the parser.

func (*StringExpr) IsValid

func (e *StringExpr) IsValid() bool

func (*StringExpr) LastToken

func (e *StringExpr) LastToken() *Token

func (*StringExpr) ParseValue

func (e *StringExpr) ParseValue() (v string, err error)

ParseValue parses the content of the string token and returns the resulting value, or an error explaining why the value could not be parsed.

func (*StringExpr) WriteTo

func (e *StringExpr) WriteTo(w io.Writer) (n int64, err error)

type TableArg

type TableArg struct {
	// Value is the table constructor expression.
	Value TableCtor
}

TableArg represents the arguments of a function call, in the form of a single table constructor.

func (*TableArg) FirstToken

func (c *TableArg) FirstToken() *Token

func (*TableArg) IsValid

func (c *TableArg) IsValid() bool

func (*TableArg) LastToken

func (c *TableArg) LastToken() *Token

func (*TableArg) WriteTo

func (tc *TableArg) WriteTo(w io.Writer) (n int64, err error)

type TableCtor

type TableCtor struct {
	// LBraceToken is the LBRACE token that opens the table.
	LBraceToken Token
	// Entries a list of entries in the table.
	Entries EntryList
	// RBraceToken is the RBRACE token that closes the table.
	RBraceToken Token
}

TableCtor represents a table constructor expression.

func (*TableCtor) FirstToken

func (e *TableCtor) FirstToken() *Token

func (*TableCtor) IsValid

func (e *TableCtor) IsValid() bool

func (*TableCtor) LastToken

func (e *TableCtor) LastToken() *Token

func (*TableCtor) WriteTo

func (e *TableCtor) WriteTo(w io.Writer) (n int64, err error)

type Token

type Token struct {
	// Type indicates the token's type.
	Type token.Type
	// Prefix holds a list of Prefix tokens that precede this token, ordered
	// left to right.
	Prefix []Prefix
	// Offset is the location of the token within a file.
	Offset int
	// Bytes contains the actual bytes of a file that the token represents.
	Bytes []byte
}

A Token represents a token within a file.

func (*Token) EndOffset

func (t *Token) EndOffset() int

EndOffset returns the offset following the end of the token.

func (*Token) StartOffset

func (t *Token) StartOffset() int

StartOffset returns the offset at the start of the token, which includes the prefix.

func (Token) WriteTo

func (t Token) WriteTo(w io.Writer) (n int64, err error)

type TokenVisitor

type TokenVisitor interface {
	Visitor
	VisitToken(node Node, n int, tok *Token)
}

A TokenVisitor extends a Visitor. If a Visitor is a TokenVisitor, then Walk will call w.VisitToken(node, n, token) for each token encountered.

The n argument indicates nth token of the current node. Combined with the node type, this can be used to identify the token field being referred to. For example, (DoStmt, 0) refers to DoStmt.DoToken, which is a DO token, and (DoStmt, 1) refers to DoStmt.EndToken, which is an END token. For nodes like NameList, an even value indicates a NAME token in the Items field, while an odd value indicates a COMMA token in the Seps field.

Tokens are guaranteed to be visited in lexical order.

type UnopExpr

type UnopExpr struct {
	// UnopToken is the unary operator token.
	UnopToken Token
	// Operand is the expression being operated on.
	Operand Expr
}

UnopExpr represents a unary operation.

func (*UnopExpr) FirstToken

func (e *UnopExpr) FirstToken() *Token

func (*UnopExpr) IsValid

func (e *UnopExpr) IsValid() bool

func (*UnopExpr) LastToken

func (e *UnopExpr) LastToken() *Token

func (*UnopExpr) WriteTo

func (e *UnopExpr) WriteTo(w io.Writer) (n int64, err error)

type ValueEntry

type ValueEntry struct {
	// Value is the expression evaluating to the value of the entry.
	Value Expr
}

ValueEntry represents a table entry defining a value with a numerical key.

func (*ValueEntry) FirstToken

func (e *ValueEntry) FirstToken() *Token

func (*ValueEntry) IsValid

func (e *ValueEntry) IsValid() bool

func (*ValueEntry) LastToken

func (e *ValueEntry) LastToken() *Token

func (*ValueEntry) WriteTo

func (e *ValueEntry) WriteTo(w io.Writer) (n int64, err error)

type VarArgExpr

type VarArgExpr struct {
	// VarArgToken is the VARARG token holding the content the expression.
	VarArgToken Token
}

VarArgExpr represents a Lua variable argument expression.

func (*VarArgExpr) FirstToken

func (e *VarArgExpr) FirstToken() *Token

func (*VarArgExpr) IsValid

func (e *VarArgExpr) IsValid() bool

func (*VarArgExpr) LastToken

func (e *VarArgExpr) LastToken() *Token

func (*VarArgExpr) WriteTo

func (e *VarArgExpr) WriteTo(w io.Writer) (n int64, err error)

type VariableExpr

type VariableExpr struct {
	// NameToken is the token indicating the name of the variable.
	NameToken Token
}

VariableExpr represents a variable name used as an expression.

func (*VariableExpr) FirstToken

func (e *VariableExpr) FirstToken() *Token

func (*VariableExpr) IsValid

func (e *VariableExpr) IsValid() bool

func (*VariableExpr) LastToken

func (e *VariableExpr) LastToken() *Token

func (*VariableExpr) WriteTo

func (e *VariableExpr) WriteTo(w io.Writer) (n int64, err error)

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

A Visitor's Visit method is called for each node encountered by Walk. If the result visitor w is not nil, Walk visits each child of the node with w, followed by a call of w.Visit(nil).

type WhileStmt

type WhileStmt struct {
	// WhileToken is the WHILE token that begins a while statement.
	WhileToken Token
	// Cond is the condition of the while statement.
	Cond Expr
	// DoToken is the DO token that begins the body of the while statement.
	DoToken Token
	// Body is body of the while statement.
	Body Block
	// EndToken is the END token that ends the while statement.
	EndToken Token
}

WhileStmt represents a `while .. do .. end` statement.

func (*WhileStmt) FirstToken

func (s *WhileStmt) FirstToken() *Token

func (*WhileStmt) IsValid

func (s *WhileStmt) IsValid() bool

func (*WhileStmt) LastToken

func (s *WhileStmt) LastToken() *Token

func (*WhileStmt) WriteTo

func (s *WhileStmt) WriteTo(w io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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