token

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

token package is used to define the token types and the Token struct.

The TokenType type is a string that represents the type of a token. The Token struct has two fields: Type and Literal.

1. Type is the type of the token, and

2. Literal is the actual value of the token.

csvlang has some reserved keywords and the keywords map is used to store them.

Index

Constants

View Source
const (
	ILLEGAL = "ILLEGAL" // unknown token
	EOF     = "EOF"     // end of file

	// Identifiers + literals
	IDENT  = "IDENT"  // add, foobar, x, y, ...
	INT    = "INT"    // 1343456
	STRING = "STRING" // "foobar"

	// Operators
	ASSIGN   = "="
	PLUS     = "+"
	MINUS    = "-"
	BANG     = "!"
	ASTERISK = "*"
	SLASH    = "/"
	LT       = "<"
	GT       = ">"
	EQ       = "=="
	NOT_EQ   = "!="

	// Delimiters
	COMMA     = "," // acts as a delimiter in arrays
	SEMICOLON = ";"
	NEWLINE   = "\\n" // Add this line

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

	// Comment
	SINGLE_LINE_COMMENT = "#"

	// Keywords
	LOAD     = "LOAD" // load csv file
	READ     = "READ" // read data from the loaded csv file
	UPDATE   = "UPDATE"
	DELETE   = "DELETE"
	FUNCTION = "FUNCTION"
	LET      = "LET"
	TRUE     = "TRUE"
	FALSE    = "FALSE"
	IF       = "IF"
	FOR      = "FOR"
	IN       = "IN"
	ELSE     = "ELSE"
	RETURN   = "RETURN"
	SAVE     = "SAVE"
	AS       = "AS" // used in "save rows as filtered.csv" statements

	ROW   = "ROW"   // read particular rows from the loaded csv file
	COL   = "COL"   // read particular columns from the loaded csv rows
	WHERE = "WHERE" // filter rows based on a condition
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type    TokenType
	Literal string
}

type TokenType

type TokenType string

func LookupIdent

func LookupIdent(ident string) TokenType

LookupIdent checks if the given identifier is a keyword defaults to IDENT if not a keyword

Example:

LookupIdent("fn") // returns FUNCTION
LookupIdent("abc") // returns IDENT

Jump to

Keyboard shortcuts

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