Git Product home page Git Product logo

anko's Introduction

Hey πŸ‘‹, I'm mattn

Github

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.

Top Langs mattn's github stats

@mattn's Holopin board

anko's People

Contributors

aisk avatar alaingilbert avatar brutella avatar c4s4 avatar catplanet007 avatar chobie avatar chyroc avatar dhiltonp avatar dvrkps avatar geseq avatar ipsusila avatar john-floren-gravwell avatar kris-watts-gravwell avatar leonelquinteros avatar mattn avatar michaels11 avatar monkeywithacupcake avatar ondrajz avatar prisoner avatar tcolar avatar truefurby avatar xrash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anko's Issues

math/big error on arm

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.

Export functions to Anko

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?

How work with class in anko?

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...)

Go 1.6 and status

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.

Can not say me to use what to make this?!

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.

Slice branch

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.

Stop Anko execution

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?

Anko is not thread-safe to use from multiple goroutines

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.

Bugs in toInt, toFloat, toBool functions?

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).

Need global() function for global variable in function!

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.

Bug of Pow Operator!

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 ?!!!

Extend http example with Post

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)

Why tab is column and not space?!

hi
why tab is column and not space?

input :β€Œ

  1. println("hello1\t2\t3")
  2. 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.

Feature Request, Not Show Offset Chars at Error Line!

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. πŸ‘ πŸ‘


One-Test

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. πŸ‘Ž πŸ‘Ž


Two-Test

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.


Tree-Test

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?

Can't define floats with exponent signs

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)

1 line counts as 2

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.

Why not support utf-8 name for variables and functions?!

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?

anko/vm test fails

# 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

Question about of slice support

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)

Order/Priority of Array item is Different?!

What Problem ?

why every time then script run , Order/Priority of array item is Different?


Input :

list={"name":"anko","age":49,"child":{"name":"anko","age":40}}
print(list)


Output :

$ ./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]

Can't modify map value

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?

Why Hashmap index name can not int or another type?!

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.

Inconsistent Map Lookup

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))

Why can not include another file?!

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.

How can add index name for every array value?!

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.

Can't Unmarshal JSON to a map

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)

Can not parse big int

hi
Can not parse big int

example input :

print(5*99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999456456456456666666666666666666666666666666666666666666666666666666666666699999999999999999999999999999999999999)

error :

typein:1: strconv.ParseInt: parsing "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999456456456456666666666666666666666666666666666666666666666666666666666666699999999999999999999999999999999999999": value out of range

Any way to call a variadic method ?

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

why '>' GE '<' LE are %left?

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

Calling functions in map

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()

err == nil is always true

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.

multiline input

#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) >

Desgin fro error handling

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.

What ^ operator?

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?

Bug of Pointer Variable

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

Feature Request , Array and Map

i have tree Feature Requset:

One

var list=[1,2,3,4]
list[]=5 # now The variable output expected is [1,2,3,4,5]
print(list)

Two

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...

Tree

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 > >

Feature Request , Array Map (Please Read)

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............................................

multiline input?

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) >

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.