MCPcopy Create free account
hub / github.com/apache/fory / parse_rpc_method

Method parse_rpc_method

compiler/fory_compiler/frontend/proto/parser.py:431–482  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

429 )
430
431 def parse_rpc_method(self) -> ProtoRpcMethod:
432 start = self.current()
433 self.consume(TokenType.RPC, "Expected 'rpc'")
434 name = self.consume(TokenType.IDENT, "Expected method name").value
435
436 # Request
437 self.consume(TokenType.LPAREN, "Expected '(' before request type")
438 client_streaming = False
439 if self.match(TokenType.STREAM):
440 client_streaming = True
441
442 req_type = self.parse_full_ident()
443 self.consume(TokenType.RPAREN, "Expected ')' after request type")
444
445 self.consume(TokenType.RETURNS, "Expected 'returns'")
446
447 # Response
448 self.consume(TokenType.LPAREN, "Expected '(' before response type")
449 server_streaming = False
450 if self.match(TokenType.STREAM):
451 server_streaming = True
452
453 res_type = self.parse_full_ident()
454 self.consume(TokenType.RPAREN, "Expected ')' after response type")
455
456 options = {}
457 if self.check(TokenType.LBRACE):
458 self.consume(TokenType.LBRACE, "Expected '{'")
459 while not self.check(TokenType.RBRACE):
460 if self.check(TokenType.OPTION):
461 opt_name, opt_value = self.parse_option_statement()
462 options[opt_name] = opt_value
463 elif self.check(TokenType.SEMI):
464 self.advance()
465 else:
466 raise self.error("Expected 'option' in method body")
467 self.consume(TokenType.RBRACE, "Expected '}'")
468 if self.check(TokenType.SEMI):
469 self.advance()
470 else:
471 self.consume(TokenType.SEMI, "Expected ';' or '{' after method signature")
472
473 return ProtoRpcMethod(
474 name=name,
475 request_type=req_type,
476 response_type=res_type,
477 client_streaming=client_streaming,
478 server_streaming=server_streaming,
479 options=options,
480 line=start.line,
481 column=start.column,
482 )
483
484 def parse_option_name(self) -> str:
485 if self.match(TokenType.LPAREN):

Callers 1

parse_serviceMethod · 0.95

Calls 9

currentMethod · 0.95
consumeMethod · 0.95
matchMethod · 0.95
parse_full_identMethod · 0.95
checkMethod · 0.95
advanceMethod · 0.95
errorMethod · 0.95
ProtoRpcMethodClass · 0.90

Tested by

no test coverage detected