MergePredicate returns the information from the merge predicate descriptor. A merge predicate is a three-place.
()
| 317 | // |
| 318 | // A merge predicate is a three-place. |
| 319 | func (d Decl) MergePredicate() ([]int, PredicateSym) { |
| 320 | bad := false |
| 321 | var indices []int |
| 322 | var mergePred PredicateSym |
| 323 | d.findDescr(DescrMergePredicate, func(a Atom) { |
| 324 | if len(a.Args) != 2 { |
| 325 | bad = true |
| 326 | return |
| 327 | } |
| 328 | var tgtVars []int |
| 329 | if tgtListApply, ok := (a.Args)[0].(ApplyFn); ok && tgtListApply.Function.Symbol == "fn:list" { |
| 330 | for _, tgtVar := range tgtListApply.Args { |
| 331 | if tgtVar, ok := tgtVar.(Variable); ok { |
| 332 | for j, declVar := range d.DeclaredAtom.Args { |
| 333 | if declVar == tgtVar { |
| 334 | tgtVars = append(tgtVars, j) |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | predNameConstant, ok := (a.Args)[1].(Constant) |
| 341 | if !ok { |
| 342 | bad = true |
| 343 | return |
| 344 | } |
| 345 | predName, err := predNameConstant.StringValue() |
| 346 | if err != nil { |
| 347 | bad = true |
| 348 | return |
| 349 | } |
| 350 | indices = tgtVars |
| 351 | mergePred = PredicateSym{predName, 2*len(tgtVars) + 1} |
| 352 | }) |
| 353 | if bad { |
| 354 | return nil, PredicateSym{} |
| 355 | } |
| 356 | return indices, mergePred |
| 357 | } |
| 358 | |
| 359 | // BoundDecl is a bound declaration for the arguments of a predicate. |
| 360 | // |
no test coverage detected