VisitAppl visits a parse tree produced by MangleParser#Appl.
(ctx *gen.ApplContext)
| 527 | |
| 528 | // VisitAppl visits a parse tree produced by MangleParser#Appl. |
| 529 | func (p Parser) VisitAppl(ctx *gen.ApplContext) any { |
| 530 | name := ctx.NAME().GetText() |
| 531 | |
| 532 | if strings.HasPrefix(name, "fn:") { |
| 533 | // Either ast.Atom or ast.ApplyFn |
| 534 | var args []ast.BaseTerm |
| 535 | for _, e := range ctx.AllTerm() { |
| 536 | arg := p.Visit(e) |
| 537 | baseTerm, ok := arg.(ast.BaseTerm) |
| 538 | if !ok { |
| 539 | p.errors.Add(fmt.Sprintf("expected base term got %v", arg), e.GetStart().GetLine(), e.GetStart().GetColumn()) |
| 540 | continue |
| 541 | } |
| 542 | args = append(args, baseTerm) |
| 543 | } |
| 544 | fnSym := ast.FunctionSym{name, len(args)} |
| 545 | return ast.ApplyFn{fnSym, args} |
| 546 | } |
| 547 | |
| 548 | var args []ast.BaseTerm |
| 549 | for _, e := range ctx.AllTerm() { |
| 550 | arg := p.Visit(e) |
| 551 | baseTerm, ok := arg.(ast.BaseTerm) |
| 552 | if !ok { |
| 553 | p.errors.Add(fmt.Sprintf("expected base term got %v", arg), e.GetStart().GetLine(), e.GetStart().GetColumn()) |
| 554 | args = append(args, ast.AnyBound) |
| 555 | continue |
| 556 | } |
| 557 | args = append(args, baseTerm) |
| 558 | } |
| 559 | predicateSym := ast.PredicateSym{ctx.NAME().GetText(), len(args)} |
| 560 | return ast.Atom{predicateSym, args} |
| 561 | } |
| 562 | |
| 563 | // VisitMap visits a parse tree produced by MangleParser#Map. |
| 564 | func (p Parser) VisitMap(ctx *gen.MapContext) any { |