twik: launchpad.net/twik Index | Files | Directories

package twik

import "launchpad.net/twik"

Package twik implements a tiny embeddable language for Go.

For details, see the blog post:

http://blog.labix.org/2013/07/16/twik-a-tiny-language-for-go

Index

Package Files

ast.go globals.go scope.go

func NewFileSet

func NewFileSet() *ast.FileSet

NewFileSet returns a new FileSet to hold positioning information for a set of parsed twik sources.

func Parse

func Parse(fset *ast.FileSet, name string, code []byte) (ast.Node, error)

Parse parses a byte slice containing twik code and returns the resulting parsed tree.

Positioning information for the parsed code will be stored in fset under the given name.

func ParseString

func ParseString(fset *ast.FileSet, name string, code string) (ast.Node, error)

ParseString parses a string containing twik code and returns the resulting parsed tree.

Positioning information for the parsed code will be stored in fset under the given name.

type Error

type Error struct {
    Err     error
    PosInfo *ast.PosInfo
}

Error holds an error and the source position where the error was found.

func (*Error) Error

func (e *Error) Error() string

type Scope

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

Scope is an environment where twik logic may be evaluated in.

func NewScope

func NewScope(fset *ast.FileSet) *Scope

NewScope returns a new scope for evaluating logic that was parsed into fset.

func (*Scope) Branch

func (s *Scope) Branch() *Scope

Branch returns a new scope that has s as a parent.

func (*Scope) Create

func (s *Scope) Create(symbol string, value interface{}) error

Create defines a new symbol with the given value in the s scope. It is an error to redefine an existent symbol.

func (*Scope) Eval

func (s *Scope) Eval(node ast.Node) (value interface{}, err error)

Eval evaluates node in the s scope and returns the resulting value.

func (*Scope) Get

func (s *Scope) Get(symbol string) (value interface{}, err error)

Get returns the value of symbol in the shallowest scope it is defined in. It is an error to get the value of an undefined symbol.

func (*Scope) Set

func (s *Scope) Set(symbol string, value interface{}) error

Set sets symbol to the given value in the shallowest scope it is defined in. It is an error to set an undefined symbol.

Directories

PathSynopsis
ast
cmd/twik

Package twik imports 3 packages (graph) and is imported by 1 packages. Updated 2014-10-30. Refresh now. Tools for package owners.