golisp

package module
v0.0.0-...-2f2c0bc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Unlicense Imports: 8 Imported by: 0

README

golisp

A toy embeddable LISP evaluation engine written in Go

Description

The purpose of this little project is to serve as a test-bed for my learning the Go Programming Language.

As such, it is likely to be rife with areas of improvement, and feedback will be gratefully received.

It isn't going to be particularly efficient, rigorous or complete, or perhaps even interesting. But it seemed like a fun way to get a handle on the capabilities and idiosyncracies of Go.

Documentation

Index

Constants

View Source
const (
	TOK_BEGIN enumTokenType = iota
	TOK_LPAREN
	TOK_RPAREN
	TOK_COMMENT
	TOK_QUOTEDSTRING
	TOK_SYMBOL
	TOK_END
	// put new tokens between BEGIN and END, and ensure you implement `String()` correctly!
	TOK_UNKNOWN
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArithmeticLibrary

type ArithmeticLibrary struct {
}

func (*ArithmeticLibrary) InjectFunctions

func (l *ArithmeticLibrary) InjectFunctions(functions FunctionTable) FunctionTable

type EnumVariantType

type EnumVariantType uint8
const (
	VAR_UNKNOWN EnumVariantType = iota
	VAR_NULL
	VAR_DATE
	VAR_BOOL
	VAR_FLOAT
	VAR_INT
	VAR_STRING
	VAR_IDENT
	VAR_ERROR
	VAR_FUNCTION
	VAR_MAX
)

func (EnumVariantType) String

func (t EnumVariantType) String() string

type EvaluationContext

type EvaluationContext struct {
	EvaluatedValue Variant
	Parent         *EvaluationContext
	FunctionTable  FunctionTable
	SymbolTable    SymbolTable
}

func NewEvaluationContext

func NewEvaluationContext(parent *EvaluationContext) *EvaluationContext

type FunctionLibrary

type FunctionLibrary interface {
	InjectFunctions(*FunctionTable) *FunctionTable
}

type FunctionTable

type FunctionTable map[string]FunctionType

type FunctionType

type FunctionType func([]Variant) Variant

type LogicalLibrary

type LogicalLibrary struct {
}

func (*LogicalLibrary) InjectFunctions

func (l *LogicalLibrary) InjectFunctions(functions FunctionTable) FunctionTable

type SExpr

type SExpr interface {
	Eval(*EvaluationContext) *EvaluationContext
	String() string
}

func Parse

func Parse(s string) (SExpr, error)

type StringLibrary

type StringLibrary struct {
}

func (*StringLibrary) InjectFunctions

func (l *StringLibrary) InjectFunctions(functions FunctionTable) FunctionTable

type SymbolTable

type SymbolTable map[string]Variant

type Variant

type Variant struct {
	VariantType  EnumVariantType
	VariantValue interface{}
}

func (*Variant) CoerceToBool

func (b *Variant) CoerceToBool() (bool, error)

func (*Variant) CoerceToFloat

func (b *Variant) CoerceToFloat() (float64, error)

func (*Variant) CoerceToInt

func (b *Variant) CoerceToInt() (int64, error)

func (*Variant) CoerceToString

func (b *Variant) CoerceToString() (string, error)

func (*Variant) GetDateValue

func (b *Variant) GetDateValue() (time.Time, error)

func (*Variant) GetErrorValue

func (b *Variant) GetErrorValue() (error, error)

func (*Variant) GetIdentifierValue

func (b *Variant) GetIdentifierValue() (string, error)

func (*Variant) GetTypeConsistentValue

func (b *Variant) GetTypeConsistentValue() (interface{}, error)

func (*Variant) MakeConsistent

func (b *Variant) MakeConsistent() Variant

func (*Variant) ToDebugString

func (b *Variant) ToDebugString() string

Jump to

Keyboard shortcuts

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