picol

package module
v0.0.0-...-55ac481 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 6 Imported by: 1

README

picol.go

Original http://oldblog.antirez.com/post/picol.html

Sample use:

func CommandPuts(i *picol.Interp, argv []string, pd interface{}) (string, error) {
	if len(argv) != 2 {
		return "", fmt.Errorf("Wrong number of args for %s %s", argv[0], argv)
	}
	fmt.Println(argv[1])
	return "", nil
}
...
	interp := picol.InitInterp()
	// add core functions
	interp.RegisterCoreCommands()
	// add user function
	interp.RegisterCommand("puts", CommandPuts, nil)
	// eval
	result, err := interp.Eval(string(buf))
	if err != nil {
		fmt.Println("ERROR", err, result)
	} else {
		fmt.Println(result)
	}

Documentation

Index

Constants

View Source
const (
	PT_ESC = iota
	PT_STR
	PT_CMD
	PT_VAR
	PT_SEP
	PT_EOL
	PT_EOF
)

Variables

View Source
var (
	PICOL_RETURN   = errors.New("RETURN")
	PICOL_BREAK    = errors.New("BREAK")
	PICOL_CONTINUE = errors.New("CONTINUE")
)

Functions

func ArityErr

func ArityErr(i *Interp, name string, argv []string) error

func CommandCallProc

func CommandCallProc(i *Interp, argv []string, pd interface{}) (string, error)

func CommandError

func CommandError(i *Interp, argv []string, pd interface{}) (string, error)

func CommandIf

func CommandIf(i *Interp, argv []string, pd interface{}) (string, error)

func CommandMath

func CommandMath(i *Interp, argv []string, pd interface{}) (string, error)

func CommandProc

func CommandProc(i *Interp, argv []string, pd interface{}) (string, error)

func CommandRetCodes

func CommandRetCodes(i *Interp, argv []string, pd interface{}) (string, error)

func CommandReturn

func CommandReturn(i *Interp, argv []string, pd interface{}) (string, error)

func CommandSet

func CommandSet(i *Interp, argv []string, pd interface{}) (string, error)

func CommandUnset

func CommandUnset(i *Interp, argv []string, pd interface{}) (string, error)

func CommandWhile

func CommandWhile(i *Interp, argv []string, pd interface{}) (string, error)

Types

type CallFrame

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

type Cmd

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

type CmdFunc

type CmdFunc func(i *Interp, argv []string, privdata interface{}) (string, error)

type Interp

type Interp struct {
	CmdInsideQuote bool
	// contains filtered or unexported fields
}

func InitInterp

func InitInterp() *Interp

func (*Interp) Command

func (i *Interp) Command(name string) *Cmd

func (*Interp) Eval

func (i *Interp) Eval(t string) (string, error)

EVAL!

func (*Interp) RegisterCommand

func (i *Interp) RegisterCommand(name string, fn CmdFunc, privdata interface{}) error

func (*Interp) RegisterCoreCommands

func (i *Interp) RegisterCoreCommands()

func (*Interp) Scope

func (i *Interp) Scope() map[string]Var

func (*Interp) SetVar

func (i *Interp) SetVar(name, val string)

func (*Interp) UnsetVar

func (i *Interp) UnsetVar(name string)

func (*Interp) Var

func (i *Interp) Var(name string) (Var, bool)

type Parser

type Parser struct {
	CmdInsideQuote bool

	Type int
	// contains filtered or unexported fields
}

func InitParser

func InitParser(text string) *Parser

func (*Parser) GetToken

func (p *Parser) GetToken() string

type Var

type Var string

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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