token

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package token contains constants which are used when lexing a program written in the monkey language, as done by the parser.

Index

Constants

View Source
const (
	AND             = "&&"
	ASSIGN          = "="
	ASTERISK        = "*"
	ASTERISK_EQUALS = "*="
	BACKTICK        = "`"
	FSTRING         = "'"
	BANG            = "!"
	CASE            = "case"
	COLON           = ":"
	COMMA           = ","
	CONST           = "CONST"
	DECLARE         = ":="
	DEFAULT         = "DEFAULT"
	FUNC            = "FUNC"
	ELSE            = "ELSE"
	EOF             = "EOF"
	EQ              = "=="
	FALSE           = "FALSE"
	FLOAT           = "FLOAT"
	FOR             = "FOR"
	GT              = ">"
	GT_EQUALS       = ">="
	IDENT           = "IDENT"
	IF              = "IF"
	ILLEGAL         = "ILLEGAL"
	INT             = "INT"
	LBRACE          = "{"
	LBRACKET        = "["
	LPAREN          = "("
	LT              = "<"
	LT_EQUALS       = "<="
	MINUS           = "-"
	MINUS_EQUALS    = "-="
	MINUS_MINUS     = "--"
	MOD             = "%"
	NOT_EQ          = "!="
	NIL             = "nil"
	PIPE            = "|"
	OR              = "||"
	PERIOD          = "."
	PLUS            = "+"
	PLUS_EQUALS     = "+="
	PLUS_PLUS       = "++"
	POW             = "**"
	QUESTION        = "?"
	RBRACE          = "}"
	RBRACKET        = "]"
	RETURN          = "RETURN"
	RPAREN          = ")"
	SEMICOLON       = ";"
	SLASH           = "/"
	SLASH_EQUALS    = "/="
	STRING          = "STRING"
	SWITCH          = "switch"
	TRUE            = "TRUE"
	NEWLINE         = "EOL"
	IMPORT          = "IMPORT"
	BREAK           = "BREAK"
	CONTINUE        = "CONTINUE"
	VAR             = "VAR"
	IN              = "IN"
	RANGE           = "RANGE"
)

pre-defined Type

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Value     rune
	Char      int
	LineStart int
	Line      int
	Column    int
	File      string
}

Position points to a particular location in an input string. It helps track offset since the beginning of the input as well as line offsets.

func (Position) ColumnNumber

func (p Position) ColumnNumber() int

func (Position) LineNumber

func (p Position) LineNumber() int

type Token

type Token struct {
	Type          Type
	Literal       string
	StartPosition Position
	EndPosition   Position
}

Token struct represent the lexer token

type Type

type Type string

Type is a string

func LookupIdentifier

func LookupIdentifier(identifier string) Type

LookupIdentifier used to determinate whether identifier is keyword nor not

Jump to

Keyboard shortcuts

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