From 6ea95526bc3bc4e9589fa8378f73bc6eaee5a483 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Tue, 21 Apr 2015 10:45:11 +0200 Subject: Move code generation code and sources to 'tool' --- build_replies.rs | 81 -------------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 build_replies.rs (limited to 'build_replies.rs') diff --git a/build_replies.rs b/build_replies.rs deleted file mode 100644 index a9c00e4..0000000 --- a/build_replies.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::fs::File; -use std::io::{ Read }; -use std::borrow::ToOwned; - -#[derive(Debug)] -struct Reply { - number: String, - reply: String, - doc: String -} - -fn main() { - let mut f = File::open("rfc2812_replies.txt").unwrap(); - - let mut content = String::new(); - f.read_to_string(&mut content).unwrap(); - - let mut lines = content.lines(); - let mut line = lines.next(); - - let mut replies = Vec::new(); - - while let Some(l) = line { - // if is new command - if l.chars().next().map(char::is_whitespace) == Some(false) { - let t = l.split(" ").filter(|s| !s.is_empty()).collect::>(); - assert_eq!(t.len(), 2); - replies.push(Reply { - number: t[0].to_owned(), - reply: t[1].to_owned(), - doc: String::new() - }); - } - - let len = replies.len(); - replies[len - 1].doc.push_str(l); - replies[len - 1].doc.push_str("\n"); - - line = lines.next(); - } - - println!("use ::{{ Result, IrscError }};"); - println!("use std::str::FromStr;"); - println!("use std::borrow::ToOwned;"); - - println!("#[allow(non_camel_case_types)]"); - println!("#[derive(Debug, Hash, PartialEq, Eq)]"); - println!("pub enum Reply {{"); - for r in &replies { - for l in r.doc.lines() { - println!(" /// {}", l); - } - - println!(" {} = {},\n", r.reply, r.number); - } - println!("}}\n\n"); - - println!("impl FromStr for Reply {{"); - println!(" type Err = IrscError;"); - println!(" fn from_str(s: &str) -> Result {{"); - println!(" use self::Reply::*;"); - println!(" match s {{"); - for r in &replies { - println!(" \"{}\" => Ok({}),", r.number, r.reply); - } - println!(" _ => Err(IrscError::NotFound)"); - println!(" }}"); - println!(" }}"); - println!("}}"); - - println!("impl ToString for Reply {{"); - println!(" fn to_string(&self) -> String {{"); - println!(" use self::Reply::*;"); - println!(" match *self {{"); - for r in &replies { - println!(" {} => \"{}\".to_owned(),", r.reply, r.number); - } - println!(" }}"); - println!(" }}"); - println!("}}"); -} -- cgit v1.2.3