Created
February 21, 2016 10:16
-
-
Save anonymous/ae7b06b1d0a1fe1bbb84 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let spec = r#"PASS s | |
NICK s | |
USER s s s | |
OPER s s | |
MODE s s os | |
SERVICE s s s s s s | |
QUIT os | |
SQUIT s s | |
JOIN s os os | |
PART s os | |
TOPIC s os | |
NAMES os os | |
LIST os os | |
INVITE s s | |
KICK s s os | |
PRIVMSG s s | |
NOTICE s s | |
MOTD os | |
LUSERS os os | |
VERSION os | |
STATS os os | |
LINKS os os | |
TIME os | |
CONNECT s s os | |
TRACE os | |
ADMIN os | |
INFO os | |
SERVLIST os os | |
SQUERY s s | |
WHO os Option<bool> | |
WHOIS os s | |
WHOWAS s os os | |
KILL s s | |
PING s os | |
PONG s os | |
ERROR s | |
AWAY os | |
REHASH | |
DIE | |
RESTART | |
SUMMON s os os | |
USERS os | |
WALLOPS s | |
USERHOST vs | |
ISON vs | |
SAJOIN s s | |
SAMODE s s os | |
SANICK s s | |
SAPART s s | |
SAQUIT s s | |
NICKSERV s | |
CHANSERV s | |
OPERSERV s | |
BOTSERV s | |
HOSTSERV s | |
MEMOSERV s | |
CAP os CapSubCommand os os | |
AUTHENTICATE s | |
ACCOUNT s | |
METADATA s Option<MetadataSubCommand> ovs os | |
MONITOR s os | |
BATCH s Option<BatchSubCommand> ovs | |
CHGHOST s s | |
Response Response vs os | |
Raw s vs os | |
"#; | |
for line in spec.lines() { | |
do_line(line); | |
} | |
} | |
fn do_line(line: &str) { | |
let tok = line.trim().split(' ').collect::<Vec<&str>>(); | |
if tok.len() == 1 { | |
println!("{},", tok[0]); | |
} else if tok.len() > 1 { | |
println!("{}(Ros<'a, ({}), ({})>),", | |
tok[0], | |
tok.iter().skip(1).map(|&tok| match tok { | |
"s" => "Range<usize>", | |
"os" => "Option<Range<usize>>", | |
"vs" => "Vec<Range<usize>>", | |
"ovs" => "Option<Vec<Range<usize>>>", | |
_ => tok | |
}).collect::<Vec<&str>>().join(", "), | |
tok.iter().skip(1).map(|&tok| match tok { | |
"s" => "Cow<'a, str>", | |
"os" => "Option<Cow<'a, str>>", | |
"vs" => "Vec<Cow<'a, str>>", | |
"ovs" => "Option<Vec<Cow<'a, str>>>", | |
_ => tok | |
}).collect::<Vec<&str>>().join(", ")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment