@@ -34,6 +34,8 @@ type RPC struct {
3434 Comments []* Comment
3535 // InlineComment is the optional one placed at the ending.
3636 InlineComment * Comment
37+ // InlineCommentBehindLeftCurly is the optional one placed behind a left curly.
38+ InlineCommentBehindLeftCurly * Comment
3739 // Meta is the meta information.
3840 Meta meta.Meta
3941}
@@ -99,7 +101,8 @@ func (s *Service) Accept(v Visitor) {
99101}
100102
101103// ParseService parses the service.
102- // service = "service" serviceName "{" { option | rpc | emptyStatement } "}"
104+ //
105+ // service = "service" serviceName "{" { option | rpc | emptyStatement } "}"
103106//
104107// See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#service_definition
105108func (p * Parser ) ParseService () (* Service , error ) {
@@ -235,12 +238,13 @@ func (p *Parser) parseRPC() (*RPC, error) {
235238 }
236239
237240 var opts []* Option
241+ var inlineLeftCurly * Comment
238242 p .lex .Next ()
239243 lastPos := p .lex .Pos
240244 switch p .lex .Token {
241245 case scanner .TLEFTCURLY :
242246 p .lex .UnNext ()
243- opts , err = p .parseRPCOptions ()
247+ opts , inlineLeftCurly , err = p .parseRPCOptions ()
244248 if err != nil {
245249 return nil , err
246250 }
@@ -259,10 +263,11 @@ func (p *Parser) parseRPC() (*RPC, error) {
259263 }
260264
261265 return & RPC {
262- RPCName : rpcName ,
263- RPCRequest : rpcRequest ,
264- RPCResponse : rpcResponse ,
265- Options : opts ,
266+ RPCName : rpcName ,
267+ RPCRequest : rpcRequest ,
268+ RPCResponse : rpcResponse ,
269+ Options : opts ,
270+ InlineCommentBehindLeftCurly : inlineLeftCurly ,
266271 Meta : meta.Meta {
267272 Pos : startPos .Position ,
268273 LastPos : lastPos .Position ,
@@ -338,12 +343,14 @@ func (p *Parser) parseRPCResponse() (*RPCResponse, error) {
338343
339344// rpcOptions = ( "{" {option | emptyStatement } "}" )
340345// See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#service_definition
341- func (p * Parser ) parseRPCOptions () ([]* Option , error ) {
346+ func (p * Parser ) parseRPCOptions () ([]* Option , * Comment , error ) {
342347 p .lex .Next ()
343348 if p .lex .Token != scanner .TLEFTCURLY {
344- return nil , p .unexpected ("{" )
349+ return nil , nil , p .unexpected ("{" )
345350 }
346351
352+ inlineLeftCurly := p .parseInlineComment ()
353+
347354 var options []* Option
348355 for {
349356 p .lex .NextKeyword ()
@@ -354,7 +361,7 @@ func (p *Parser) parseRPCOptions() ([]*Option, error) {
354361 case scanner .TOPTION :
355362 option , err := p .ParseOption ()
356363 if err != nil {
357- return nil , err
364+ return nil , nil , err
358365 }
359366 options = append (options , option )
360367 case scanner .TRIGHTCURLY :
@@ -363,13 +370,13 @@ func (p *Parser) parseRPCOptions() ([]*Option, error) {
363370 default :
364371 err := p .lex .ReadEmptyStatement ()
365372 if err != nil {
366- return nil , err
373+ return nil , nil , err
367374 }
368375 }
369376
370377 p .lex .Next ()
371378 if p .lex .Token == scanner .TRIGHTCURLY {
372- return options , nil
379+ return options , inlineLeftCurly , nil
373380 }
374381 p .lex .UnNext ()
375382 }
0 commit comments