1
Fork 0

syntax_ext: format: separate verification and translation of pieces

This commit is contained in:
Wang Xuerui 2016-06-05 18:01:37 +08:00
parent 06b034ae8b
commit 0e2a96321a
No known key found for this signature in database
GPG key ID: 78396CEF692310EC

View file

@ -651,21 +651,27 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
};
let mut parser = parse::Parser::new(&fmt);
let mut pieces = vec![];
loop {
match parser.next() {
Some(piece) => {
if !parser.errors.is_empty() { break }
cx.verify_piece(&piece);
if let Some(piece) = cx.trans_piece(&piece) {
let s = cx.trans_literal_string();
cx.str_pieces.push(s);
cx.pieces.push(piece);
}
pieces.push(piece);
}
None => break
}
}
for piece in pieces {
if let Some(piece) = cx.trans_piece(&piece) {
let s = cx.trans_literal_string();
cx.str_pieces.push(s);
cx.pieces.push(piece);
}
}
if !parser.errors.is_empty() {
cx.ecx.span_err(cx.fmtsp, &format!("invalid format string: {}",
parser.errors.remove(0)));