I β€ Open Source. I love Vim and Go.
- Long-time Golang user&contributor
- Google Dev Expert for Go
- Author of many Go tools
- Vim plugin author (emmet-vim, vim-gist, vim-lsp-settings, etc)
- Windows hacker
I'm looking for GitHub sponsors.
Scriptable interpreter written in golang
Home Page: http://play-anko.appspot.com/
License: MIT License
I β€ Open Source. I love Vim and Go.
I'm looking for GitHub sponsors.
When attempting to build on arm, I get this:
src/github.com/mattn/anko/builtins/math/big/big.go:19: constant 4294967295 overflows int
and the build fails.
Hi,
Im trying exporting my function to Anko, but im getting "reflect: cannot use []interface {} as type string in Call". My code:
env.Define("gociExec", func(command string, params ...string) {
cmd := exec.Command(command, params...)
out, err := cmd.Output()if err != nil { job.AppendOutputContentLine(JOB_OUTPUT_GROUP_CONSOLE_NAME, err.Error()) } else { outList := strings.Split(string(out), "\n") for _, outListItem := range outList { job.AppendOutputContentLine(JOB_OUTPUT_GROUP_CONSOLE_NAME, outListItem) } }
})
I want export a function that have two params: string and array of strings (...string).
Can you help me?
Hi
How to force an error inside script?
Thx.
Hi ,
How work with (public,private,protected) variable,function in class at anko?
module Plugin{
private owner="anko"
public var ver=1.5
private func own(){
println("is ok")
}
public func version() {
println(this.ver)
println(this.owner)
}
}
Plugin.version()
Print (Plugin.ver)
####################
Plugin.ver=99 #this change value of variable
Print (Plugin.ver)
####################
Plugin.owner="none" #this say error(example: is not public...)
####################
Plugin.own() #this say error(function is not public...)
Hi,
I dont find any contact here, so i decide write here.
How long this project is supported?
It has an active development?
Everything is working fine with Go 1.6?
I want put it on my open-source project like Jenkins, but made with Go. I need a script language user make their script to deploy.
hi
Very ashamed
example : list={"name":"attn",1,5,6,7,8}
i not want then you do this.
i want (me) do this. but need a help.
can not say me to use what to make this?
mean how can store value in go?
tank you. good bye.
I see there is a slice support branch, but it was never merged into master, are you still working on it ? Is it on hold ?
Thanks.
..
I'm looking for a way to stop or limit the time Anko can execute. I looked through the source but I could not find a way to do this.
Would it be possible to implement the ability to cancel Anko execution?
I'm using Anko for a thread-safe project and i found that the VM isn't safe for multiple goroutines.
I've forked and quickly fix the issue i have, but i found there is a lack of support for this on the package and no data race tests are present to detect these issues.
But by running go test -race ./...
from the root directory, you can find 1 data race found "by accident" on a test.
I have created a function in go that returns a uint32. I then call toInt on that value in anko, which converts it to 0. I think there's a bug in how this is currently defined:
env.Define("toInt", func(v interface{}) int64 {
nt := reflect.TypeOf(1)
rv := reflect.ValueOf(v)
if rv.Type().ConvertibleTo(nt) {
return 0
}
return rv.Convert(nt).Int()
})
For this to work, I think the return statements will need to switch positions (see in playground, with added ability to handle converting strings).
BTW, toFloat
and toBool
also have this bug. I'll submit a PR to fix all 3 (and add the capability to convert from string).
var qq = import("github.com/PuerkitoBio/goquery")
got an error:
package 'github.com/puerkitobio/goquery' not found
It seems that the README of this project includes Ocdp's picture licensed under CC BY-SA 3.0.
You should add a credit about it to the README.
Hi
test input :
age=2
func test(){
age=age*2
print(age)
}
test()
now in function , can access to all of out. but this is bad.
need a global() function to can get access variable out of func.
please add global() function to interpreter.
tank you.
Hi
Please Check this.
example/test.ank
(input file) : print(5**5)
vm/vm.go
file:
case "**":
if lhsV.Kind() == reflect.Float64 {
return reflect.ValueOf(math.Pow(toFloat64(lhsV), toFloat64(rhsV))), nil
}
print(toFloat64(lhsV))//added by me to test
print(" ** ")//added by me to test
print(toFloat64(rhsV))//added by me to test
print("\n")//added by me to test
print(math.Pow(toFloat64(lhsV),toFloat64(rhsV)))//added by me to test
print("\n")//added by me to test
return reflect.ValueOf(int64(math.Pow(toFloat64(lhsV), toFloat64(rhsV)))), nil
=========
output :
$ ./anko example/test.ank
+5.000000e+000 ** +5.000000e+000
+3.125000e+003
3125
why output of pow is 3125
?!!!
So I want to try making Post request with http:-
var http, ioutil = import("net/http"), import("io/ioutil")
var url = import("net/url")
r = http.DefaultClient.PostForm("http://httpbin.org/post", {"name": "kamal"})
This didn't work either:-
data = url.Values({"name": "kamal"})
r = http.DefaultClient.PostForm("http://httpbin.org/post", data)
..
hi
why tab is column and not space?
input :β
println("hello1\t2\t3")
println("1\t2\t3")
i think is better then you change \t
to example \tc
(as column) and make \t
as a tab space.
tank you.
Hi
Feature Request, Not Show Offset Chars at Error Line(yycolumn)!
Example error text :
example/test.ank:11: syntax error:
example/test.ank:11:** syntax error:
so 11:**
, here ** why empty?
error of (lexer and parser) both just show line and not show offset current error line!
carefull link for example , have startColumn
and column
:
i also work on this , file anko.go
:
fmt.Fprintf(os.Stderr, "%s:%d: %s\n", source, e.Pos.Line, err)
changed to :
fmt.Fprintf(os.Stderr, "%s:%d:%d %s\n", source, e.Pos.Line,e.Pos.Column, err)
so now also show offset/column of error. π π
now again compile go build anko.go
and next test with a input :
print(5***2)
print("\n")
file : http://ilestra.com/input-1.txt
now error is : example/test.ank:1:12 syntax error: unexpected ')'
say in offset 12 have error but in offset 12 code end.
and error of me available in offset 10. π π
also now with another test input :
print(456456);print(456***);print(5**2)
print("\n")
file : http://ilestra.com/input-2.txt
also now error say : example/test.ank:1:27 syntax error: unexpected ')'
but offset/column of my error available in 25 or 26.
also again test with input :
print(456456);print( @#$%^&*(((((( ));print(5**2)
print "\n"
file : http://ilestra.com/input-3.txt
error now: example/test.ank:1:29 syntax error: unexpected $end
Output of column/offset is expected to be 28 or 29
Github delete space of my test's code. so i also upload file.
I think Lexer need some changes.
may problem is $$.SetPosition($1.Position())
in some yacc rule?
can you check/fix this?
When defining a float, the exponent sign cannot be used. For example:
#!anko
# ok
f = 1.325e12
println(typeOf(f))
println(f)
# fail
f = 1.325e+12
println(typeOf(f))
println(f)
# fail
f = 1.325e-12
println(typeOf(f))
println(f)
Sample script with a syntax error:
#!anko
func fib(n) {
a, b = 1, 1
f = []
for i in range n {
f += a
b += a
a = b - a
}
return f
}
println(fib(20))
You get this output:
$ ./anko fib-for.ank
fib-for.ank:11: syntax error: unexpected IDENT
The reported line is incorrect, the error is on line 6. The correct line can be found by doing (l.pos.Line-1)/2+1... but that just masks the underlying problem - somewhere a new line is double counted.
Hi
How can support utf-8 name for variables and functions?!
///////////////////////////////////////////////////////////////////////////////////////////
Example :
var ΡΠ°Π»Π»Π°ΠΌ="Hello"
(utf-8 name)
var Ψ³ΩΩ
="Hello"
(utf-8 name)
var atext-with="Hello"
(name with -
char)
func Ψ³ΩΩ
(){return 5;}
(utf-8 name)
///////////////////////////////////////////////////////////////////////////////////////////
isLetter()
and scanIdentifier()
lexer.go file need some changes.
can use from https://golang.org/pkg/unicode/ (unicode.IsLetter function)
how can fix?
# github.com/mattn/anko/vm ./env_test.go:12: invalid operation: ! error ./env_test.go:27: env.New undefined (type *Env has no field or method New) ./env_test.go:29: invalid operation: ! error ./env_test.go:45: env.New undefined (type *Env has no field or method New) ./env_test.go:48: invalid operation: ! error ./env_test.go:59: invalid operation: ! error FAIL github.com/mattn/anko/vm [build failed]
go version go1.3.3 linux/amd64 Debian 3.16.7-ckt4-3 (2015-02-03) x86_64 GNU/Linux
Great & Cool project. In anko, I can't see slice support , b.e. data[start : end]
Then , I implemented in the file github.com/mattn/anko/builtins/strings/strings.go
m.Define("Substring", reflect.ValueOf(func(args ...interface{}) string {
if len(args) < 2 {
panic("Missing arguments")
}
if len(args) > 3 {
panic("Too many arguments")
}
src := args[0].(string)
start := args[1].(int64)
end := len(src)
if len(args) > 2 {
end = int(args[2].(int64))
}
return string(src[start:end])
}))
You have considered include support for slices (this would change the syntax)
why every time then script run , Order/Priority of array item is Different?
list={"name":"anko","age":49,"child":{"name":"anko","age":40}}
print(list)
$ ./anko input.txt
map[name:anko age:49 child:map[name:arshia age:anko]]
$ ./anko input.txt
map[age:49 child:map[name:anko age:40] name:anko]
I want to use Sourcegraph code search and code review with anko. A project maintainer needs to enable it to set up a webhook so the code is up-to-date there.
Could you please enable anko on @sourcegraph by going to https://sourcegraph.com/github.com/mattn/anko and clicking on Settings? (It should only take 15 seconds.)
Thank you!
Hi, I'm playing anko script to studying go. I realized it couldn't modify map value.
http://play-anko.appspot.com/p/a55dd5e7ebc8ac0f109de84a0d61fbeae6d63a0a
I'm poor about reflection things,I googled it and found this thread https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/4_pabWnsMp0 :
map value is not addressable so it can't modify value directly.
I've tried to fix this issue but I'm not sure this patch is good.
diff --git a/vm/vm.go b/vm/vm.go
index f238ed5..6df93bf 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -511,6 +511,7 @@ func invokeLetExpr(expr ast.Expr, rv reflect.Value, env *Env) (reflect.Value, er
return rv, nil
case *ast.MemberExpr:
v, err := invokeExpr(lhs.Expr, env)
+ orig := v
if err != nil {
return v, NewError(expr, err)
}
@@ -533,12 +534,17 @@ func invokeLetExpr(expr ast.Expr, rv reflect.Value, env *Env) (reflect.Value, er
v = v.FieldByName(lhs.Name)
} else if v.Kind() == reflect.Map {
v = v.MapIndex(reflect.ValueOf(lhs.Name))
+ y := v.Interface()
+ v = reflect.ValueOf(&y).Elem()
}
if !v.CanSet() {
return NilValue, NewStringError(expr, "Cannot assignable")
}
v.Set(rv)
+ if orig.Kind() == reflect.Map {
+ orig.SetMapIndex(reflect.ValueOf(lhs.Name), v)
+ }
return v, nil
case *ast.ItemExpr:
v, err := invokeExpr(lhs.Value, env)
can you check this issue when you have a chance?
after go get ....
and 295fa83
input :
var a = 1
p = &a
println(1***p)
also again another error : input.txt:2:3 syntax error: unexpected '='
fix this.
hi
Why Hashmap index name can not int or another type?!
need change parser.go.y
file :
expr_pair : STRING ':' expr { $$ = &ast.PairExpr{Key: $1.Lit, Value: $3} }
use
expr
for index name.
also vm.go
and expr.go
file need some changes!
please also check this.
tank you.
The following gives Invalid Operation
, as it should:
var j = 3
println(j["v"])
The following, however prints 3
. It should give the same Invalid Operation
as above.
func test(h) {
return h["v"]
}
var j = 3
println(test(j))
hi
need to can include another file in current file.... with
include()
==>show error
in file
require()
==>not show error
in file
example : include("config.ank")
tankx.
hi.
yes?
hi
How can add index name for every array value?!
(mean map
type)
example : [ 0:"start","name":"mattn","age":39,"child":[1,2,3,4,5,9:1] ]
also need to in interpreter code return a array.
tank you.
please add this to source.
Hi,
Need ability to load a new librarys just by adding a file in near of the project(like php/python extensions) without rebuild anko.
example in near of output anko file have a extensions
folder, then auto load all library of them
Please add this.
I think this a good ability.
https://tip.golang.org/pkg/plugin/ in go 1.8
Thanks a lot. π
Run in anko playground.
json = import("encoding/json")
jsonTrans = `{"name": "ph_settings", "type": "anko_cmd"}`
println(jsonTrans)
out = {}
err = json.Unmarshal(toByteSlice(jsonTrans), &out)
if err != nil {
println("unmarshal: ", err)
}
println("result: ", out)
hi
Can not parse big int
example input :
print(5*99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999456456456456666666666666666666666666666666666666666666666666666666666666699999999999999999999999999999999999999)
error :
typein:1: strconv.ParseInt: parsing "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999456456456456666666666666666666666666666666666666666666666666666666666666699999999999999999999999999999999999999": value out of range
The code at http://play-anko.appspot.com/p/dd93df95984fb46f739f322e3a476b5cf2c4fd8a is causing an invalid operation exception in a strange place.
I'd think that the resp.items would be evaluated rather than just the resp which is what appears to be happening in the above code. -- This is just a simple mockup, in my real usecase I'm exposing an http API endpoint which returns something like resp, which is how I surfaced the bug.
For example the exec.Command() method is variadic (takes list of string), is there a way to call such a method, it seems '...' expression would be needed, or maybe you have an alternative ?
http://play-anko.appspot.com/p/4140ef199db61653c1265dd82160929251cef9f2
I could add that feature but wanted to check if I'm missing something first.
Related question:
a = ["a", "b", "c"]
yelds a []interface{}
should core have methods such as toStringSlice() to make it easy to convert that into []string ?
Thanks
I have a question about parser about '>' GE '<' LE.
Not it looks like this
%nonassoc EQEQ NEQ ','
%left '>' GE '<' LE SHIFTLEFT SHIFTRIGHT
if( 3 > 2 > 1){
println("true")
}else{
println("false")
}
This code prints "false".
IMO this should be
%nonassoc EQEQ NEQ ',' '>' GE '<' LE
%left SHIFTLEFT SHIFTRIGHT
Setting function to a map:
obj = {
"foo": func() {
println("foo")
}
}
and then calling it directly:
obj.foo()
throws Unknown function
error.
However saving it to a variable and calling the variable works:
foo = obj.foo
foo()
Script:
f, err = io.ioutil.ReadFile("file") println(err == nil) println(err != nil)
Output if file exist:
true false
Output if file does not exist:
true false
Working with err as a string
err != ""does work though.
#16 was closed prematurely; the commit there does nothing to address the issue raised.
I'd like to define a function at the repl, is multiline input available? For example, when I try to type in a function, I get an error (1) and a hang (2).
$ anko
> f=func(x) {
typein:1: syntax error: unexpected $end, expecting ',' <error (1)>
> return x+1 }
<hang (2) >
hi
how can hidden interface[*]{} text from output?
> age=39
39
> var age=39
[]interface {}{39}
var age=39
why have output?
b, err = ioutil.ReadFile("file")
This doesn't throw error
b, _ = ioutil.ReadFile("file")
Also not
b = ioutil.ReadFile("file")
In this case, anko should throw an error.
ioutil.ReadFile("file")
Also throw.
Hi
What is ^
operator? and what do?
print(^5)
==> -6
print(^-5)
==> +4
in source : reflect.ValueOf(^toInt64(v))
after search in google undrestand then this operator is Bitwise XOR
so what do ^
opeator in go?
you send me a sample code in : #55
input :
var a = 1
p = &a
println(1***p)
but this say error :
anko$ ./anko input.txt
panic: reflect.Value.Addr of unaddressable value
goroutine 1 [running]:
panic(0x78ab80, 0xc820075070)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
reflect.Value.Addr(0x76b840, 0xc820075010, 0x16, 0x0, 0x0, 0x0)
/usr/lib/go-1.6/src/reflect/value.go:240 +0x8c
github.com/mattn/anko/vm.invokeExpr(0x7f6ad5c3ad20, 0xc8200de780, 0xc820096410, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/compiler/go/src/github.com/mattn/anko/vm/vm.go:844 +0xc8af
github.com/mattn/anko/vm.invokeExpr(0x7f6ad5c3ad58, 0xc820070340, 0xc820096410, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/compiler/go/src/github.com/mattn/anko/vm/vm.go:1199 +0xd30
github.com/mattn/anko/vm.invokeExpr(0x7f6ad5c3ad90, 0xc820096500, 0xc820096410, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/compiler/go/src/github.com/mattn/anko/vm/vm.go:1315 +0x770d
github.com/mattn/anko/vm.RunSingleStmt(0x7f6ad5c3adc8, 0xc8200de7a0, 0xc820096410, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/compiler/go/src/github.com/mattn/anko/vm/vm.go:130 +0x58f3
github.com/mattn/anko/vm.Run(0xc820070380, 0x3, 0x4, 0xc820096410, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/compiler/go/src/github.com/mattn/anko/vm/vm.go:95 +0x214
main.main()
/home/compiler/go/src/github.com/mattn/anko/anko.go:144 +0xaa8
i have tree Feature Requset:
var list=[1,2,3,4]
list[]=5
# now The variable output expected is [1,2,3,4,5]
print(list)
var list={5:45456}
can not set index name as int or get value from function or .....
in go also can get index name from other types, but anko no...
i think need a new data type. i also help to make this.
Derived from the array and Maps
example with operator <>
some example :
var list= < 1,2,3,4,5 >
var list= < 1,2,3,4,5 , < 56789 > , 9 >
var list= < 1,2,3,4,5 , < 56789,"dfgdfg" >,9,"dfgdfdfg>
var list= < "name" : "anko" , "age" : 50 , "child" : < 1 , 2 , 3 , "4" , 5 > >
HI
why not add feature request? and just lock issues?
link : #56
example One :
var list=[1,2,3,4]
list[]=5
# now The variable output expected is [1,2,3,4,5]
list[]=8
# now The variable output expected is [1,2,3,4,5,8]
list[]=9
# now The variable output expected is [1,2,3,4,5,8,9]
list[]="hello"
# now The variable output expected is [1,2,3,4,5,8,9,"hello"]
print(list)
i want can after make variable , add some value to array.
but you say anko have range(1,5)
:|
i not have big request. just small changes.
please read my request on page.
please............................................
I'd like to define a function at the repl, is multiline input available? For example, when I try to type in a function, I get an error (1) and a hang (2).
$ anko
> f=func(x) {
typein:1: syntax error: unexpected $end, expecting ',' <error (1)>
> return x+1 }
<hang (2) >
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.