Skip to content

feat(gpRc): update FDL lexer/parser to support service and rpc definitions#3308

Merged
chaokunyang merged 18 commits intoapache:mainfrom
ayush00git:feat/fdl-parser
Feb 8, 2026
Merged

feat(gpRc): update FDL lexer/parser to support service and rpc definitions#3308
chaokunyang merged 18 commits intoapache:mainfrom
ayush00git:feat/fdl-parser

Conversation

@ayush00git
Copy link
Contributor

@ayush00git ayush00git commented Feb 7, 2026

Why?

Using fory with gRPCs forced using the protobuffs for the services and methods of a class. Users needed to define separate files for generating stubs. Which turns their focus on using protobuff completely, ignoring the fory's performance.

What does this PR do?

Adds the parser for rpc methods and services to allow users use FDL with gRPC.

Added Keywords

service
rpc
returns
stream

Changes Made

1. compiler/fory_compiler/ir/ast.py

Added RpcMethod and Service Data classes.

@dataclass
class Service:
    """A service definition."""

    name: str
    methods: List[RpcMethod] = field(default_factory=list)
    options: dict = field(default_factory=dict)
    line: int = 0
    column: int = 0
    location: Optional[SourceLocation] = None

    def __repr__(self) -> str:
        opts_str = f", options={len(self.options)}" if self.options else ""
        return f"Service({self.name}, methods={len(self.methods)}{opts_str})"

2. compiler/fory_compiler/frontend/fdl/lexer.py

  • Added the SERVICE RPC RETURNS STREAM to the TokenType enum
  • Mapped Keywords in Lexer.Keywords
    SERVICE = auto()
    RPC = auto()
    RETURNS = auto()
    STREAM = auto()
   "service": TokenType.SERVICE,
   "rpc": TokenType.RPC,
   "returns": TokenType.RETURNS,
   "stream": TokenType.STREAM,

3. compiler/fory_compiler/frontend/fdl/parser.py

  • Added the parse_service and parse_rpc_method method.
    def parse_service(self) -> Service:
        """Parse a service definition: service Greeter { rpc ... }"""
        start = self.current()
        self.consume(TokenType.SERVICE)
        name = self.consume(TokenType.IDENT, "Expected service name").value
        self.consume(TokenType.LBRACE, "Expected '{' after service name")
.....
    def parse_rpc_method(self) -> RpcMethod:
        """Parse an RPC method: rpc Name (stream? Req) returns (stream? Res) { option ... };"""
        start = self.current()
        self.consume(TokenType.RPC)
        name = self.consume(TokenType.IDENT, "Expected method name").value

        # Parse request type
        self.consume(TokenType.LPAREN, "Expected '(' before request type")
        client_streaming = False
        if self.check(TokenType.STREAM):
            self.advance()
            client_streaming = True

4. Done the same updates just a slight different based on implementations for the protobuffs and flatbuffers.

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
    This PR extends the FDL language with support for service definitions using service rpc returns and stream keywords. This allows users to define gRPC services directly in their FDL schemas.
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

N/A

@ayush00git
Copy link
Contributor Author

Hey @chaokunyang
Give it a review and let me know the desired changes. Meanwhile i'm working on the #3269

@chaokunyang
Copy link
Collaborator

chaokunyang commented Feb 7, 2026

You also need to update protobuf and flatbuffers idl parser and add tests

@ayush00git
Copy link
Contributor Author

Hey @chaokunyang
I've updated the proto and fbs parsers as well, have a review and let me know.

Copy link
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaokunyang chaokunyang merged commit dc9f3e7 into apache:main Feb 8, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compiler][gRPC][FDL] Parse service/rpc/stream in FDL frontend

2 participants