Merge pull request #151 from seemk/latest_rust_fix

Build fix for latest Rust
This commit is contained in:
Tony Aldridge
2014-07-08 09:04:03 +01:00
4 changed files with 39 additions and 36 deletions
+2
View File
@@ -16,3 +16,5 @@ name = "demo"
path = "src/demo/main.rs"
[dev-dependencies.codegen]
path = "src/codegen"
+35 -34
View File
@@ -93,9 +93,8 @@ pub fn generate_branchified_method(
unknown: &str) {
// Write Formatted
macro_rules! wf(($($x:tt)*) => ({
let mut wf = |s: String| {
let indentstr = " ".repeat(indent * 4);
let s = format!($($x)*);
let result = writer.write(indentstr.as_bytes())
.and(writer.write(s.as_bytes()))
.and(writer.write(b"\n"));
@@ -104,47 +103,49 @@ pub fn generate_branchified_method(
Ok(_) => {},
Err(e) => fail!("write error: {:s}", e.desc),
}
}))
};
fn r(branch: &ParseBranch, prefix: &str, read_call: &str,
valid: &str, unknown: &str, write_fmt: &mut |String|) {
fn r(writer: &mut BufferedWriter<File>, branch: &ParseBranch, prefix: &str, indent: uint, read_call: &str,
end: &str, max_len: &str, valid: &str, unknown: &str) {
for &c in branch.matches.iter() {
let next_prefix = format!("{}{}", prefix, c as char);
wf!("Some(b) if b == '{}' as u8 => match {} {{", c as char, read_call);
(*write_fmt)(format!("Some(b) if b == '{}' as u8 => match {} {{", c as char, read_call));
for b in branch.children.iter() {
r(writer, b, next_prefix.as_slice(), indent + 1, read_call, end, max_len, valid, unknown);
r(b, next_prefix.as_slice(), read_call, valid, unknown, write_fmt);
}
match branch.result {
Some(ref result) => wf!(" Some(b) if b == SP => return Some({}),", *result),
None => wf!(" Some(b) if b == SP => return Some({}),",
unknown.replace("{}", format!("~\"{}\"", next_prefix.as_slice()).as_slice())),
Some(ref result) => (*write_fmt)(format!(" Some(b) if b == SP => return Some({}),", *result)),
None => (*write_fmt)(format!(" Some(b) if b == SP => return Some({}),",
unknown.replace("{}", format!("~\"{}\"", next_prefix.as_slice()).as_slice()))),
}
wf!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix.as_slice());
wf!(" _ => return None,");
wf!("}},");
(*write_fmt)(format!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix.as_slice()));
(*write_fmt)(format!(" _ => return None,"));
(*write_fmt)(format!("}},"));
}
}
wf!("let (s, next_byte) = match {} {{", read_call);
wf(format!("let (s, next_byte) = match {} {{", read_call));
for b in branches.iter() {
r(writer, b, "", indent + 1, read_call, end, max_len, valid, unknown);
r(b, "", read_call, valid, unknown, &mut wf);
}
wf!(" Some(b) if {} => (\"\", b),", valid);
wf!(" _ => return None,");
wf!("}};");
wf!("// OK, that didn't pan out. Let's read the rest and see what we get.");
wf!("let mut s = s.to_string();");
wf!("s.push_char(next_byte as char);");
wf!("loop {{");
wf!(" match {} {{", read_call);
wf!(" Some(b) if b == {} => return Some({}),", end, unknown.replace("{}", "s"));
wf!(" Some(b) if {} => {{", valid);
wf!(" if s.len() == {} {{", max_len);
wf!(" // Too long; bad request");
wf!(" return None;");
wf!(" }}");
wf!(" s.push_char(b as char);");
wf!(" }},");
wf!(" _ => return None,");
wf!(" }}");
wf!("}}");
wf(format!(" Some(b) if {} => (\"\", b),", valid));
wf(format!(" _ => return None,"));
wf(format!("}};"));
wf(format!("// OK, that didn't pan out. Let's read the rest and see what we get."));
wf(format!("let mut s = s.to_string();"));
wf(format!("s.push_char(next_byte as char);"));
wf(format!("loop {{"));
wf(format!(" match {} {{", read_call));
wf(format!(" Some(b) if b == {} => return Some({}),", end, unknown.replace("{}", "s")));
wf(format!(" Some(b) if {} => {{", valid));
wf(format!(" if s.len() == {} {{", max_len));
wf(format!(" // Too long; bad request"));
wf(format!(" return None;"));
wf(format!(" }}"));
wf(format!(" s.push_char(b as char);"));
wf(format!(" }},"));
wf(format!(" _ => return None,"));
wf(format!(" }}"));
wf(format!("}}"));
}
+1 -1
View File
@@ -1,5 +1,5 @@
#![feature(macro_rules)]
#![crate_id = "codegen#0.1"]
#![crate_name = "codegen"]
use std::os;
use std::io::BufferedWriter;
+1 -1
View File
@@ -1,4 +1,4 @@
#![crate_id="sdl2#0.0.1"]
#![crate_name = "sdl2"]
#![crate_type = "lib"]
#![desc = "SDL2 bindings"]