gameServer2/src/protocol/hwprotocol.lalrpop
changeset 12131 a4d22f197bd2
parent 12130 6273f89ab13d
equal deleted inserted replaced
12130:6273f89ab13d 12131:a4d22f197bd2
     1 use std::str;
     1 use std::string;
       
     2 use std::str::FromStr;
     2 
     3 
     3 use super::messages::HWProtocolMessage::*;
     4 use super::messages::HWProtocolMessage::*;
     4 use super::messages::HWProtocolMessage;
     5 use super::messages::*;
     5 
     6 
     6 grammar;
     7 grammar;
     7 
     8 
     8 pub ProtocolMessage: HWProtocolMessage<'input> = {
     9 pub ProtocolMessage: HWProtocolMessage = {
     9     "NICK" <s:Str> => Nick(s),
    10     <SpecificMessage> "\n\n",
    10 };
    11 };
    11 
    12 
    12 Str: &'input str = {
    13 SpecificMessage: HWProtocolMessage = {
    13     <s:r"[^\n]\n"> => s,
    14     "NICK" "\n" <ProtocolString> => Nick(<>),
       
    15     "PONG" => Pong,
       
    16     "PING" => Ping,
       
    17     "PROTO" "\n" <Num32> => Proto(<>),
    14 };
    18 };
    15 
    19 
       
    20 Num32: u32 =
       
    21     <Digit*> => number(<>);
    16 
    22 
    17 //Num32: i32 = <s:r"[0-9]+"> => i32::from_str(s).unwrap();
    23 ProtocolString: String =
       
    24     <ProtocolChar*> => <>.join("");
       
    25 
       
    26 ProtocolChar: &'input str =
       
    27     r"[^\n]" => <>;
       
    28 
       
    29 Digit: u8 = {
       
    30     "0" => 0,
       
    31     "1" => 1,
       
    32     "2" => 2,
       
    33     "3" => 3,
       
    34     "4" => 4,
       
    35     "5" => 5,
       
    36     "6" => 6,
       
    37     "7" => 7,
       
    38     "8" => 8,
       
    39     "9" => 9,
       
    40 };