Esempio n. 1
0
func composeInts(expr *ast.Expr) (funcs.Ints, error) {
	uniq, err := prep(expr, types.LIST_INT)
	if err != nil {
		return nil, err
	}
	if expr.List != nil {
		vs, err := newValues(expr.GetList().GetElems())
		if err != nil {
			return nil, err
		}
		bs := make([]funcs.Int, len(vs))
		var ok bool
		for i := range vs {
			bs[i], ok = vs[i].(funcs.Int)
			if !ok {
				return nil, &errExpected{types.SINGLE_INT.String(), expr.String()}
			}
		}
		return funcs.NewListOfInt(bs), nil
	}
	values, err := newValues(expr.GetFunction().GetParams())
	if err != nil {
		return nil, err
	}
	return funcs.NewIntsFunc(uniq, values...)
}
Esempio n. 2
0
func prep(expr *ast.Expr, expType types.Type) (uniq string, err error) {
	if expr.Function != nil {
		fnc := expr.GetFunction()
		uniq, err = WhichFunc(fnc)
		if err != nil {
			return "", err
		}
		typ, err := funcs.Out(uniq)
		if err != nil {
			return "", err
		}
		if typ != expType {
			return "", &errExpected{expType.String(), expr.String()}
		}
		return uniq, err
	}
	if expr.List != nil {
		if !types.IsList(expType) {
			return "", &errExpected{expType.String(), expr.String()}
		}
	}
	typ, err := Which(expr)
	if err != nil {
		return "", err
	}
	if typ != expType {
		return "", &errExpected{expType.String(), expr.String()}
	}
	return "", nil
}