neugram / ng

scripting language integrated with Go
https://neugram.io
BSD 2-Clause "Simplified" License
917 stars 43 forks source link

ng: support keyed array literal #160

Closed sbinet closed 6 years ago

sbinet commented 6 years ago

the following fails in ng:

ng> arr := [2]int{1:1}
neugram: parser: panic: TODO parseStmt } (off 18)
goroutine 5 [running]:
runtime/debug.Stack(0x32, 0x0, 0x0)
    /home/binet/sdk/go1.10beta1/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
    /home/binet/sdk/go1.10beta1/src/runtime/debug/stack.go:16 +0x22
neugram.io/ng/parser.(*Parser).work.func1(0xc42013a070)
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:145 +0x116
panic(0xae8820, 0xc420114190)
    /home/binet/sdk/go1.10beta1/src/runtime/panic.go:502 +0x229
neugram.io/ng/parser.(*Parser).parseStmt(0xc42013a070, 0x0, 0x0)
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:1190 +0x1836
neugram.io/ng/parser.(*Parser).work(0xc42013a070)
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:188 +0x1f4
created by neugram.io/ng/parser.New
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:30 +0x114
neugram: parser: expected "}", found ":" (off 16)
neugram: parser: expected ";", found "integer" (off 17)
neugram: parser: panic: TODO parseStmt } (off 18)

ng> arr := [...]int{1:1}
neugram: parser: panic: TODO parseStmt } (off 20)
goroutine 18 [running]:
runtime/debug.Stack(0x32, 0x0, 0x0)
    /home/binet/sdk/go1.10beta1/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
    /home/binet/sdk/go1.10beta1/src/runtime/debug/stack.go:16 +0x22
neugram.io/ng/parser.(*Parser).work.func1(0xc42019c000)
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:145 +0x116
panic(0xae8820, 0xc42021e0c0)
    /home/binet/sdk/go1.10beta1/src/runtime/panic.go:502 +0x229
neugram.io/ng/parser.(*Parser).parseStmt(0xc42019c000, 0x0, 0x0)
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:1190 +0x1836
neugram.io/ng/parser.(*Parser).work(0xc42019c000)
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:188 +0x1f4
created by neugram.io/ng/parser.New
    /home/binet/work/gonum/src/neugram.io/ng/parser/parser.go:30 +0x114
neugram: parser: expected "}", found ":" (off 18)
neugram: parser: expected ";", found "integer" (off 19)
neugram: parser: panic: TODO parseStmt } (off 20)
..> 

this probably means we'd have to modify expr.ArrayLiteral to something along the lines of:

type ArrayLiteral struct {
        Position src.Pos
        Type     *tipe.Slice
        Keys     []Expr
        Values   []Expr
}