Skip to content

Commit

Permalink
Merge pull request #302 from MichaelS11/types
Browse files Browse the repository at this point in the history
0.0.9 Making types now more dynamic
  • Loading branch information
mattn authored Feb 12, 2019
2 parents 60896df + 6078401 commit c573355
Show file tree
Hide file tree
Showing 14 changed files with 1,051 additions and 861 deletions.
2 changes: 1 addition & 1 deletion anko.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/mattn/anko/vm"
)

const version = "0.0.8"
const version = "0.0.9"

var (
flagExecute string
Expand Down
34 changes: 34 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ast

// Token is used in the lexer to split characters into a string called a token
type Token struct {
PosImpl
Tok int
Lit string
}

// TypeKind blah
type TypeKind int

const (
// TypeDefault default type
TypeDefault TypeKind = iota
// TypePtr ptr type
TypePtr
// TypeSlice slice type
TypeSlice
// TypeMap map type
TypeMap
// TypeChan chan type
TypeChan
)

// TypeStruct blah
type TypeStruct struct {
Kind TypeKind
Env []string
Name string
Dimensions int
SubType *TypeStruct
Key *TypeStruct
}
3 changes: 0 additions & 3 deletions ast/astutil/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func walkExpr(expr ast.Expr, f WalkFunc) error {
return err
}
return walkExprs(expr.RHSS, f)
case *ast.NewExpr:
case *ast.AnonCallExpr:
if err := walkExpr(expr.Expr, f); err != nil {
return err
Expand All @@ -218,8 +217,6 @@ func walkExpr(expr ast.Expr, f WalkFunc) error {
return err
}
return walkExpr(expr.RHS, f)
case *ast.MakeChanExpr:
return walkExpr(expr.SizeExpr, f)
case *ast.MakeExpr:
if err := walkExpr(expr.LenExpr, f); err != nil {
return err
Expand Down
25 changes: 3 additions & 22 deletions ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,12 @@ type ChanExpr struct {
RHS Expr
}

// NewExpr provide expression to make new instance.
type NewExpr struct {
ExprImpl
Type string
}

// MakeChanExpr provide expression to make chan instance.
type MakeChanExpr struct {
ExprImpl
Type string
SizeExpr Expr
}

// ArrayCount is used in MakeExpr to provide Dimensions
type ArrayCount struct {
Count int
}

// MakeExpr provide expression to make instance.
type MakeExpr struct {
ExprImpl
Dimensions int
Type string
LenExpr Expr
CapExpr Expr
TypeData *TypeStruct
LenExpr Expr
CapExpr Expr
}

// MakeTypeExpr provide expression to make type.
Expand Down
8 changes: 0 additions & 8 deletions ast/token.go

This file was deleted.

2 changes: 1 addition & 1 deletion packages/encoding.json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestJson(t *testing.T) {
os.Setenv("ANKO_DEBUG", "1")
tests := []testlib.Test{
{Script: `json = import("encoding/json"); a = make(mapStringInterface); a["b"] = "b"; c, err = json.Marshal(a); err`, Types: map[string]interface{}{"mapStringInterface": map[string]interface{}{}}, Output: map[string]interface{}{"a": map[string]interface{}{"b": "b"}, "c": []byte(`{"b":"b"}`)}},
{Script: `json = import("encoding/json"); a = make(map[string]interface); a["b"] = "b"; c, err = json.Marshal(a); err`, Output: map[string]interface{}{"a": map[string]interface{}{"b": "b"}, "c": []byte(`{"b":"b"}`)}},
{Script: `json = import("encoding/json"); b = 1; err = json.Unmarshal(a, &b); err`, Input: map[string]interface{}{"a": []byte(`{"b": "b"}`)}, Output: map[string]interface{}{"a": []byte(`{"b": "b"}`), "b": map[string]interface{}{"b": "b"}}},
{Script: `json = import("encoding/json"); b = 1; err = json.Unmarshal(a, &b); err`, Input: map[string]interface{}{"a": `{"b": "b"}`}, Output: map[string]interface{}{"a": `{"b": "b"}`, "b": map[string]interface{}{"b": "b"}}},
{Script: `json = import("encoding/json"); b = 1; err = json.Unmarshal(a, &b); err`, Input: map[string]interface{}{"a": `[["1", "2"],["3", "4"]]`}, Output: map[string]interface{}{"a": `[["1", "2"],["3", "4"]]`, "b": []interface{}{[]interface{}{"1", "2"}, []interface{}{"3", "4"}}}},
Expand Down
17 changes: 4 additions & 13 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var opName = map[string]int{
"len": LEN,
"delete": DELETE,
"close": CLOSE,
"map": MAP,
}

var (
Expand Down Expand Up @@ -190,19 +191,9 @@ retry:
tok = MINUSEQ
lit = "-="
default:
if isDigit(s.peek()) {
tok = NUMBER
lit, err = s.scanNumber()
if err != nil {
return
}
lit = "-" + lit
s.back()
} else {
s.back()
tok = int(ch)
lit = "-"
}
s.back()
tok = int(ch)
lit = "-"
}
case '*':
s.next()
Expand Down
Loading

0 comments on commit c573355

Please sign in to comment.