@@ -86,55 +86,58 @@ pub fn generate_branchified_method(
86
86
valid : & str ,
87
87
unknown : & str ) {
88
88
89
- // Write Formatted
90
- macro_rules! wf( ( $( $x: tt) * ) => ( {
91
- let s = fmt!( $( $x) * ) ;
92
- writer. write( indentstr. as_bytes( ) ) ;
93
- writer. write( s. as_bytes( ) ) ;
94
- writer. write( bytes!( "\n " ) ) ;
95
- } ) )
96
-
97
89
fn r ( writer : @Writer , branch : & ParseBranch , prefix : & str , indent : uint , read_call : & str ,
98
90
end : & str , max_len : & str , valid : & str , unknown : & str ) {
99
91
let indentstr = " " . repeat ( indent * 4 ) ;
92
+ let w = |s : & str | {
93
+ writer. write ( indentstr. as_bytes ( ) ) ;
94
+ writer. write ( s. as_bytes ( ) ) ;
95
+ writer. write ( bytes ! ( "\n " ) ) ;
96
+ } ;
100
97
for & c in branch. matches . iter ( ) {
101
98
let next_prefix = fmt ! ( "%s%c" , prefix, c as char ) ;
102
- wf ! ( "Some(b) if b == '%c' as u8 => match %s {" , c as char , read_call) ;
99
+ w ( fmt ! ( "Some(b) if b == '%c' as u8 => match %s {" , c as char , read_call) ) ;
103
100
for b in branch. children . iter ( ) {
104
101
r ( writer, b, next_prefix, indent + 1 , read_call, end, max_len, valid, unknown) ;
105
102
}
106
103
match branch. result {
107
- Some ( ref result) => wf ! ( " Some(b) if b == SP => return Some(%s)," , * result) ,
108
- None => wf ! ( " Some(b) if b == SP => return Some(%s)," ,
109
- unknown. replace( "%s" , fmt!( "~\" %s\" " , next_prefix) ) ) ,
104
+ Some ( ref result) => w ( fmt ! ( " Some(b) if b == SP => return Some(%s)," , * result) ) ,
105
+ None => w ( fmt ! ( " Some(b) if b == SP => return Some(%s)," ,
106
+ unknown. replace( "%s" , fmt!( "~\" %s\" " , next_prefix) ) ) ) ,
110
107
}
111
- wf ! ( " Some(b) if %s => (\" %s\" , b)," , valid, next_prefix) ;
112
- wf ! ( " _ => return None," ) ;
113
- wf ! ( "}," ) ;
108
+ w ( fmt ! ( " Some(b) if %s => (\" %s\" , b)," , valid, next_prefix) ) ;
109
+ w ( fmt ! ( " _ => return None," ) ) ;
110
+ w ( fmt ! ( "}," ) ) ;
114
111
}
115
112
}
116
113
let indentstr = " " . repeat ( indent * 4 ) ;
117
- wf ! ( "let (s, next_byte) = match %s {" , read_call) ;
114
+ let w = |s : & str | {
115
+ writer. write ( indentstr. as_bytes ( ) ) ;
116
+ writer. write ( s. as_bytes ( ) ) ;
117
+ writer. write ( bytes ! ( "\n " ) ) ;
118
+ } ;
119
+
120
+ w ( fmt ! ( "let (s, next_byte) = match %s {" , read_call) ) ;
118
121
for b in branches. iter ( ) {
119
122
r ( writer, b, "" , indent + 1 , read_call, end, max_len, valid, unknown) ;
120
123
}
121
- wf ! ( " Some(b) if %s => (\" \" , b)," , valid) ;
122
- wf ! ( " _ => return None," ) ;
123
- wf ! ( "};" ) ;
124
- wf ! ( "// OK, that didn't pan out. Let's read the rest and see what we get." ) ;
125
- wf ! ( "let mut s = s.to_owned();" ) ;
126
- wf ! ( "s.push_char(next_byte as char);" ) ;
127
- wf ! ( "loop {" ) ;
128
- wf ! ( " match %s {" , read_call) ;
129
- wf ! ( " Some(b) if b == %s => return Some(%s)," , end, unknown. replace( "%s" , "s" ) ) ;
130
- wf ! ( " Some(b) if %s => {" , valid) ;
131
- wf ! ( " if s.len() == %s {" , max_len) ;
132
- wf ! ( " // Too long; bad request" ) ;
133
- wf ! ( " return None;" ) ;
134
- wf ! ( " }" ) ;
135
- wf ! ( " s.push_char(b as char);" ) ;
136
- wf ! ( " }," ) ;
137
- wf ! ( " _ => return None," ) ;
138
- wf ! ( " }" ) ;
139
- wf ! ( "}" ) ;
124
+ w ( fmt ! ( " Some(b) if %s => (\" \" , b)," , valid) ) ;
125
+ w ( fmt ! ( " _ => return None," ) ) ;
126
+ w ( fmt ! ( "};" ) ) ;
127
+ w ( fmt ! ( "// OK, that didn't pan out. Let's read the rest and see what we get." ) ) ;
128
+ w ( fmt ! ( "let mut s = s.to_owned();" ) ) ;
129
+ w ( fmt ! ( "s.push_char(next_byte as char);" ) ) ;
130
+ w ( fmt ! ( "loop {" ) ) ;
131
+ w ( fmt ! ( " match %s {" , read_call) ) ;
132
+ w ( fmt ! ( " Some(b) if b == %s => return Some(%s)," , end, unknown. replace( "%s" , "s" ) ) ) ;
133
+ w ( fmt ! ( " Some(b) if %s => {" , valid) ) ;
134
+ w ( fmt ! ( " if s.len() == %s {" , max_len) ) ;
135
+ w ( fmt ! ( " // Too long; bad request" ) ) ;
136
+ w ( fmt ! ( " return None;" ) ) ;
137
+ w ( fmt ! ( " }" ) ) ;
138
+ w ( fmt ! ( " s.push_char(b as char);" ) ) ;
139
+ w ( fmt ! ( " }," ) ) ;
140
+ w ( fmt ! ( " _ => return None," ) ) ;
141
+ w ( fmt ! ( " }" ) ) ;
142
+ w ( fmt ! ( "}" ) ) ;
140
143
}
0 commit comments