Give up on lalrpop, let's try nom
authorunc0rr
Sat, 07 Jan 2017 21:34:00 +0300
changeset 12137 1525923cd7e3
parent 12136 a4d22f197bd2
child 12138 81df2e1f9ae9
Give up on lalrpop, let's try nom
gameServer2/Cargo.toml
gameServer2/build.rs
gameServer2/src/protocol/hwprotocol.lalrpop
gameServer2/src/protocol/lexer.rs
gameServer2/src/protocol/mod.rs
--- a/gameServer2/Cargo.toml	Fri Jan 06 01:00:21 2017 +0300
+++ b/gameServer2/Cargo.toml	Sat Jan 07 21:34:00 2017 +0300
@@ -2,14 +2,10 @@
 name = "hedgewars-server"
 version = "0.0.1"
 authors = [ "Andrey Korotaev <a.korotaev@hedgewars.org>" ]
-build = "build.rs"
 
 [dependencies]
 rand = "0.3"
 mio = "0.6"
 slab = "0.3"
 netbuf = "0.3.8"
-lalrpop-util = "0.12.4"
-
-[build-dependencies]
-lalrpop = "0.12.4"
+nom = "^2.0"
--- a/gameServer2/build.rs	Fri Jan 06 01:00:21 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-extern crate lalrpop;
-
-fn main() {
-    lalrpop::process_root().unwrap();
-}
--- a/gameServer2/src/protocol/hwprotocol.lalrpop	Fri Jan 06 01:00:21 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-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,
-};
--- a/gameServer2/src/protocol/lexer.rs	Fri Jan 06 01:00:21 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-pub type Spanned<Tok, Loc, Error> = Result<(Loc, Tok, Loc), Error>;
-
-#[derive(Debug)]
-pub enum Tok {
-    Linefeed,
-}
-
-#[derive(Debug)]
-pub enum LexicalError {
-    // Not possible
-}
-
-use std::str::CharIndices;
-
-pub struct Lexer<'input> {
-    chars: CharIndices<'input>,
-}
-
-impl<'input> Lexer<'input> {
-    pub fn new(input: &'input str) -> Self {
-        Lexer { chars: input.char_indices() }
-    }
-}
-
-impl<'input> Iterator for Lexer<'input> {
-    type Item = Spanned<Tok, usize, LexicalError>;
-
-    fn next(&mut self) -> Option<Self::Item> {
-        loop {
-            match self.chars.next() {
-                Some((i, '\n')) => return Some(Ok((i, Tok::Linefeed, i+1))),
-
-                None => return None, // End of file
-                _ => continue, // Comment; skip this character
-            }
-        }
-    }
-}
--- a/gameServer2/src/protocol/mod.rs	Fri Jan 06 01:00:21 2017 +0300
+++ b/gameServer2/src/protocol/mod.rs	Sat Jan 07 21:34:00 2017 +0300
@@ -3,8 +3,6 @@
 use std::io::Result;
 
 mod messages;
-mod hwprotocol;
-mod lexer;
 
 pub struct FrameDecoder {
     buf: netbuf::Buf,
@@ -25,9 +23,3 @@
         &self.buf[..]
     }
 }
-
-#[test]
-fn testparser() {
-    assert_eq!(messages::HWProtocolMessage::Nick("hey".to_string()),
-               hwprotocol::parse_ProtocolMessage("NICK\nhey\n\n").unwrap());
-}