func (r *resolver) resolveMethod(s *scope, mth *ast.Method) error { o := r.resolveName(s, mth.InTypeName) if o == nil { return fmt.Errorf("failed to resolve name %q", mth.InTypeName) } mth.InType = o.last() o = r.resolveName(s, mth.OutTypeName) if o == nil { return fmt.Errorf("failed to resolve name %q", mth.OutTypeName) } mth.OutType = o.last() return nil }
func (p *parser) readService(srv *ast.Service) *parseError { if err := p.readToken("service"); err != nil { return err } srv.Position = p.cur.astPosition() tok := p.next() if tok.err != nil { return tok.err } srv.Name = tok.value // TODO: validate if err := p.readToken("{"); err != nil { return err } // Parse methods for !p.done { tok := p.next() if tok.err != nil { return tok.err } switch tok.value { case "}": // end of service return nil case "rpc": // handled below default: return p.errorf(`got %q, want "rpc" or "}"`, tok.value) } tok = p.next() if tok.err != nil { return tok.err } mth := new(ast.Method) srv.Methods = append(srv.Methods, mth) mth.Position = tok.astPosition() mth.Name = tok.value // TODO: validate mth.Up = srv if err := p.readToken("("); err != nil { return err } tok = p.next() if tok.err != nil { return tok.err } mth.InTypeName = tok.value // TODO: validate if tok.value == "stream" { // If the next token isn't ")", this is a stream. tok = p.next() if tok.err != nil { return tok.err } if tok.value != ")" { mth.InTypeName = tok.value mth.ClientStreaming = true } else { p.back() } } if err := p.readToken(")"); err != nil { return err } if err := p.readToken("returns"); err != nil { return err } if err := p.readToken("("); err != nil { return err } tok = p.next() if tok.err != nil { return tok.err } mth.OutTypeName = tok.value // TODO: validate if tok.value == "stream" { // If the next token isn't ")", this is a stream. tok = p.next() if tok.err != nil { return tok.err } if tok.value != ")" { mth.OutTypeName = tok.value mth.ServerStreaming = true } else { p.back() } } if err := p.readToken(")"); err != nil { return err } if err := p.readToken(";"); err != nil { return err } } return p.errorf("unexpected EOF while parsing service") }