()
| 603 | } |
| 604 | |
| 605 | func (p *parser) parseInterface() error { |
| 606 | s := p.s |
| 607 | t, err := expectTagContents(s) |
| 608 | if err != nil { |
| 609 | return err |
| 610 | } |
| 611 | |
| 612 | n := bytes.IndexByte(t.Value, '{') |
| 613 | if n < 0 { |
| 614 | return fmt.Errorf("missing '{' in interface at %s", s.Context()) |
| 615 | } |
| 616 | ifname := string(stripTrailingSpace(t.Value[:n])) |
| 617 | if len(ifname) == 0 { |
| 618 | return fmt.Errorf("missing interface name at %s", s.Context()) |
| 619 | } |
| 620 | p.Printf("type %s interface {", ifname) |
| 621 | p.prefix = "\t" |
| 622 | |
| 623 | tail := t.Value[n:] |
| 624 | exprStr := fmt.Sprintf("interface %s", tail) |
| 625 | expr, err := goparser.ParseExpr(exprStr) |
| 626 | if err != nil { |
| 627 | return fmt.Errorf("error when parsing interface at %s: %s", s.Context(), err) |
| 628 | } |
| 629 | it, ok := expr.(*ast.InterfaceType) |
| 630 | if !ok { |
| 631 | return fmt.Errorf("unexpected interface type at %s: %T", s.Context(), expr) |
| 632 | } |
| 633 | methods := it.Methods.List |
| 634 | if len(methods) == 0 { |
| 635 | return fmt.Errorf("interface must contain at least one method at %s", s.Context()) |
| 636 | } |
| 637 | |
| 638 | for _, m := range it.Methods.List { |
| 639 | methodStr := exprStr[m.Pos()-1 : m.End()-1] |
| 640 | f, err := parseFuncDef([]byte(methodStr)) |
| 641 | if err != nil { |
| 642 | return fmt.Errorf("when when parsing %q at %s: %s", methodStr, s.Context(), err) |
| 643 | } |
| 644 | p.Printf("%s string", methodStr) |
| 645 | p.Printf("%s", f.DefStream("qw"+mangleSuffix)) |
| 646 | p.Printf("%s", f.DefWrite("qq"+mangleSuffix)) |
| 647 | } |
| 648 | p.prefix = "" |
| 649 | p.Printf("}") |
| 650 | return nil |
| 651 | } |
| 652 | |
| 653 | func (p *parser) parsePackageName() error { |
| 654 | t, err := expectTagContents(p.s) |
no test coverage detected