token

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

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Illegal is used to identify illegal (unknown) token types
	Illegal = Type("Illegal")

	// EOF is used to identify end of file, the parser can stop after this
	EOF = Type("EOF")

	// Identifier is used for use inputs such as x, y, z ...
	Identifier = Type("Identifier")

	// Primitive types
	Int    = Type("Int")
	String = Type("String")

	// Operators
	Assign          = Type("=")
	Plus            = Type("+")
	Minus           = Type("-")
	ExclamationMark = Type("!")
	Asterisk        = Type("*")
	Slash           = Type("/")
	LessThan        = Type("<")
	GreaterThan     = Type(">")
	Equal           = Type("==")
	NotEqual        = Type("!=")

	// Delimiters
	Comma            = Type(",")
	SemiColon        = Type(";")
	LeftParenthesis  = Type("(")
	RightParenthesis = Type(")")
	LeftBrace        = Type("{")
	RightBrace       = Type("}")
	LeftBracket      = Type("[")
	RightBracket     = Type("]")
	Colon            = Type(":")

	// Keywords
	Function = Type("Function")
	Let      = Type("Let")
	True     = Type("True")
	False    = Type("False")
	If       = Type("If")
	Else     = Type("Else")
	Return   = Type("Return")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type    Type
	Literal string
}

Token represents a token abstraction that is used in lexer logic

func (*Token) Set

func (t *Token) Set(typ Type, literal byte)

Set sets the fields of the token type

type Type

type Type string

Type identifies the token type and is just an alias to string type. String type is easier to work with when debugging, but in the ideal case scenario int or byte should be used for performance.

func ParseIdentifier

func ParseIdentifier(input string) Type

ParseIdentifier is used to parse a string to a token type. For user inputs that are not in gohil's keywords, the result should be of Identifier value

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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