token

package
v0.0.0-...-cad9b24 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ILLEGAL = "ILLEGAL"
	UNKNOWN = "UNKNOWN"
	EOF     = "EOF"

	// Literals
	STRING = "string"
	NUMBER = "number"
	FLOAT  = "float"
	BOOL   = "bool"

	// Operators
	ASSIGN          = "="
	INFER           = ":="
	PLUS            = "+"
	PLUS_EQUALS     = "+="
	MINUS           = "-"
	MINUS_EQUALS    = "-="
	ASTERISK        = "*"
	ASTERISK_EQUALS = "*="
	SLASH           = "/"
	SLASH_EQUALS    = "/="
	MOD             = "%"
	AND             = "&&"
	AMPERSAND       = "&"
	OR              = "||"
	PIPE            = "|"
	EQ              = "=="
	NOT_EQ          = "!="
	LT              = "<"
	LT_EQUALS       = "<="
	GT              = ">"
	GT_EQUALS       = ">="
	QUESTION        = "?"
	SLASH_SLASH     = "//"
	SLASH_ASTERISK  = "/*"
	ASTERISK_SLASH  = "/*"

	// Delimiters
	COMMA     = ","
	COLON     = ":"
	SEMICOLON = ";"
	DOT       = "."

	LPAREN   = "("
	RPAREN   = ")"
	LBRACE   = "{"
	RBRACE   = "}"
	LBRACKET = "["
	RBRACKET = "]"

	// Keywords
	FUNCTION  = "FUNCTION"
	CONST     = "CONST"
	LET       = "LET"
	RETURN    = "RETURN"
	IF        = "if"
	ELSE      = "else"
	PUB       = "pub"
	PACKAGE   = "pkg"
	IMPORT    = "import"
	INTERFACE = "interface"
	STRUCT    = "struct"
	TEST      = "test"
	ENUM      = "enum"
	DEFER     = "defer"

	IDENTIFIER = "IDENTIFIER"

	TRUE  = "true"
	FALSE = "false"

	BANG = "!"
)

Token types

View Source
const (
	U8  = "u8"
	U16 = "u16"
	U32 = "u32"
	U64 = "u64"
	I8  = "i8"
	I16 = "i16"
	I32 = "i32"
	I64 = "i64"
	F32 = "f32"
	F64 = "f64"
)

Variables

View Source
var Keywords = map[Type]string{
	PACKAGE:   "pkg",
	IMPORT:    "import",
	INTERFACE: "interface",
	STRUCT:    "struct",
	TEST:      "test",
	ENUM:      "enum",
	RETURN:    "return",
	CONST:     "const",
	LET:       "let",
	IF:        "if",
	ELSE:      "else",
	TRUE:      "true",
	FALSE:     "false",
	PUB:       "pub",
}

Functions

func Match

func Match(t1, t2 Token) bool

Types

type Token

type Token struct {
	Type     Type
	Literal  string
	Position scanner.Position
}

func (Token) IsFloat

func (t Token) IsFloat() bool

func (Token) IsFloatInt

func (t Token) IsFloatInt() bool

func (Token) IsIdentRune

func (t Token) IsIdentRune(ch rune, i int) bool

func (Token) IsIdentifier

func (t Token) IsIdentifier() bool

func (Token) IsInt

func (t Token) IsInt() bool

func (Token) IsKeyword

func (t Token) IsKeyword() bool

func (Token) IsNumber

func (t Token) IsNumber() bool

func (Token) IsOperator

func (t Token) IsOperator() bool

func (Token) IsSingleCharIdentifier

func (t Token) IsSingleCharIdentifier() bool

func (Token) IsString

func (t Token) IsString() bool

func (Token) String

func (t Token) String() string

String formats a token as a string for pretty printing.

type TokenCollector

type TokenCollector interface {
	Collect(token Token)
	Result() []Token
}

type Type

type Type string

Jump to

Keyboard shortcuts

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