token

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenValPlus    = "+"
	TokenValMinus   = "-"
	TokenValStar    = "*"
	TokenValSlash   = "/"
	TokenValPercent = "%"
	TokenValComma   = ","

	TokenValTrue  = "true"
	TokenValFalse = "false"
)

Common Tokens

Variables

View Source
var ErrInvalidToken = errors.New("invalid token")

ErrInvalidToken indicates a general invalid token (e.g., nil reference)

View Source
var ErrParsingInt = errors.New("error parsing input for integer")

ErrParsingInt indicates a general integer parsing error

Functions

func IsComma

func IsComma(t Typ) bool

IsComma returns true if the subject Typ is Comma

func IsLogicalOperator

func IsLogicalOperator(t Typ) bool

IsLogicalOperator returns true if the subject Typ falls in the Logical Operator range

Types

type Lookup

type Lookup map[string]*Token

Lookup represents a map of Strings to Token Reference

type Token

type Token struct {
	Typ Typ    // The type of this Token.
	Pos int    // The starting position, in bytes, of this Token in the input string.
	Val string // The value of this Token.
}

Token represents a token or text string returned from the scanner.

func (*Token) Clone

func (t *Token) Clone() *Token

Clone makes a perfect copy of the subject Token

func (*Token) Int64

func (t *Token) Int64() (int64, error)

Int64 attempts to return an int64 rendition of the token value

func (*Token) String

func (t *Token) String() string

type Tokens

type Tokens []*Token

Tokens represents a slice of Tokens

func (Tokens) Compress

func (t Tokens) Compress() Tokens

Compress returns a new Tokens slice with nil values removed

func (Tokens) String

func (t Tokens) String() string

func (Tokens) Values

func (t Tokens) Values() []string

Values returns a []string of the Vals in Tokens

type Typ

type Typ uint

Typ identifies the type of lex items.

const (
	Error              Typ = iota // error occurred; value is text of error
	EOF                           // end of the input was reached and there are no more tokens coming
	Char                          // printable ASCII character; grab bag for comma etc.
	Equals                        // equals ('=') introducing an assignment
	Bool                          // boolean constant
	Complex                       // complex constant (1+2i); imaginary is just a number
	Identifier                    // unquoted, non-keyword alphanumeric identifier not starting with '.'
	LeftParen                     // '('
	Number                        // simple number, including imaginary
	RightParen                    // ')'
	Space                         // run of spaces separating arguments
	String                        // quoted string (includes quotes)
	LessThan                      // <
	GreaterThan                   // >
	LessThanOrEqual               // <=
	GreaterThanOrEqual            // >=
	InequalityOperator            // !, NOT, depending upon the applied language specification
	NotEqualOperator              // !=
	Comma                         // ','
	//
	// TokenTypeLogicalOps is the value after where Logical Operators start
	TokenTypeLogicalOps    Typ = iota + 32 // this value boundary should not be used for an item.Typ
	LogicalAnd                             // AND, &&, etc., depending upon the applied language specification
	LogicalOr                              // OR, ||, etc.,  depending upon the applied language specification
	TokenTypeLogicalOpsEnd                 // this value boundary should not be used for an item.Typ
	//
	// TypeMathOps is the value after where Mathemathical Operators start
	TokenTypeMathOps Typ = iota + 48 // this value boundary is should not be used for an item.Typ
	Plus
	Minus
	Multiply
	Divide
	Modulo
	TokenTypeMathOpsEnd // this value boundary should not be used for an item.Typ
	//
	// CustomNonKeyword is the value after which custom implementations start custom item types
	CustomNonKeyword Typ = 1024 //
	// CustomNonKeyword is the value after where custom non-Keywords end
	CustomNonKeywordEnd Typ = 65535
	// CustomKeyword defines the value after where custom Keywords item types start
	// We pad to 65K, so that any custom expansions can use the Type value space as regular item or keywords
	CustomKeyword Typ = 65536 // used only to delimit Keywords
)

Types

func (Typ) IsAddOrSubtract

func (t Typ) IsAddOrSubtract() bool

IsAddOrSubtract returns true if the subject Typ is Plus or Minus

func (Typ) IsBoolean

func (t Typ) IsBoolean() bool

IsBoolean returns true if the subject Typ falls in the Boolean Operator range

func (Typ) IsBreakable

func (t Typ) IsBreakable() bool

IsBreakable returns true if the Typ is EOF or Error

func (Typ) IsEOF

func (t Typ) IsEOF() bool

IsEOF returns true if the Typ is EOF

func (Typ) IsErr

func (t Typ) IsErr() bool

IsErr returns true if the sbuject Typ is Error

func (Typ) IsGTorGTE

func (t Typ) IsGTorGTE() bool

IsGTorGTE returns true if the Typ is > or >=

func (Typ) IsGreaterOrLessThan

func (t Typ) IsGreaterOrLessThan() bool

IsGreaterOrLessThan returns true if the Typ is >, >=, <, or <=

func (Typ) IsLTorLTE

func (t Typ) IsLTorLTE() bool

IsLTorLTE returns true if the Typ is < or <=

func (Typ) IsMathOperator

func (t Typ) IsMathOperator() bool

IsMathOperator returns true if the subject Typ falls in the Math Operator range

func (Typ) IsOrEquals

func (t Typ) IsOrEquals() bool

IsOrEquals returns true if the Typ is <= or >=

func (Typ) IsSpaceChar

func (t Typ) IsSpaceChar() bool

IsSpaceChar returns true if the Typ is a Space, Tab, CR or LF

func (Typ) String

func (t Typ) String() string

type TypLookup

type TypLookup map[Typ]string

TypLookup represents a map of Typs to their human-readable descriptions

type TypeCheckFunc

type TypeCheckFunc func(Typ) bool

TypeCheckFunc represents a function that returns true or false based on the Typ

Jump to

Keyboard shortcuts

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