anko

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2019 License: MIT Imports: 11 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, photo by Ocdp)

Usage Example - Embedded

package main

import (
	"fmt"
	"log"

	"github.com/mattn/anko/vm"
)

func main() {
	env := vm.NewEnv()

	err := env.Define("println", fmt.Println)
	if err != nil {
		log.Fatalf("Define error: %v\n", err)
	}

	script := `
println("Hello World :)")
`

	_, err = env.Execute(script)
	if err != nil {
		log.Fatalf("Execute error: %v\n", err)
	}

	// output: Hello World :)
}

More examples are located in the GoDoc:

https://godoc.org/github.com/mattn/anko/vm

Usage Example - Command Line

Building
go get github.com/mattn/anko
go install github.com/mattn/anko
Running an Anko script file named script.ank
./anko script.ank

Anko Script Quick Start

// declare variables
x = 1
y = x + 1

// print using outside the script defined println function
println(x + y) // 3

// if else statement
if x < 1 || y < 1 {
	println(x)
} else if x < 1 && y < 1 {
	println(y)
} else {
	println(x + y)
}

// array
a = [1, 2, 3]
println(a) // [1 2 3]
println(a[0]) // 1

// map
a = {"x": 1}
println(a) // map[x:1]
a.b = 2
a["c"] = 3
println(a["b"]) // 2
println(a.c) // 3

// function
func a (x) {
	println(x + 1)
}
a(3) // 4

Please note that the master branch is not stable

The master branch language and API may change at any time.

To mitigate breaking changes, please use tagged branches. New tagged branches will be created for breaking changes.

Author

Yasuhiro Matsumoto (a.k.a mattn)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
ast
Package ast implements abstruct-syntax-tree for anko.
Package ast implements abstruct-syntax-tree for anko.
cmd
Package core implements core interface for anko script.
Package core implements core interface for anko script.
internal
misc
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