lexer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package lexer implements a lexical analyzer used by the Elk interpreter.

Lexer expects a slice of bytes containing Elk source code analyses it and returns a stream of tokens/tokens.

Tokens are returned on demand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Colorize

func Colorize(source string) string

Lex the given string and construct a new one colouring every token.

func ColorizeEmbellishedText

func ColorizeEmbellishedText(source string) string

Lex the given string and construct a new one colouring every token. Used for text with bits of Elk code in backticks like "foo `1 + 2` bar"

func Lex

func Lex(source string) []*token.Token

Lex the given string and return a slice containing all the tokens.

func LexValue

func LexValue(source string) *value.ArrayList

Lex the given string and return a slice containing all the tokens.

Types

type Colorizer

type Colorizer struct{}

Implements the Colorizer interface

func (Colorizer) Colorize

func (c Colorizer) Colorize(source string) (string, error)

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Holds the current state of the lexing process.

func New

func New(source string) *Lexer

Instantiates a new lexer for the given source code.

func NewWithMode

func NewWithMode(sourceName string, source string, m mode) *Lexer

Same as New but lets you specify the path to the source code file.

func NewWithName

func NewWithName(sourceName string, source string) *Lexer

Same as New but lets you specify the path to the source code file.

func (*Lexer) Class

func (*Lexer) Class() *value.Class

func (*Lexer) Copy

func (l *Lexer) Copy() value.Reference

func (*Lexer) DirectClass

func (*Lexer) DirectClass() *value.Class

func (*Lexer) Error

func (l *Lexer) Error() string

func (*Lexer) Inspect

func (l *Lexer) Inspect() string

func (*Lexer) InstanceVariables

func (l *Lexer) InstanceVariables() *value.InstanceVariables

func (*Lexer) Next

func (l *Lexer) Next() *token.Token

Returns the next token or an error if the input is malformed.

func (*Lexer) SingletonClass

func (l *Lexer) SingletonClass() *value.Class

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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