MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / methodDecl

Method methodDecl

syntax/parser.go:1709–1821  ·  view source on GitHub ↗

MethodSpec = MethodName Signature | InterfaceTypeName . MethodName = identifier . InterfaceTypeName = TypeName .

()

Source from the content-addressed store, hash-verified

1707// MethodName = identifier .
1708// InterfaceTypeName = TypeName .
1709func (p *parser) methodDecl() *Field {
1710 if trace {
1711 defer p.trace("methodDecl")()
1712 }
1713
1714 f := new(Field)
1715 f.pos = p.pos()
1716 name := p.name()
1717
1718 // accept potential name list but complain
1719 // TODO(gri) We probably don't need this special check anymore.
1720 // Nobody writes this kind of code. It's from ancient
1721 // Go beginnings.
1722 hasNameList := false
1723 for p.got(_Comma) {
1724 p.name()
1725 hasNameList = true
1726 }
1727 if hasNameList {
1728 p.syntaxError("name list not allowed in interface type")
1729 // already progressed, no need to advance
1730 }
1731
1732 const context = "interface method"
1733
1734 switch p.tok {
1735 case _Lparen:
1736 // method
1737 f.Name = name
1738 f.Type = p.funcType(context, nil)
1739
1740 case _Lbrack:
1741 if p.allowGenerics() {
1742 // Careful dance: We don't know if we have a generic method m[T C](x T)
1743 // or an embedded instantiated type T[P1, P2] (we accept generic methods
1744 // for generality and robustness of parsing).
1745 pos := p.pos()
1746 p.next()
1747
1748 // Empty type parameter or argument lists are not permitted.
1749 // Treat as if [] were absent.
1750 if p.tok == _Rbrack {
1751 // name[]
1752 pos := p.pos()
1753 p.next()
1754 if p.tok == _Lparen {
1755 // name[](
1756 p.errorAt(pos, "empty type parameter list")
1757 f.Name = name
1758 f.Type = p.funcType(context, nil)
1759 } else {
1760 p.errorAt(pos, "empty type argument list")
1761 f.Type = name
1762 }
1763 break
1764 }
1765
1766 // A type argument list looks like a parameter list with only

Callers 1

interfaceTypeMethod · 0.95

Calls 13

traceMethod · 0.95
posMethod · 0.95
nameMethod · 0.95
gotMethod · 0.95
syntaxErrorMethod · 0.95
funcTypeMethod · 0.95
allowGenericsMethod · 0.95
paramListMethod · 0.95
qualifiedNameMethod · 0.95
errorAtMethod · 0.80
nextMethod · 0.65
PosMethod · 0.65

Tested by

no test coverage detected