fn parse(&mut self) -> io::Result<Node> {
        match self.token.kind {
            TokenKind::Package => {
                // Package node
                self.consume_token(TokenKind::Package)?;
                let node = Node::Package(self.token.value.clone().unwrap());
                self.consume_token(TokenKind::Identifier)?;
                self.consume_token(TokenKind::Semicolon)?;
                Ok(node)
            }
            TokenKind::Service => {
                // Service node
                self.consume_token(TokenKind::Service)?;
                // Get service name
                let service = self
                    .consume_token(TokenKind::Identifier)?
                    .expect("service name does not exist");
                self.consume_token(TokenKind::LeftBrace)?;
                // Pare RPC definitions
                let mut rpc_definitions = Vec::new();
                let mut messages = HashSet::new();
                while self.token.kind == TokenKind::Rpc {
                    rpc_definitions.push(self.parse_rpc(&mut messages)?);
                }
                let mut messages_unique = messages.into_iter().collect::<Vec<String>>();
                messages_unique.sort();
                self.consume_token(TokenKind::RightBrace)?;
                Ok(Node::Service {
                    name: service,
                    messages: messages_unique,
                    rpcs: rpc_definitions,
                })
            }
            TokenKind::Enum => {
                // Enum node
                self.consume_token(TokenKind::Enum)?;
                // Get enum message name
                let enum_name = self
                    .consume_token(TokenKind::Identifier)?
                    .expect("enum name does not exist");
                self.consume_token(TokenKind::LeftBrace)?;
                let mut index = 0;
                let mut elements = Vec::new();
                while self.token.kind == TokenKind::Identifier {
                    elements.push(self.parse_enum(index)?);
                    index += 1;
                }
                self.consume_token(TokenKind::RightBrace)?;
                Ok(Node::Enum {
                    name: enum_name,
                    elements,
                })
            }
            _ => Err(Error::new(
                ErrorKind::InvalidInput,
                "only package or service definitions are to be parsed",
            )),
        }
    }
/// Parse package statement or service definition.
/// ```text
/// package name;
/// service name{
///   rpc method(request) returns (response);
///   rpc method(request) returns (response);
/// }
/// ```
Parse package statement or service definition.
Parse package statement or service definition .
fn parse(&mut self) -> io::Result<Node> {
        match self.token.kind {
            TokenKind::Package => {
                // Package node
                self.consume_token(TokenKind::Package)?;
                let node = Node::Package(self.token.value.clone().unwrap());
                self.consume_token(TokenKind::Identifier)?;
                self.consume_token(TokenKind::Semicolon)?;
                Ok(node)
            }
            TokenKind::Service => {
                // Service node
                self.consume_token(TokenKind::Service)?;
                // Get service name
                let service = self
                    .consume_token(TokenKind::Identifier)?
                    .expect("service name does not exist");
                self.consume_token(TokenKind::LeftBrace)?;
                // Pare RPC definitions
                let mut rpc_definitions = Vec::new();
                let mut messages = HashSet::new();
                while self.token.kind == TokenKind::Rpc {
                    rpc_definitions.push(self.parse_rpc(&mut messages)?);
                }
                let mut messages_unique = messages.into_iter().collect::<Vec<String>>();
                messages_unique.sort();
                self.consume_token(TokenKind::RightBrace)?;
                Ok(Node::Service {
                    name: service,
                    messages: messages_unique,
                    rpcs: rpc_definitions,
                })
            }
            TokenKind::Enum => {
                // Enum node
                self.consume_token(TokenKind::Enum)?;
                // Get enum message name
                let enum_name = self
                    .consume_token(TokenKind::Identifier)?
                    .expect("enum name does not exist");
                self.consume_token(TokenKind::LeftBrace)?;
                let mut index = 0;
                let mut elements = Vec::new();
                while self.token.kind == TokenKind::Identifier {
                    elements.push(self.parse_enum(index)?);
                    index += 1;
                }
                self.consume_token(TokenKind::RightBrace)?;
                Ok(Node::Enum {
                    name: enum_name,
                    elements,
                })
            }
            _ => Err(Error::new(
                ErrorKind::InvalidInput,
                "only package or service definitions are to be parsed",
            )),
        }
    }
fn parse ( & mut self ) -> io :: Result < Node > { match self . token . kind { TokenKind :: Package => { // Package node self . consume_token ( TokenKind :: Package ) ? ; let node = Node :: Package ( self . token . value . clone ( ) . unwrap ( ) ) ; self . consume_token ( TokenKind :: Identifier ) ? ; self . consume_token ( TokenKind :: Semicolon ) ? ; Ok ( node ) } TokenKind :: Service => { // Service node self . consume_token ( TokenKind :: Service ) ? ; // Get service name let service = self . consume_token ( TokenKind :: Identifier ) ? . expect ( " " ) ; self . consume_token ( TokenKind :: LeftBrace ) ? ; // Pare RPC definitions let mut rpc_definitions = Vec :: new ( ) ; let mut messages = HashSet :: new ( ) ; while self . token . kind == TokenKind :: Rpc { rpc_definitions . push ( self . parse_rpc ( & mut messages ) ? ) ; } let mut messages_unique = messages . into_iter ( ) . collect :: < Vec < String > > ( ) ; messages_unique . sort ( ) ; self . consume_token ( TokenKind :: RightBrace ) ? ; Ok ( Node :: Service { name : service , messages : messages_unique , rpcs : rpc_definitions , } ) } TokenKind :: Enum => { // Enum node self . consume_token ( TokenKind :: Enum ) ? ; // Get enum message name let enum_name = self . consume_token ( TokenKind :: Identifier ) ? . expect ( " " ) ; self . consume_token ( TokenKind :: LeftBrace ) ? ; let mut index = 0 ; let mut elements = Vec :: new ( ) ; while self . token . kind == TokenKind :: Identifier { elements . push ( self . parse_enum ( index ) ? ) ; index += 1 ; } self . consume_token ( TokenKind :: RightBrace ) ? ; Ok ( Node :: Enum { name : enum_name , elements , } ) } _ => Err ( Error :: new ( ErrorKind :: InvalidInput , " " , ) ) , } }
Parse package statement or service definition.
Parse package statement or service definition .
&mut self
&mut self