Documentation
¶
Overview ¶
The token package defines constants representing the lexical tokens of the Lua programming language.
Index ¶
- Constants
- type File
- type Position
- type Type
- func (left Type) AdjoinSeparator(right Type) rune
- func (t Type) IsBinary() bool
- func (t Type) IsBool() bool
- func (t Type) IsComment() bool
- func (t Type) IsKeyword() bool
- func (t Type) IsNumber() bool
- func (t Type) IsOperator() bool
- func (t Type) IsPrefix() bool
- func (t Type) IsString() bool
- func (t Type) IsUnary() bool
- func (t Type) IsValid() bool
- func (t Type) Precedence() [2]int
- func (t Type) String() (s string)
Constants ¶
const UnaryPrecedence = 8
UnaryPrecedence indicates the priority of unary operators.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
A File represents a Lua source file. Methods are safe to use concurrently.
func (*File) ClearLines ¶
func (f *File) ClearLines()
ClearLines resets the line offsets for a file.
func (*File) SetLinesForContent ¶
SetLinesForContent sets the line offset for a given file content.
type Position ¶
type Position struct {
Filename string // The name of the file, if specified.
Offset int // The offset within the file, starting at 0.
Line int // The line number, starting at 1.
Column int // The column number, starting at 1.
}
A Position describes a position with a file, including the name of the file, the line, and the column.
type Type ¶
type Type int
Type indicates the type of a token.
const ( INVALID Type = iota EOF // End of file marker SPACE // Whitespace sequence COMMENT // Line-style comment LONGCOMMENT // Block-style comment NAME // Identifier NUMBERFLOAT // Float number NUMBERHEX // Hexadecimal number STRING // Quote-style string LONGSTRING // Block-style string SEMICOLON // `;` operator ASSIGN // `=` operator COMMA // `,` operator DOT // `.` operator COLON // `:` operator LBRACK // `[` operator RBRACK // `]` operator VARARG // `...` operator LPAREN // `(` operator RPAREN // `)` operator LBRACE // `{` operator RBRACE // `}` operator PLUS // `+` binary operator ASTERISK // `*` binary operator SLASH // `/` binary operator PERCENT // `%` binary operator CARET // `^` binary operator CONCAT // `..` binary operator LT // `<` binary operator LEQ // `<=` binary operator GT // `>` binary operator GEQ // `>=` binary operator EQ // `==` binary operator NEQ // `~=` binary operator MINUS // `-` binary / unary operator HASH // `#` unary operator NOT // `not` keyword / unary operator WHILE // `while` keyword UNTIL // `until` keyword IF // `if` keyword ELSEIF // `elseif` keyword IN // `in` keyword RETURN // `return` keyword AND // `and` keyword / binary operator OR // `or` keyword / binary operator DO // `do` keyword END // `end` keyword REPEAT // `repeat` keyword THEN // `then` keyword ELSE // `else` keyword FOR // `for` keyword LOCAL // `local` keyword FUNCTION // `function` keyword BREAK // `break` keyword NIL // `nil` keyword FALSE // `false` keyword / boolean TRUE // `true` keyword / boolean )
func (Type) AdjoinSeparator ¶
AdjoinSeparator returns the character that would allow a token of type 'left' to precede a token of type 'right', if placed as a SPACE token between the two. Currently, this is '\n' for COMMENTs, and a space for everything else.
Returns -1 if the two tokens are allowed to be adjacent. Note that this is returned by tokens that will never be adjacent while being syntactically correct.
Returns -2 if the allowed adjacency of the two tokens depends on the content of the tokens.
func (Type) IsOperator ¶
IsOperator returns whether the type indicates an operator.
func (Type) IsPrefix ¶
IsPrefix returns whether the type is considered non-essential data. When parsing, prefixes are held within a token structure as extra data that precedes the main content.
Spaces and comments are treated as prefixes.
func (Type) Precedence ¶
Precedence returns the priority of binary operators. The returned numbers indicate the left and right priorities, respectively.