parens: github.com/spy16/parens Index | Files | Directories

package parens

import "github.com/spy16/parens"

Index

Package Files

exprs.go parens.go parser.go reflect.go scope.go

Variables

var (
    // ErrNameNotFound is returned when a lookup is performed with a
    // non-bound name.
    ErrNameNotFound = errors.New("name not bound to a value")

    // ErrNotCallable is returned when a Call is attempted on a non-
    // callable value.
    ErrNotCallable = errors.New("value is not callable")

    // ErrConversionImpossible is returned when the Value type cannot be
    // converted to the expected type.
    ErrConversionImpossible = errors.New("cannot be converted")

    // ErrInvalidNumberOfArgs is returned when a function call is attempted
    // with invalid number of arguments.
    ErrInvalidNumberOfArgs = errors.New("invalid number of arguments")
)

func Execute Uses

func Execute(rd io.RuneScanner, env Scope) (interface{}, error)

Execute reads until EOF or an error from the RuneScanner and executes the read s-expressions in the given scope.

func ExecuteExpr Uses

func ExecuteExpr(expr Expr, env Scope) (interface{}, error)

ExecuteExpr executes the expr in the given scope.

func ExecuteOne Uses

func ExecuteOne(rd io.RuneScanner, env Scope) (interface{}, error)

ExecuteOne reads runes enough to construct one s-exp and executes the s-exp with given scope.

func ExecuteStr Uses

func ExecuteStr(src string, env Scope) (interface{}, error)

ExecuteStr is a convenience wrapper for Execute.

type CommentExpr Uses

type CommentExpr string

CommentExpr is returned to represent a lisp-style comment.

func (CommentExpr) Eval Uses

func (ce CommentExpr) Eval(_ Scope) (interface{}, error)

Eval returns the comment string.

type Expr Uses

type Expr interface {
    Eval(env Scope) (interface{}, error)
}

Expr represents an expression.

func Parse Uses

func Parse(sc io.RuneScanner) (Expr, error)

Parse parses till the EOF and returns all s-exprs as a single ModuleExpr. This should be used to build an entire module from a file or string etc.

func ParseOne Uses

func ParseOne(sc io.RuneScanner) (Expr, error)

ParseOne consumes runes from the reader until a single s-expression is extracted. Returns any other errors from reader. This should be used when a continuous parse eval from a stream is necessary (e.g. TCP socket).

func ParseStr Uses

func ParseStr(src string) (Expr, error)

ParseStr is a convenience wrapper for Parse.

type KeywordExpr Uses

type KeywordExpr string

KeywordExpr represents a keyword literal.

func (KeywordExpr) Eval Uses

func (ke KeywordExpr) Eval(_ Scope) (interface{}, error)

Eval returns the keyword itself.

type ListExpr Uses

type ListExpr []Expr

ListExpr represents a list (i.e., a function call) expression.

func (ListExpr) Eval Uses

func (le ListExpr) Eval(scope Scope) (interface{}, error)

Eval evaluates each s-exp in the list and then evaluates the list itself as an s-exp.

type MacroFunc Uses

type MacroFunc func(scope Scope, exprs []Expr) (interface{}, error)

MacroFunc represents the signature of the Go macro functions. Functions bound in the scope as MacroFunc will receive un-evaluated list of s-exps and the current scope.

type ModuleExpr Uses

type ModuleExpr []Expr

ModuleExpr represents a list of Exprs.

func (ModuleExpr) Eval Uses

func (me ModuleExpr) Eval(scope Scope) (interface{}, error)

Eval executes each expression in the module and returns the last result.

type NumberExpr Uses

type NumberExpr struct {
    NumStr string
    Number interface{}
}

NumberExpr represents number s-expression.

func (NumberExpr) Eval Uses

func (ne NumberExpr) Eval(scope Scope) (interface{}, error)

Eval for a number returns itself.

type QuoteExpr Uses

type QuoteExpr struct {
    Expr Expr
}

QuoteExpr implements the quote-literal form.

func (QuoteExpr) Eval Uses

func (qe QuoteExpr) Eval(scope Scope) (interface{}, error)

Eval returns the expression itself without evaluating it.

func (QuoteExpr) UnquoteEval Uses

func (qe QuoteExpr) UnquoteEval(scope Scope) (interface{}, error)

UnquoteEval unquotes and evaluates the underlying expression.

type Scope Uses

type Scope interface {
    Get(name string) (interface{}, error)
    Bind(name string, v interface{}, doc ...string) error
    Root() Scope
}

Scope is responsible for managing bindings.

func NewScope Uses

func NewScope(parent Scope) Scope

NewScope initializes a new scope with given parent scope. parent can be nil.

type StringExpr Uses

type StringExpr string

StringExpr represents single and double quoted strings.

func (StringExpr) Eval Uses

func (se StringExpr) Eval(_ Scope) (interface{}, error)

Eval returns unquoted version of the STRING token.

type SymbolExpr Uses

type SymbolExpr string

SymbolExpr represents a symbol.

func (SymbolExpr) Eval Uses

func (se SymbolExpr) Eval(scope Scope) (interface{}, error)

Eval returns the symbol name itself.

type VectorExpr Uses

type VectorExpr []Expr

VectorExpr represents a vector form.

func (VectorExpr) Eval Uses

func (ve VectorExpr) Eval(scope Scope) (interface{}, error)

Eval creates a golang slice.

Directories

PathSynopsis
genPackage gen provides functions for Go code generation from lisp.
stdlib

Package parens imports 9 packages (graph) and is imported by 1 packages. Updated 2019-02-08. Refresh now. Tools for package owners.