예제 #1
0
파일: bracket.go 프로젝트: gale320/gisp
func (bracket Bracket) evalSlice(env Env, val reflect.Value) (interface{}, error) {
	items, err := Evals(env, bracket.expr...)
	if err != nil {
		return nil, err
	}
	indexs, err := bracket.computeIndexs(val, items)
	if err != nil {
		return nil, err
	}
	switch len(indexs) {
	case 2:
		v := val.Slice(indexs[0], indexs[1])
		return bracket.inter(v), nil
	case 3:
		v := val.Slice3(indexs[0], indexs[1], indexs[2])
		return bracket.inter(v), nil
	}

	return nil, fmt.Errorf("Index for slice %v[%v]  is invalid",
		bracket.obj, bracket.expr)
}