token

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package token defines the token types used by the lexer and parser for the English programming language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type  Type
	Value string
	Line  int
	Col   int
	Pos   int // byte offset of the token's first character in the source string
}

Token represents a single token from the lexer

type Type

type Type int

Type represents different token types in the English language

const (
	// Special tokens
	EOF Type = iota
	ERROR
	NEWLINE

	// Literals
	NUMBER
	STRING
	IDENTIFIER

	// Keywords
	DECLARE
	LET
	EQUAL
	FUNCTION
	THAT
	DOES
	FOLLOWING
	THATS
	IT
	TO
	BE
	ALWAYS
	SET
	CALL
	RETURN
	PRINT
	IF
	THEN
	OTHERWISE
	REPEAT
	WHILE
	FOREVER
	BREAK
	OUT
	LOOP
	TIMES
	FOR
	EACH
	IN
	DO
	TAKES
	AND
	WITH
	THE
	OF
	CALLING
	VALUE
	ITEM
	AT
	POSITION
	LENGTH
	REMAINDER
	DIVIDED
	BY
	TRUE
	FALSE
	TOGGLE
	LOCATION
	WRITE
	AS
	STRUCTURE
	STRUCT
	FIELDS
	FIELD
	INSTANCE
	NEW
	TRY
	DOING
	ON
	ONERROR
	FINALLY
	RAISE
	REFERENCE
	COPY
	SWAP
	CASTED
	TYPE
	WHICH
	IS
	FROM
	UNSIGNED
	INTEGER
	DEFAULT
	BUT
	IMPORT
	EVERYTHING
	ALL
	SAFELY

	// New keywords
	CONTINUE
	SKIP
	NOTHING
	NOT
	OR
	ASK
	ARRAY
	LOOKUP
	TABLE
	HAS
	ENTRY
	RANGE

	// PLEASE is emitted for politeness prefixes: "please", "kindly",
	// "could you", and "would you kindly". When --minimum-politeness is
	// active the parser counts PLEASE-prefixed statements toward the
	// politeness quota.
	PLEASE

	// SLEEP is emitted for the "sleep" and "wait" keywords used in
	// "Sleep for <duration>." / "Wait for <duration>." statements.
	SLEEP

	// WHITESPACE is emitted by TokenizeForHighlight to represent horizontal
	// whitespace (spaces / tabs) that was skipped by the lexer between tokens.
	// It is never produced by NextToken or TokenizeAll; it exists solely for
	// reconstructing the original source text during syntax highlighting.
	WHITESPACE

	// Operators and Punctuation
	PERIOD
	COMMA
	COLON
	LPAREN
	RPAREN
	LBRACKET
	RBRACKET
	PLUS
	MINUS
	STAR
	SLASH
	ASSIGN
	DOTDOT // ".." range operator

	// Comparison operators (multi-word)
	IS_EQUAL_TO
	IS_LESS_THAN
	IS_GREATER_THAN
	IS_LESS_EQUAL
	IS_GREATER_EQUAL
	IS_NOT_EQUAL
	IS_SOMETHING  // "is something" / "has a value" — not-nil check
	IS_NOTHING_OP // "is nothing" / "has no value" — nil check
	IS_TRUE       // "is true"  — boolean true check
	IS_FALSE      // "is false" — boolean false check
	ISNT_TRUE     // "isn't true"  — boolean not-true check
	ISNT_FALSE    // "isn't false" — boolean not-false check
	POSSESSIVE    // standalone 's — postfix possessive operator (e.g. "hello"'s title)
	COMMENT       // # … — source comment; Value holds the text after '#' (trimmed)
)

func (Type) String

func (t Type) String() string

String representation of token type

Jump to

Keyboard shortcuts

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