twik

package module
v1.0.0-...-095ec92 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2014 License: LGPL-3.0 Imports: 3 Imported by: 2

README

Installation and usage

See gopkg.in/twik.v1 for documentation and usage details.

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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