anko

command module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2018 License: MIT Imports: 13 Imported by: 0

README

anko

GoDoc Reference Build Status Coverage Go Report Card

Anko is a scriptable interpreter written in Go.

(Picture licensed under CC BY-SA 3.0 by wikipedia)

Installation

Requires Go.

$ go get -u github.com/mattn/anko

Examples

# declare function
func plus(n){
  return n + 1
}

# declare variables
x = 1
y = x + 1

# print values 
println(x * (y + 2 * x + plus(x) / 2))

# if/else condition
if plus(y) > 1 {
  println("こんにちわ世界")
} else {
  println("Hello, World")
}

# array type
a = [1,2,3]
println(a[2])
println(len(a))

# map type
m = {"foo": "bar", "far": "boo"}
m.foo = "baz"
for k in keys(m) {
  println(m[k])
}

See _examples/scripts for more examples.

Usage

Embedding the interpreter into your own program:

var env = vm.NewEnv()

env.Define("foo", 1)
env.Define("bar", func() int {
	return 2
})

val, err := env.Execute(`foo + bar()`)
if err != nil {
	panic(err)
}

fmt.Println(val) 
// output:
// 3

To import all core language builtins, allowing the example scripts to work:

import "github.com/mattn/anko/core"

var env = vm.NewEnv()
core.Import(env)

_, err := env.Execute(`println("test")`)
if err != nil {
	panic(err)
}
// output:
// "test"

Running scripts using anko command-line tool:

$ anko script.ank

Author

Yasuhiro Matsumoto (a.k.a mattn)

Note

Please note that the language and API may change at any time so be very weary of using in production

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
_example
ast
Package ast implements abstruct-syntax-tree for anko.
Package ast implements abstruct-syntax-tree for anko.
Package core implements core interface for anko script.
Package core implements core interface for anko script.
Package parser implements parser for anko.
Package parser implements parser for anko.
Package vm implements virtual-machine for anko.
Package vm implements virtual-machine for anko.

Jump to

Keyboard shortcuts

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