| 327 | } |
| 328 | |
| 329 | func projectCollection(rt *ResultTypeExpr, view string, seen map[string]*AttributeExpr) (*ResultTypeExpr, error) { |
| 330 | // Project the collection element result type |
| 331 | e := rt.Type.(*Array).ElemType.Type.(*ResultTypeExpr) // validation checked this cast would work |
| 332 | pe, err2 := project(e, view, seen) |
| 333 | if err2 != nil { |
| 334 | return nil, fmt.Errorf("collection element: %w", err2) |
| 335 | } |
| 336 | |
| 337 | // Build the projected collection with the results |
| 338 | id := rt.projectIdentifier(view) |
| 339 | proj := &ResultTypeExpr{ |
| 340 | Identifier: id, |
| 341 | UserTypeExpr: &UserTypeExpr{ |
| 342 | AttributeExpr: &AttributeExpr{ |
| 343 | Description: rt.TypeName + " is the result type for an array of " + e.TypeName + " (" + view + " view)", |
| 344 | Type: &Array{ElemType: &AttributeExpr{Type: pe}}, |
| 345 | UserExamples: rt.UserExamples, |
| 346 | }, |
| 347 | TypeName: pe.TypeName + "Collection", |
| 348 | UID: id, |
| 349 | }, |
| 350 | Views: []*ViewExpr{{ |
| 351 | AttributeExpr: DupAtt(pe.View(DefaultView).AttributeExpr), |
| 352 | Name: DefaultView, |
| 353 | Parent: pe, |
| 354 | }}, |
| 355 | } |
| 356 | |
| 357 | // Run the DSL that was created by the CollectionOf function |
| 358 | if !eval.Execute(proj.DSL(), proj) { |
| 359 | return nil, eval.Context.Errors |
| 360 | } |
| 361 | |
| 362 | return proj, nil |
| 363 | } |
| 364 | |
| 365 | func projectRecursive(at *AttributeExpr, vat *NamedAttributeExpr, view string, seen map[string]*AttributeExpr) (*AttributeExpr, error) { |
| 366 | if att, ok := seen[hashAttrAndView(at, view)]; ok { |