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

Method interfaceType

syntax/parser.go:1469–1530  ·  view source on GitHub ↗

InterfaceType = "interface" "{" { ( MethodDecl | EmbeddedElem | TypeList ) ";" } "}" . TypeList = "type" Type { "," Type } . TODO(gri) remove TypeList syntax if we accept #45346

()

Source from the content-addressed store, hash-verified

1467// TypeList = "type" Type { "," Type } .
1468// TODO(gri) remove TypeList syntax if we accept #45346
1469func (p *parser) interfaceType() *InterfaceType {
1470 if trace {
1471 defer p.trace("interfaceType")()
1472 }
1473
1474 typ := new(InterfaceType)
1475 typ.pos = p.pos()
1476
1477 p.want(_Interface)
1478 p.asyncList(_Lbrace, _Semi, _Rbrace, func() bool {
1479 switch p.tok {
1480 case _Name:
1481 f := p.methodDecl()
1482 if f.Name == nil && p.allowGenerics() {
1483 f = p.embeddedElem(f)
1484 }
1485 typ.MethodList = append(typ.MethodList, f)
1486 return false
1487
1488 case _Lparen:
1489 // TODO(gri) Need to decide how to adjust this restriction.
1490 p.syntaxError("cannot parenthesize embedded type")
1491 f := new(Field)
1492 f.pos = p.pos()
1493 p.next()
1494 f.Type = p.qualifiedName(nil)
1495 p.want(_Rparen)
1496 typ.MethodList = append(typ.MethodList, f)
1497 return false
1498
1499 case _Operator:
1500 if p.op == Tilde && p.allowGenerics() {
1501 typ.MethodList = append(typ.MethodList, p.embeddedElem(nil))
1502 return false
1503 }
1504
1505 default:
1506 if p.allowGenerics() {
1507 pos := p.pos()
1508 if t := p.typeOrNil(); t != nil {
1509 f := new(Field)
1510 f.pos = pos
1511 f.Type = t
1512 typ.MethodList = append(typ.MethodList, p.embeddedElem(f))
1513 return false
1514 }
1515 }
1516 }
1517
1518 if p.allowGenerics() {
1519 p.syntaxError("expecting method or embedded element")
1520 p.advance(_Semi, _Rbrace)
1521 return false
1522 }
1523
1524 p.syntaxError("expecting method or interface name")
1525 p.advance(_Semi, _Rbrace)
1526 return false

Callers 1

typeOrNilMethod · 0.95

Calls 14

traceMethod · 0.95
posMethod · 0.95
wantMethod · 0.95
asyncListMethod · 0.95
methodDeclMethod · 0.95
allowGenericsMethod · 0.95
embeddedElemMethod · 0.95
syntaxErrorMethod · 0.95
qualifiedNameMethod · 0.95
typeOrNilMethod · 0.95
advanceMethod · 0.95
nextMethod · 0.65

Tested by

no test coverage detected