I know there should be some good crate for merging doc metas, but.. syn take about 2x compile time the main program takes.. Thus I decided not to use either syn or proc-macro2.
... and the code now seems to be ugly.
fn parse_doc(meta:&mut String, prev_is_sharp: &mut bool, x:TokenTree){
// status: ..@.. @ means I'm here.
if *prev_is_sharp { // status: # @..
*prev_is_sharp = false;
// check whether the current token is `[...]`
let Group (x) = x else { return };
if x.delimiter() != Delimiter::Bracket { return }
// status: # @[...]
let stream = x.stream().into_iter().collect::<Vec<_>>();
// status: # @[stream]
if stream.len()<3 { return } // cannot satisfy doc = literal
let Ident(ref ident) = stream[0] else { return };
if ident.to_string() != "doc" { return }
// status: # @[doc stream[1..]]
let Punct(ref ch) = stream[1] else { return };
if ch.as_char() != '=' { return }
// status: # @[doc = stream[2..]]
let Literal(ref lit) = stream[2] else { return };
meta.push(format!("\n#' {lit}"));
} else if let Punct(x) = x {
if x.as_char()=='#' {
*prev_is_sharp = true;
}
}
}
There are too many let Pat(x) = y else { return }
in the program, is there a better way avoid writting so much return?