Elem makes it possible to specify validations for array and map values. Example: Attribute("array", ArrayOf(Int), func() { Elem(func() { Enum(1, 2, 3, 4, 5) // list possible values for array elements }) }) Attribute("map", MapOf(String, Int), func() { Elem(func() {
(fn func())
| 288 | // }) |
| 289 | // }) |
| 290 | func Elem(fn func()) { |
| 291 | at, ok := eval.Current().(*expr.AttributeExpr) |
| 292 | if !ok { |
| 293 | eval.IncompatibleDSL() |
| 294 | return |
| 295 | } |
| 296 | switch e := at.Type.(type) { |
| 297 | case *expr.Array: |
| 298 | eval.Execute(fn, e.ElemType) |
| 299 | case *expr.Map: |
| 300 | eval.Execute(fn, e.ElemType) |
| 301 | default: |
| 302 | eval.IncompatibleDSL() |
| 303 | } |
| 304 | } |