lispy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalSource

func EvalSource(source string) ([]string, error)

method which exposes eval to other packages which call this as an API to get a result

func EvalSourceIO

func EvalSourceIO(source string, env *Env) error

used to load library packages into the env

Types

type Env

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

func InitState

func InitState() *Env

func (*Env) Eval

func (env *Env) Eval(nodes []Sexp) []string

evaluates and interprets our AST

func (Env) String

func (env Env) String() string

allow functionvalue to implement value

type FunctionThunkValue

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

func (FunctionThunkValue) Eval

func (thunk FunctionThunkValue) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

not ideal

func (FunctionThunkValue) String

func (thunk FunctionThunkValue) String() string

type FunctionValue

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

Value referencing any functions

func (FunctionValue) Eval

func (funcVal FunctionValue) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

create new function binding

func (FunctionValue) String

func (f FunctionValue) String() string

type Lexer

type Lexer struct {
	Input        string
	Position     int
	ReadPosition int
	Char         byte
}

********* Lexer ***********

func New

func New(input string) *Lexer

type LispyUserFunction

type LispyUserFunction func(env *Env, name string, args []Sexp) Sexp

type Sexp

type Sexp interface {
	String() string
	Eval(*Env, *StackFrame, bool) Sexp
}

Generic interface for an Sexp (any node in our AST must implement this interface)

func Parse

func Parse(tokens []Token) ([]Sexp, error)

********* PARSING CODE ***************

type SexpArray

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

func (SexpArray) Eval

func (arr SexpArray) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpArray) String

func (s SexpArray) String() string

type SexpFloat

type SexpFloat float64

SexpFloat

func (SexpFloat) Eval

func (s SexpFloat) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpFloat) String

func (n SexpFloat) String() string

type SexpFunctionCall

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

func (SexpFunctionCall) Eval

func (s SexpFunctionCall) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpFunctionCall) String

func (f SexpFunctionCall) String() string

type SexpFunctionLiteral

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

SexpFunction Literal to store the functions when parsing them

func (SexpFunctionLiteral) Eval

func (s SexpFunctionLiteral) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpFunctionLiteral) String

func (f SexpFunctionLiteral) String() string

type SexpInt

type SexpInt int

SexpInt

func (SexpInt) Eval

func (s SexpInt) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpInt) String

func (n SexpInt) String() string

type SexpPair

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

SexpPair is an implementation of a cons cell with a head (car) and tail (cdr) Lists in lispy are defined as linked lists of cons cells

func (SexpPair) Eval

func (n SexpPair) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpPair) String

func (l SexpPair) String() string

type SexpSymbol

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

Symbol have dedicated types for strings and bools or this suffices?

func (SexpSymbol) Eval

func (s SexpSymbol) Eval(env *Env, frame *StackFrame, allowThunk bool) Sexp

func (SexpSymbol) String

func (s SexpSymbol) String() string

type StackFrame

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

struct to store function arguments for now

type Token

type Token struct {
	Token   TokenType
	Literal string
}

func Read

func Read(reader io.Reader) []Token

Takes as input the source code as a string and returns a list of tokens

type TokenType

type TokenType string

Token type definitions

const ARRAY TokenType = "ARRAY"
const COMMENT TokenType = "COMMENT"
const DEFINE TokenType = "DEFINE"
const DO TokenType = "DO"
const EOF TokenType = "EOF"

not used const ATOM TokenType = "ATOM" const EXP TokenType = "EXP" const ENV TokenType = "ENV"

const FALSE TokenType = "FALSE"
const FLOAT TokenType = "FLOAT"
const ID TokenType = "ID"
const IF TokenType = "IF"
const INTEGER TokenType = "INTEGER"
const LPAREN TokenType = "LPAREN"
const LSQUARE TokenType = "LSQUARE"
const MACRO TokenType = "MACRO"
const QUOTE TokenType = "QUOTE"
const RPAREN TokenType = "RPAREN"
const RSQUARE TokenType = "RSQUARE"
const STRING TokenType = "STRING"

Symbols

const SYMBOL TokenType = "SYMBOL"
const TRUE TokenType = "TRUE"
const UNQUOTE TokenType = "UNQUOTE"

type Value

type Value interface {
	String() string
}

Value is a reference to any Value in a Lispy program

Jump to

Keyboard shortcuts

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