From cc201afd3a352a28f5daddbe00d7aed974d52d30 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Mon, 26 Feb 2024 00:20:17 -0800 Subject: [PATCH] feat: macros to manipulate doc generation --- typegen/src/parse.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/typegen/src/parse.rs b/typegen/src/parse.rs index 05c5662..03124ea 100644 --- a/typegen/src/parse.rs +++ b/typegen/src/parse.rs @@ -130,7 +130,7 @@ impl Parser { pub fn new() -> Self { Self { class_regex: Regex::new(r#"(?(\s*\/\/\/.*\n)+)?\s*class\s+(?\w+)(?:\s*:\s*public\s+(?\w+)(\s*,(\s*\w+)*)*)?\s*\{(?[\s\S]*?)};"#).unwrap(), - macro_regex: Regex::new(r#"(?(\s*\/\/\/.*\n)+)?\s*(?(Q|QML)_\w+)\s*(\(\s*(?.*)\s*\))?;"#).unwrap(), + macro_regex: Regex::new(r#"(?(\s*\/\/\/.*\n)+)?\s*(?QSDOC_HIDE\s)?(?(Q|QML|QSDOC)_\w+)\s*(\(\s*(?.*)\s*\))?;"#).unwrap(), property_regex: Regex::new(r#"^\s*(?(\w|::|<|>)+\*?)\s+(?\w+)(\s+(MEMBER\s+(?\w+)|READ\s+(?\w+)|WRITE\s+(?\w+)|NOTIFY\s+(?\w+)|(?CONSTANT)))+\s*$"#).unwrap(), fn_regex: Regex::new(r#"(?(\s*\/\/\/.*\n)+)?\s*(?Q_INVOKABLE)?\s+(?(\w|::|<|>)+\*?)\s+(?\w+)\((?[\s\S]*?)\);"#).unwrap(), fn_param_regex: Regex::new(r#"(?(\w|::|<|>)+\*?)\s+(?\w+)(,|$)"#).unwrap(), @@ -149,7 +149,7 @@ impl Parser { for class in self.class_regex.captures_iter(text) { let comment = class.name("comment").map(|m| m.as_str()); let name = class.name("name").unwrap().as_str(); - let superclass = class.name("super").map(|m| m.as_str()); + let mut superclass = class.name("super").map(|m| m.as_str()); let body = class.name("body").unwrap().as_str(); let mut classtype = None; @@ -164,16 +164,23 @@ impl Parser { (|| { for macro_ in self.macro_regex.captures_iter(body) { + if macro_.name("hide").is_some() { + continue + } + let comment = macro_.name("comment").map(|m| m.as_str()); let type_ = macro_.name("type").unwrap().as_str(); let args = macro_.name("args").map(|m| m.as_str()); (|| { match type_ { + "QSDOC_BASECLASS" => superclass = Some( + args.expect("QSDOC_BASECLASS must have the base class as an argument") + ), "Q_OBJECT" => classtype = Some(ClassType::Object), "Q_GADGET" => classtype = Some(ClassType::Gadget), - "QML_ELEMENT" => qml_name = Some(name), - "QML_NAMED_ELEMENT" => { + "QML_ELEMENT" | "QSDOC_ELEMENT" => qml_name = Some(name), + "QML_NAMED_ELEMENT" | "QSDOC_NAMED_ELEMENT" => { qml_name = Some(args.ok_or_else(|| { anyhow!("expected name for QML_NAMED_ELEMENT") })?)