From 8caead7505ba5bea54bf3067974d978ede135415 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sun, 21 Jul 2024 14:31:12 -0700 Subject: [PATCH] typegen: add more .,:; as reference shorthand separators --- typegen/src/parse.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/typegen/src/parse.rs b/typegen/src/parse.rs index d52a29f..515c9dd 100644 --- a/typegen/src/parse.rs +++ b/typegen/src/parse.rs @@ -647,13 +647,25 @@ fn parse_details(comment: Comment) -> String { accum += &src[..i]; src = &src[i + 2..]; - let endmk = src.find('$'); - let endsp = src.find(' '); + let separators = [ + ('$', true), + (' ', false), + ('.', false), + (',', false), + (';', false), + (':', false), + ]; - let (end, ty) = match (endmk, endsp) { - (Some(i), _) if i < endsp.unwrap_or(usize::MAX) => (i + 1, &src[..i]), - (_, Some(i)) => (i, &src[..i]), - _ => (src.len(), src), + let mut chars = src.chars().enumerate(); + let (end, ty) = loop { + match chars.next() { + Some((i, c)) => { + if let Some(strip) = separators.iter().filter(|(sc, _)| c == *sc).map(|(_, strip)| *strip).next() { + break (i + if strip { 1 } else { 0 }, &src[..i]); + } + }, + None => break (src.len(), src), + } }; let mut split = ty.rsplit_once('.').unwrap_or(("", ty));