token

package
v0.0.0-...-5c64afc Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidPos = Pos(-1)
View Source
var Reserved = map[string]TokenType{
	"and":      AND,
	"break":    BREAK,
	"do":       DO,
	"else":     ELSE,
	"elseif":   ELSEIF,
	"end":      END,
	"false":    FALSE,
	"for":      FOR,
	"function": FUNCTION,
	"goto":     GOTO,
	"if":       IF,
	"in":       IN,
	"local":    LOCAL,
	"nil":      NIL,
	"not":      NOT,
	"or":       OR,
	"repeat":   REPEAT,
	"return":   RETURN,
	"then":     THEN,
	"true":     TRUE,
	"until":    UNTIL,
	"while":    WHILE,

	"@class": DOC_CLASS,
}
View Source
var TokenStr = map[TokenType]string{
	INVALID:    "invalid",
	EOF:        "eof",
	IDENT:      "identifier",
	LABEL:      "label",
	COMMENT:    "comment",
	WHITESPACE: "whitespace",

	BREAK:    "break",
	DO:       "do",
	ELSE:     "else",
	ELSEIF:   "elseif",
	END:      "end",
	FOR:      "for",
	FUNCTION: "function",
	GOTO:     "goto",
	IF:       "if",
	IN:       "in",
	LOCAL:    "local",
	REPEAT:   "repeat",
	RETURN:   "return",
	THEN:     "then",
	UNTIL:    "until",
	WHILE:    "while",

	FALSE:     "false",
	NIL:       "nil",
	NUMBER:    "number",
	RAWSTRING: "rawstring",
	STRING:    "string",
	TRUE:      "true",

	AND:    "and",
	ASSIGN: "assign",
	POW:    "pow",
	EQUAL:  "equal",
	GEQ:    "geq",
	GT:     "gt",
	LEN:    "len",
	LEQ:    "leq",
	LT:     "lt",
	MINUS:  "minus",
	NEQ:    "neq",
	NOT:    "not",
	OR:     "or",
	MOD:    "mod",
	PLUS:   "plus",
	SLASH:  "slash",
	MUL:    "mul",

	LPAREN: "left paren",
	RPAREN: "right paren",
	LBRACK: "left bracket",
	RBRACK: "right bracket",
	LBRACE: "left brace",
	RBRACE: "right brace",

	COLON:     "colon",
	COMMA:     "comma",
	CONCAT:    "concat",
	DOT:       "dot",
	SEMICOLON: "semicolon",
	VARARG:    "vararg",

	DOC_CLASS: "@class",
}

Functions

This section is empty.

Types

type LineBreaks

type LineBreaks []int

func (LineBreaks) ToPos

func (f LineBreaks) ToPos(position protocol.Position) Pos

func (LineBreaks) ToProtocolPos

func (f LineBreaks) ToProtocolPos(pos Pos) protocol.Position

func (LineBreaks) ToProtocolRange

func (f LineBreaks) ToProtocolRange(rng Range) protocol.Range

type Pos

type Pos = int

type Range

type Range struct {
	Start int
	End   int
}

func (*Range) ContainsPos

func (r *Range) ContainsPos(pos Pos) bool

func (*Range) ContainsRange

func (r *Range) ContainsRange(rng Range) bool

func (*Range) String

func (r *Range) String() string

type Token

type Token struct {
	Type    TokenType
	Literal string
	Pos     Pos
}

func (Token) End

func (t Token) End() int

func (*Token) Range

func (t *Token) Range() Range

func (*Token) String

func (t *Token) String() string

type TokenType

type TokenType int
const (
	INVALID TokenType = iota
	EOF
	COMMENT
	WHITESPACE

	// Variable
	IDENT
	LABEL

	// Keywords
	BREAK
	DO
	ELSE
	ELSEIF
	END
	FOR
	FUNCTION
	GOTO
	IF
	IN
	LOCAL
	REPEAT
	RETURN
	THEN
	UNTIL
	WHILE

	// Literals
	FALSE
	NIL
	NUMBER
	RAWSTRING
	STRING
	TRUE

	// Operators
	AND
	ASSIGN
	POW
	CONCAT
	EQUAL
	GEQ
	GT
	LEN
	LEQ
	LT
	MINUS
	NEQ
	NOT
	OR
	MOD
	PLUS
	SLASH
	MUL

	// Structure
	LPAREN
	RPAREN
	LBRACK
	RBRACK
	LBRACE
	RBRACE

	// Grammar
	COLON
	COMMA
	DOT
	SEMICOLON
	VARARG

	// Annotation
	DOC_CLASS
)

func (*TokenType) MarshalJSON

func (t *TokenType) MarshalJSON() ([]byte, error)

func (TokenType) String

func (t TokenType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳