diff --git a/typegen/Cargo.lock b/typegen/Cargo.lock index b3ff41c..e8c09ba 100644 --- a/typegen/Cargo.lock +++ b/typegen/Cargo.lock @@ -1,48 +1,48 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "bit-set" -version = "0.5.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" dependencies = [ "bit-vec", ] [[package]] name = "bit-vec" -version = "0.6.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fancy-regex" -version = "0.13.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531e46835a22af56d1e3b66f04844bed63158bc094a628bec1d321d9b4c44bf2" +checksum = "72cf461f865c862bb7dc573f643dd6a2b6842f7c30b07882b56bd148cc2761b8" dependencies = [ "bit-set", "regex-automata", @@ -51,15 +51,15 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "indexmap" -version = "2.2.2" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", @@ -67,39 +67,39 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" dependencies = [ "proc-macro2", ] [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -108,15 +108,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "ryu" -version = "1.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "same-file" @@ -129,18 +123,28 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.196" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -149,29 +153,31 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", - "ryu", + "memchr", "serde", + "serde_core", + "zmij", ] [[package]] name = "serde_spanned" -version = "0.6.5" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" dependencies = [ - "serde", + "serde_core", ] [[package]] name = "syn" -version = "2.0.48" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -180,38 +186,43 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.10" +version = "0.9.11+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" +checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46" dependencies = [ - "serde", + "indexmap", + "serde_core", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_parser", + "toml_writer", + "winnow", ] [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.7.5+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" dependencies = [ - "serde", + "serde_core", ] [[package]] -name = "toml_edit" -version = "0.22.4" +name = "toml_parser" +version = "1.0.6+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9ffdf896f8daaabf9b66ba8e77ea1ed5ed0f72821b398aba62352e95062951" +checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44" dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", "winnow", ] +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + [[package]] name = "typegen" version = "0.1.0" @@ -226,9 +237,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "walkdir" @@ -242,91 +253,36 @@ dependencies = [ [[package]] name = "winapi-util" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ "windows-sys", ] [[package]] -name = "windows-sys" -version = "0.59.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows-targets" -version = "0.52.6" +name = "windows-sys" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-link", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "winnow" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" [[package]] -name = "winnow" -version = "0.5.37" +name = "zmij" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5" -dependencies = [ - "memchr", -] +checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" diff --git a/typegen/Cargo.toml b/typegen/Cargo.toml index f66e24b..f41c207 100644 --- a/typegen/Cargo.toml +++ b/typegen/Cargo.toml @@ -5,8 +5,8 @@ edition = "2021" [dependencies] anyhow = "^1" -fancy-regex = "^0.13" +fancy-regex = "^0.17" serde = { version = "^1", features = ["derive"] } serde_json = "^1" -toml = "^0.8" -walkdir = "2.5.0" +toml = "^0.9" +walkdir = "^2.5" diff --git a/typegen/src/main.rs b/typegen/src/main.rs index e33b625..29c3f6e 100644 --- a/typegen/src/main.rs +++ b/typegen/src/main.rs @@ -1,7 +1,4 @@ -use std::{ - collections::HashMap, - path::{Path, PathBuf}, -}; +use std::{collections::HashMap, path::Path}; use anyhow::{anyhow, Context}; use walkdir::WalkDir; @@ -140,23 +137,17 @@ fn gentypes(modinfo: &str, outpath: &str) -> anyhow::Result<()> { let qml_parser = parse::QmlParser::new(); let mut ctx = parse::ParseContext::new(&module.header.name); - texts - .iter() - .map(|(header, text)| { - header_parser - .parse(&text, &mut ctx) - .with_context(|| format!("while parsing module header `{header}`")) - }) - .collect::>()?; + texts.iter().try_for_each(|(header, text)| { + header_parser + .parse(text, &mut ctx) + .with_context(|| format!("while parsing module header `{header}`")) + })?; - qml_texts - .iter() - .map(|(file, text)| { - qml_parser - .parse(&file, &text, &mut ctx) - .with_context(|| format!("while parsing module qml file `{file}`")) - }) - .collect::>()?; + qml_texts.iter().try_for_each(|(file, text)| { + qml_parser + .parse(file, text, &mut ctx) + .with_context(|| format!("while parsing module qml file `{file}`")) + })?; let typespec = ctx.gen_typespec(&module.header.name); @@ -178,7 +169,7 @@ fn gendocs( for path in typepaths { let text = - std::fs::read_to_string(&path).with_context(|| anyhow!("attempting to read {path}"))?; + std::fs::read_to_string(path).with_context(|| anyhow!("attempting to read {path}"))?; let ts = serde_json::from_str::(&text) .with_context(|| anyhow!("attempting to parse {path}"))?; @@ -239,7 +230,7 @@ hidetitle = true name = module.header.name ); - let templatepath = templatepath.join(format!("_index.md")); + let templatepath = templatepath.join("_index.md"); std::fs::write(&templatepath, template) .with_context(|| format!("while writing {templatepath:?}")) } diff --git a/typegen/src/parse.rs b/typegen/src/parse.rs index a0f34ba..99bd58f 100644 --- a/typegen/src/parse.rs +++ b/typegen/src/parse.rs @@ -25,7 +25,7 @@ pub struct ModuleInfo<'a> { pub details: &'a str, } -pub fn parse_module(text: &str) -> anyhow::Result { +pub fn parse_module(text: &str) -> anyhow::Result> { let Some((mut header, mut details)) = text.split_once("-----") else { bail!("could not split module header"); }; @@ -217,7 +217,7 @@ impl CppParser { let comment = macro_ .name("comment") .map(|m| m.as_str()) - .or(carryover.as_ref().map(|c| c.comment).flatten()); + .or(carryover.as_ref().and_then(|c| c.comment)); let type_ = macro_.name("type").unwrap().as_str(); let args = macro_.name("args").map(|m| m.as_str()); @@ -275,8 +275,7 @@ impl CppParser { type_: Cow::Borrowed( this_carryover .as_ref() - .map(|c| c.type_override) - .flatten() + .and_then(|c| c.type_override) .unwrap_or_else(|| prop.name("type").unwrap().as_str()), ), name: prop.name("name").unwrap().as_str(), @@ -411,7 +410,7 @@ impl CppParser { type_, name, qml_name, - superclass: superclass.map(|s| Cow::Borrowed(s)), + superclass: superclass.map(Cow::Borrowed), singleton, uncreatable: uncreatable && !force_creatable, comment: comment.map(|v| Comment::new(v, ctx.module)), @@ -447,16 +446,13 @@ impl CppParser { let args = macro_.name("args").map(|m| m.as_str()); (|| { - match type_ { - "Q_DECLARE_FLAGS" => { - enum_name = args - .expect("Q_DECLARE_FLAGS must have arguments") - .split_once(',') - .expect("Q_DECLARE_FLAGS must have two arguments") - .0 - .trim(); - }, - _ => {}, + if type_ == "Q_DECLARE_FLAGS" { + enum_name = args + .expect("Q_DECLARE_FLAGS must have arguments") + .split_once(',') + .expect("Q_DECLARE_FLAGS must have two arguments") + .0 + .trim(); } Ok::<_, anyhow::Error>(()) @@ -784,7 +780,7 @@ fn parse_details(comment: Comment) -> String { seen_content |= any; filter }) - .fold(String::new(), |accum, line| accum + line.as_ref() + "\n"); + .fold(String::new(), |accum, line| accum + line + "\n"); let reformat_ctx = reformat::Context { module: comment.module, diff --git a/typegen/src/reformat.rs b/typegen/src/reformat.rs index 984eca4..55e70b3 100644 --- a/typegen/src/reformat.rs +++ b/typegen/src/reformat.rs @@ -38,7 +38,7 @@ impl ReformatPass for TypeLinks { fn reformat(&self, context: &Context, text: &mut String) { let lines = text.lines().map(|line| { if line.contains("@@") { - let mut src: &str = &*line; + let mut src: &str = line; let mut accum = String::new(); while let Some(i) = src.find("@@") { @@ -62,7 +62,7 @@ impl ReformatPass for TypeLinks { .find(|(sc, _)| char == *sc) .map(|(_, strip)| (i + if *strip { 1 } else { 0 }, &src[..i])) }) - .unwrap_or_else(|| (src.len(), src)); + .unwrap_or((src.len(), src)); // special case for . as it is contained in valid types as well if ty.ends_with('.') { @@ -76,18 +76,15 @@ impl ReformatPass for TypeLinks { Some(_) => { let mut split = ty.rsplit_once('.').unwrap_or(("", ty)); - let member = split - .1 - .chars() - .next() - .unwrap() - .is_lowercase() - .then(|| { + let member = if split.1.chars().next().unwrap().is_lowercase() { + { let prop = split.1; split = split.0.rsplit_once('.').unwrap_or(("", split.0)); prop - }) - .unwrap_or(""); + } + } else { + "" + }; let (mut module, name) = split; @@ -132,9 +129,9 @@ impl ReformatPass for TypeLinks { accum += src; - return Cow::Owned(accum); + Cow::Owned(accum) } else { - return Cow::Borrowed(line); + Cow::Borrowed(line) } }); diff --git a/typegen/src/resolver.rs b/typegen/src/resolver.rs index d5c0734..bcf28ff 100644 --- a/typegen/src/resolver.rs +++ b/typegen/src/resolver.rs @@ -123,7 +123,7 @@ pub fn resolve_types( match qtype { Some((module, name)) => { - let mut t = outform::Type::resolve(module.as_ref().map(|v| v as &str), &name); + let mut t = outform::Type::resolve(module.as_ref().map(|v| v as &str), name); t.of = of; t }, diff --git a/typegen/src/typespec.rs b/typegen/src/typespec.rs index 481829e..0cd4859 100644 --- a/typegen/src/typespec.rs +++ b/typegen/src/typespec.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Default)] pub struct TypeSpec { pub typemap: Vec, pub classes: Vec, @@ -8,17 +8,6 @@ pub struct TypeSpec { pub enums: Vec, } -impl Default for TypeSpec { - fn default() -> Self { - Self { - typemap: Vec::new(), - classes: Vec::new(), - gadgets: Vec::new(), - enums: Vec::new(), - } - } -} - #[derive(Debug, Serialize, Deserialize)] pub struct QmlTypeMapping { pub name: String,