token

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: 2 Imported by: 0

Documentation

Overview

The token package defines constants representing the lexical tokens of the Lua programming language.

Index

Constants

View Source
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 NewFile

func NewFile(filename string) *File

NewFile creates a new file with the given name.

func (*File) AddLine

func (f *File) AddLine(offset int)

AddLine specifies the location of the start of a line in the file.

func (*File) ClearLines

func (f *File) ClearLines()

ClearLines resets the line offsets for a file.

func (*File) LineCount

func (f *File) LineCount() (c int)

Returns the number of lines in the file.

func (*File) Name

func (f *File) Name() string

Name returns the name of the file.

func (*File) Position

func (f *File) Position(offset int) (pos Position)

Position returns the Position value for a given offset within the file.

func (*File) SetLinesForContent

func (f *File) SetLinesForContent(content []byte)

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.

func (*Position) IsValid

func (pos *Position) IsValid() bool

IsValid returns whether the position is valid.

func (Position) String

func (pos Position) String() string

String returns a formatted representation of the position, which may be one of several forms:

file:line:column    Filename with valid position.
line:column         No filename with valid position.
file                Filename with invalid position.
-                   No filename with invalid position.

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 Lookup

func Lookup(name string) Type

Lookup maps a name to its keyword, or NAME if it is not a keyword.

func (Type) AdjoinSeparator

func (left Type) AdjoinSeparator(right Type) rune

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) IsBinary

func (t Type) IsBinary() bool

IsBinary returns whether the type indicates a binary operator.

func (Type) IsBool

func (t Type) IsBool() bool

IsBool returns whether the type indicates a boolean value.

func (Type) IsComment

func (t Type) IsComment() bool

IsComment returns whether the type indicates a comment.

func (Type) IsKeyword

func (t Type) IsKeyword() bool

IsKeyword returns whether the type indicates a keyword.

func (Type) IsNumber

func (t Type) IsNumber() bool

IsNumber returns whether the type indicates a number value.

func (Type) IsOperator

func (t Type) IsOperator() bool

IsOperator returns whether the type indicates an operator.

func (Type) IsPrefix

func (t Type) IsPrefix() bool

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) IsString

func (t Type) IsString() bool

IsString returns whether the type indicates a string value.

func (Type) IsUnary

func (t Type) IsUnary() bool

IsUnary returns whether the type indicates a unary operator.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid returns whether the type is valid.

func (Type) Precedence

func (t Type) Precedence() [2]int

Precedence returns the priority of binary operators. The returned numbers indicate the left and right priorities, respectively.

func (Type) String

func (t Type) String() (s string)

String returns a string representation of the token type, when possible.

Jump to

Keyboard shortcuts

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