Thu, 26 Feb 2026 11:36:22 -0500
Subproblem solver and sliding adjustments/improvements
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
1 | use regex::{Captures, Regex}; |
|
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | use std::env; |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
4 | fn main() { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
5 | process_readme(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
6 | // Does not seem to be needed now. |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
7 | //discover_gsl(); |
|
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | } |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
10 | /* |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
11 | /// Discover how to link to gsl, as the gsl crate does not provide this information |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
12 | fn discover_gsl() { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
13 | pkg_config::Config::new().probe("gsl").unwrap(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
14 | } |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
15 | */ |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
16 | |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
17 | /// `\`-escape `_`, `*`, and ยด\\` in matches of `re` within `str`. |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
18 | fn proc<A: AsRef<str>>(re: &str, str: A) -> String { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
19 | let need_to_escape = Regex::new(r"([_*\\])").unwrap(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
20 | Regex::new(re) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
21 | .unwrap() |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
22 | .replace_all(str.as_ref(), |caps: &Captures| { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
23 | format!( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
24 | "{}{}{}", |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
25 | caps.get(1).unwrap().as_str(), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
26 | need_to_escape.replace_all(caps.get(2).unwrap().as_str(), "\\$1"), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
27 | caps.get(3).unwrap().as_str() |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
28 | ) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
29 | }) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
30 | .to_string() |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
31 | } |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
32 | |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
33 | /// Process the README for inclusion in documentation |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
34 | fn process_readme() { |
|
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | let out_dir = env::var("OUT_DIR").unwrap(); |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
36 | |
|
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | // Since rust is stuck in 80's 7-bit gringo ASCII world, so that rustdoc does not support |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | // markdown KaTeX mathematics, we have to process the README to include horrible horrible |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | // horrible escapes for the math, and then use an vomit-inducingly ugly javasccript |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | // workaround to process the math on the fly. |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | println!("cargo:rerun-if-changed=README.md"); |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
44 | let readme = std::fs::read_to_string("README.md").expect("Error reading README"); |
|
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | // Escape _, *, and \ in equations. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
47 | let readme_uglified = proc( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
48 | r"(?m)([^$]\$)([^$]+)(\$[^$])", |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
49 | proc(r"([^$]\$\$)([^$]+)(\$\$[^$])", readme), |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
6
diff
changeset
|
50 | ); |
|
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
51 | // Remove the instructions for building the documentation |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
52 | let readme_cut = Regex::new("## Internals(.*|\n)*") |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | .unwrap() |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | .replace_all(&readme_uglified, ""); |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
55 | |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | std::fs::write(out_dir + "/README_uglified.md", readme_cut.as_bytes()) |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | .expect("Error saving uglified README"); |
|
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | } |