# HG changeset patch # User unc0rr # Date 1483814040 -10800 # Node ID 1525923cd7e3c8d9d294d5fa42b7ca6206d1295f # Parent a4d22f197bd2291878344c8ab651605c4db0384e Give up on lalrpop, let's try nom diff -r a4d22f197bd2 -r 1525923cd7e3 gameServer2/Cargo.toml --- 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 " ] -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" diff -r a4d22f197bd2 -r 1525923cd7e3 gameServer2/build.rs --- 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(); -} diff -r a4d22f197bd2 -r 1525923cd7e3 gameServer2/src/protocol/hwprotocol.lalrpop --- 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 = { - "\n\n", -}; - -SpecificMessage: HWProtocolMessage = { - "NICK" "\n" => Nick(<>), - "PONG" => Pong, - "PING" => Ping, - "PROTO" "\n" => Proto(<>), -}; - -Num32: u32 = - => number(<>); - -ProtocolString: String = - => <>.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, -}; diff -r a4d22f197bd2 -r 1525923cd7e3 gameServer2/src/protocol/lexer.rs --- 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 = 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; - - fn next(&mut self) -> Option { - 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 - } - } - } -} diff -r a4d22f197bd2 -r 1525923cd7e3 gameServer2/src/protocol/mod.rs --- 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()); -}