Skip to content

Update all our crates #2235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 110 additions & 100 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ name = "remove_markup"
path = "tools/src/bin/remove_markup.rs"

[dependencies]
walkdir = "0.1.5"
docopt = "0.6.82"
rustc-serialize = "0.3.19"
regex = "0.1.73"
lazy_static = "0.2.1"
flate2 = "1.0"
tar = "0.4.16"
walkdir = "2.3.1"
docopt = "1.1.0"
serde = "1.0"
regex = "1.3.3"
lazy_static = "1.4.0"
flate2 = "1.0.13"
tar = "0.4.26"
2 changes: 1 addition & 1 deletion tools/src/bin/concat_chapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn match_files(
regex.replace_all(source_filename, replacement);
let source_path = entry.path();
let mut target_path = PathBuf::from(&target_dir);
target_path.push(target_filename);
target_path.push(target_filename.to_string());
return Some((source_path, target_path));
}
}
Expand Down
9 changes: 3 additions & 6 deletions tools/src/bin/lfp.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// We have some long regex literals, so:
// ignore-tidy-linelength

extern crate docopt;
extern crate rustc_serialize;
extern crate walkdir;

use docopt::Docopt;
use serde::Deserialize;
use std::io::BufRead;
use std::{fs, io, path};

fn main() {
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.decode())
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());

let src_dir = &path::Path::new(&args.arg_src_dir);
Expand Down Expand Up @@ -69,7 +66,7 @@ Options:
-h --help Show this screen.
";

#[derive(Debug, RustcDecodable)]
#[derive(Debug, Deserialize)]
struct Args {
arg_src_dir: String,
}
Expand Down
24 changes: 12 additions & 12 deletions tools/src/bin/link2print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,48 @@ fn parse_references(buffer: String) -> (String, HashMap<String, String>) {
let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###)
.unwrap();
let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
let key = caps.at(1).unwrap().to_owned().to_uppercase();
let val = caps.at(2).unwrap().to_owned();
let key = caps.get(1).unwrap().as_str().to_uppercase();
let val = caps.get(2).unwrap().as_str().to_string();
if ref_map.insert(key, val).is_some() {
panic!("Did not expect markdown page to have duplicate reference");
}
"".to_string()
});
}).to_string();
(output, ref_map)
}

fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
// FIXME: check which punctuation is allowed by spec.
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
let re = Regex::new(r###"(?:(?P<pre>(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^\[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P<name>[^]]+)\](?:(?:\([[:blank:]]*(?P<val>[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P<key>[^]]*)\]))?))"###).expect("could not create regex");
let error_code =
Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
match caps.name("pre") {
Some(pre_section) => format!("{}", pre_section.to_owned()),
Some(pre_section) => format!("{}", pre_section.as_str()),
None => {
let name = caps.name("name").expect("could not get name").to_owned();
let name = caps.name("name").expect("could not get name").as_str();
// Really we should ignore text inside code blocks,
// this is a hack to not try to treat `#[derive()]`,
// `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
if name.starts_with("derive(") ||
name.starts_with("profile") ||
name.starts_with("test") ||
name.starts_with("no_mangle") ||
error_code.is_match(&name) {
return name
error_code.is_match(name) {
return name.to_string()
}

let val = match caps.name("val") {
// `[name](link)`
Some(value) => value.to_owned(),
Some(value) => value.as_str().to_string(),
None => {
match caps.name("key") {
Some(key) => {
match key {
match key.as_str() {
// `[name][]`
"" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
// `[name][reference]`
_ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
_ => format!("{}", ref_map.get(&key.as_str().to_uppercase()).expect(&format!("could not find url for the link text `{}`", key.as_str()))),
}
}
// `[name]` as reference
Expand All @@ -81,7 +81,7 @@ fn parse_links((buffer, ref_map): (String, HashMap<String, String>)) -> String {
}
}
});
output
output.to_string()
}

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions tools/src/bin/remove_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ fn main() {
let link_regex = Regex::new(regex).unwrap();
let first_pass = link_regex.replace_all(&buffer, |caps: &Captures<'_>| {
// Save the link reference we want to delete.
if let Some(reference) = caps.at(2) {
refs.insert(reference.to_owned());
if let Some(reference) = caps.get(2) {
refs.insert(reference.as_str().to_string());
}

// Put the link title back.
caps.at(1).unwrap().to_owned()
caps.get(1).unwrap().as_str().to_string()
});

// Search for the references we need to delete.
let ref_regex = Regex::new(r"(?m)^\[([^\]]+)\]:\s.*\n").unwrap();
let out = ref_regex.replace_all(&first_pass, |caps: &Captures<'_>| {
let capture = caps.at(1).unwrap().to_owned();
let capture = caps.get(1).unwrap().to_owned();

// Check if we've marked this reference for deletion ...
if refs.contains(capture.as_str()) {
return "".to_string();
}

// ... else we put back everything we captured.
caps.at(0).unwrap().to_owned()
caps.get(0).unwrap().as_str().to_string()
});

write!(io::stdout(), "{}", out).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tools/src/bin/remove_markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn remove_markup(input: String) -> String {
let result =
regexen.iter().fold(line.to_string(), |result, regex| {
regex.replace_all(&result, |caps: &Captures<'_>| {
caps.at(1).unwrap().to_owned()
})
caps.get(1).unwrap().as_str().to_string()
}).to_string()
});
Some(result)
}
Expand Down