From c116b5ed394aae66f7380f676ef16bac616b9326 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 23 Feb 2021 21:44:26 +0800 Subject: [PATCH] feat: add rust data type suppor --- plugins/coco_struct_analysis/src/ctags_parser.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/coco_struct_analysis/src/ctags_parser.rs b/plugins/coco_struct_analysis/src/ctags_parser.rs index c0c14370..32f76148 100644 --- a/plugins/coco_struct_analysis/src/ctags_parser.rs +++ b/plugins/coco_struct_analysis/src/ctags_parser.rs @@ -44,6 +44,10 @@ lazy_static! { static ref RE_LANGUAGE: Regex = Regex::new(r"language:(?P[A-Za-z0-9_\#]+)").unwrap(); static ref RE_TYPE: Regex = Regex::new(r"/\^([ ]*)(?P[A-Za-z0-9_.]+)([^A-Za-z0-9_]+)(.*)\$/").unwrap(); + static ref RUST_TYPE: Regex = Regex::new( + r"/\^([ ]*)([A-Za-z0-9_.]+)(\t|\s)([A-Za-z0-9_.]+)\s?:(\t|\s)?(?P[A-Za-z0-9_.<>]+)" + ) + .unwrap(); static ref TYPE_KEYWORDS: [&'static str; 18] = [ "private", "public", @@ -166,7 +170,11 @@ impl CtagsParser { data_type = (&capts["datatype"]).to_string(); } } - "Rust" => {} + "Rust" => { + if let Some(capts) = RUST_TYPE.captures(line) { + data_type = (&capts["datatype"]).to_string(); + } + } _ => {} } @@ -286,8 +294,8 @@ name src/coco_struct.rs /^ pub name: String,$/;\" field line:22 language:Rust let parser = CtagsParser::parse_str(lines); let classes = parser.classes(); - print!("{:?}", classes); assert_eq!(1, classes.len()); + assert_eq!("String", classes[0].members[0].data_type); } #[test]