From 7fa1a10c7851796fa3de1fba02c72af04a75ff0e Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sun, 3 Mar 2024 16:05:31 -0800 Subject: [PATCH] fix(parse): stop constructors from being picked up as invokables --- typegen/src/parse.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/typegen/src/parse.rs b/typegen/src/parse.rs index b166cba..aac0983 100644 --- a/typegen/src/parse.rs +++ b/typegen/src/parse.rs @@ -105,6 +105,7 @@ pub struct Parser { pub property_regex: Regex, pub signals_regex: Regex, pub fn_regex: Regex, + pub signal_regex: Regex, pub fn_param_regex: Regex, pub defaultprop_classinfo_regex: Regex, pub enum_regex: Regex, @@ -132,7 +133,8 @@ impl Parser { 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*(?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_regex: Regex::new(r#"(?(\s*\/\/\/.*\n)+)?\s*Q_INVOKABLE\s+(?(\w|::|<|>)+\*?)\s+(?\w+)\((?[\s\S]*?)\);"#).unwrap(), + signal_regex: Regex::new(r#"(?(\s*\/\/\/.*\n)+)?\s*void\s+(?\w+)\((?[\s\S]*?)\);"#).unwrap(), fn_param_regex: Regex::new(r#"(const\s+)?(?(\w|::|<|>)+\*?)&?\s+(?\w+)(,|$)"#).unwrap(), signals_regex: Regex::new(r#"signals:(?(\s*(\s*///.*\s*)*void .*;)*)"#).unwrap(), defaultprop_classinfo_regex: Regex::new(r#"^\s*"DefaultProperty", "(?.+)"\s*$"#).unwrap(), @@ -174,9 +176,11 @@ impl Parser { (|| { match type_ { - "QSDOC_BASECLASS" => superclass = Some( - args.expect("QSDOC_BASECLASS must have the base class as an argument") - ), + "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" | "QSDOC_ELEMENT" => qml_name = Some(name), @@ -242,9 +246,6 @@ impl Parser { } for invokable in self.fn_regex.captures_iter(body) { - if invokable.name("invokable").is_none() { - continue; - } let comment = invokable.name("comment").map(|m| m.as_str()); let type_ = invokable.name("type").unwrap().as_str(); @@ -271,13 +272,12 @@ impl Parser { for signal_set in self.signals_regex.captures_iter(body) { let signals_body = signal_set.name("signals").unwrap().as_str(); - for signal in self.fn_regex.captures_iter(signals_body) { + for signal in self.signal_regex.captures_iter(signals_body) { if signal.name("invokable").is_some() { continue; } let comment = signal.name("comment").map(|m| m.as_str()); - let type_ = signal.name("type").unwrap().as_str(); let name = signal.name("name").unwrap().as_str(); let params_raw = signal.name("params").unwrap().as_str(); @@ -285,10 +285,6 @@ impl Parser { continue; } - if type_ != "void" { - bail!("non void return for signal {name}"); - } - let mut params = Vec::new(); for param in self.fn_param_regex.captures_iter(params_raw) {