rust/hedgewars-network-protocol/src/parser.rs
changeset 16026 7c8697fa019f
parent 16016 b26c3497ea85
equal deleted inserted replaced
16025:19927b70588c 16026:7c8697fa019f
     6  * For example, a nullary command like PING will be actually sent as `PING\n\n`.
     6  * For example, a nullary command like PING will be actually sent as `PING\n\n`.
     7  * A unary command, such as `START_GAME nick` will be actually sent as `START_GAME\nnick\n\n`.
     7  * A unary command, such as `START_GAME nick` will be actually sent as `START_GAME\nnick\n\n`.
     8  */
     8  */
     9 use nom::{
     9 use nom::{
    10     branch::alt,
    10     branch::alt,
    11     bytes::complete::{tag, tag_no_case, take_until, take_while},
    11     bytes::streaming::{tag, tag_no_case, take_until, take_while},
    12     character::complete::{newline, not_line_ending},
    12     character::streaming::{newline, not_line_ending},
    13     combinator::{map, peek},
    13     combinator::{map, peek},
    14     error::{ErrorKind, ParseError},
    14     error::{ErrorKind, ParseError},
    15     multi::separated_list0,
    15     multi::separated_list0,
    16     sequence::{delimited, pair, preceded, terminated, tuple},
    16     sequence::{delimited, pair, preceded, terminated, tuple},
    17     Err, IResult, Parser
    17     Err, IResult, Parser,
    18 };
    18 };
    19 
    19 
    20 use std::{
    20 use std::{
    21     num::ParseIntError,
    21     num::ParseIntError,
    22     str,
    22     str,
   212         parser: F,
   212         parser: F,
   213         constructor: G,
   213         constructor: G,
   214     ) -> impl FnMut(&'a [u8]) -> HwResult<HwProtocolMessage> + '_
   214     ) -> impl FnMut(&'a [u8]) -> HwResult<HwProtocolMessage> + '_
   215     where
   215     where
   216         F: Parser<&'a [u8], T, HwProtocolError> + 'a,
   216         F: Parser<&'a [u8], T, HwProtocolError> + 'a,
   217         G: FnMut(T) -> HwProtocolMessage + 'a
   217         G: FnMut(T) -> HwProtocolMessage + 'a,
   218     {
   218     {
   219         map(preceded(tag(name), parser), constructor)
   219         map(preceded(tag(name), parser), constructor)
   220     }
   220     }
   221 
   221 
   222     alt((
   222     alt((