aboutsummaryrefslogtreecommitdiff
path: root/build_replies.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-04-21 10:45:11 +0200
committerTill Hoeppner2015-04-21 10:45:54 +0200
commit6ea95526bc3bc4e9589fa8378f73bc6eaee5a483 (patch)
tree9f4f6f41f6c899084dc954ac6d3b61627b709a6d /build_replies.rs
parent7829586d607759d7544bbfd421d8eef4d17091f6 (diff)
downloadirsc-6ea95526bc3bc4e9589fa8378f73bc6eaee5a483.tar.gz
irsc-6ea95526bc3bc4e9589fa8378f73bc6eaee5a483.tar.xz
irsc-6ea95526bc3bc4e9589fa8378f73bc6eaee5a483.zip
Move code generation code and sources to 'tool'
Diffstat (limited to 'build_replies.rs')
-rw-r--r--build_replies.rs81
1 files changed, 0 insertions, 81 deletions
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::<Vec<&str>>();
- 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<Reply> {{");
- 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!("}}");
-}