gameServer2/src/protocol/hwprotocol.lalrpop
author unc0rr
Fri, 06 Jan 2017 01:00:21 +0300
changeset 12136 a4d22f197bd2
parent 12135 6273f89ab13d
permissions -rw-r--r--
Still trying to make parser work

use std::string;
use std::str::FromStr;

use super::messages::HWProtocolMessage::*;
use super::messages::*;

grammar;

pub ProtocolMessage: HWProtocolMessage = {
    <SpecificMessage> "\n\n",
};

SpecificMessage: HWProtocolMessage = {
    "NICK" "\n" <ProtocolString> => Nick(<>),
    "PONG" => Pong,
    "PING" => Ping,
    "PROTO" "\n" <Num32> => Proto(<>),
};

Num32: u32 =
    <Digit*> => number(<>);

ProtocolString: String =
    <ProtocolChar*> => <>.join("");

ProtocolChar: &'input str =
    r"[^\n]" => <>;

Digit: u8 = {
    "0" => 0,
    "1" => 1,
    "2" => 2,
    "3" => 3,
    "4" => 4,
    "5" => 5,
    "6" => 6,
    "7" => 7,
    "8" => 8,
    "9" => 9,
};