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

package parens

import "github.com/spy16/parens"

Index

Package Files

format.go parens.go repl.go scope.go

type Executor Uses

type Executor interface {
    Execute(src string) (interface{}, error)
}

Executor implementation is responsible for understanding and evaluating the input to generate a result.

type Interpreter Uses

type Interpreter struct {
    Scope         parser.Scope
    Parse         ParseFn
    DefaultSource string
}

Interpreter represents the LISP interpreter instance. You can provide your own implementations of ParseFn to extend the interpreter.

func New Uses

func New(scope parser.Scope) *Interpreter

New initializes new parens LISP interpreter with given env.

func (*Interpreter) Execute Uses

func (parens *Interpreter) Execute(src string) (interface{}, error)

Execute tokenizes, parses and executes the given LISP code.

func (*Interpreter) ExecuteExpr Uses

func (parens *Interpreter) ExecuteExpr(expr parser.Expr) (interface{}, error)

ExecuteExpr executes the given expr using the appropriate scope.

func (*Interpreter) ExecuteFile Uses

func (parens *Interpreter) ExecuteFile(file string) (interface{}, error)

ExecuteFile reads, tokenizes, parses and executes the contents of the given file.

type ParseFn Uses

type ParseFn func(name, src string) (parser.Expr, error)

ParseFn is responsible for tokenizing and building Expr out of tokens.

type REPL Uses

type REPL struct {
    Exec   Executor
    Banner string

    ReadIn   ReadInFunc
    WriteOut WriteOutFunc
}

REPL represents a session of read-eval-print-loop.

func NewREPL Uses

func NewREPL(exec Executor) (*REPL, error)

NewREPL initializes a REPL session with given evaluator.

func (*REPL) Start Uses

func (repl *REPL) Start(ctx context.Context) error

Start the REPL which reads from in and writes results to out.

type ReadInFunc Uses

type ReadInFunc func() (string, error)

ReadInFunc implementation is used by the REPL to read input.

type Scope Uses

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

Scope manages lifetime of values. Scope can inherit values from a parent as well.

func NewScope Uses

func NewScope(parent parser.Scope) *Scope

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

func (*Scope) Bind Uses

func (sc *Scope) Bind(name string, v interface{}, doc ...string) error

Bind will bind the value to the given name. If a value already exists for the given name, it will be overwritten.

func (*Scope) Doc Uses

func (sc *Scope) Doc(name string) string

Doc returns doc string for the name. If name is not found, returns empty string.

func (*Scope) Get Uses

func (sc *Scope) Get(name string) (interface{}, error)

Get returns the actual Go value bound to the given name.

func (*Scope) Root Uses

func (sc *Scope) Root() parser.Scope

Root traverses the entire hierarchy of scopes and returns the topmost one (i.e., the one with no parent).

func (*Scope) String Uses

func (sc *Scope) String() string

type WriteOutFunc Uses

type WriteOutFunc func(res interface{}, err error)

WriteOutFunc implementation is used by the REPL to write result.

Directories

PathSynopsis
genPackage gen provides functions for Go code generation from lisp.
lexer
lexer/utfstrings
parserPackage parser provides functions for turning token stream into an AST (Symbolic Expressions)
reflectionPackage reflection uses reflection to provide dynamic functionalities.
stdlib

Package parens imports 9 packages (graph) and is imported by 1 packages. Updated 2018-11-22. Refresh now. Tools for package owners.