diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-03 06:41:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-03 06:41:33 +0100 |
| commit | 04478298032e1d1be14f5656c38448e274b6bef6 (patch) | |
| tree | 466904966ec2f39f6d8f819b1e42198f965af347 | |
| parent | daf59857d6d2b87af4b846316bf1561a6083ed51 (diff) | |
| parent | 797ef6455e782ec0ec4b6dd725c8ec70746e3e2d (diff) | |
| download | rust-04478298032e1d1be14f5656c38448e274b6bef6.tar.gz rust-04478298032e1d1be14f5656c38448e274b6bef6.zip | |
Rollup merge of #137103 - yotamofek:pr/jsonhtmldocck-deprecated-syntax, r=aDotInTheVoid
{json|html}docck: catch and error on deprecated syntax
https://github.com/rust-lang/rust/pull/137099#pullrequestreview-2619498733
| -rwxr-xr-x | src/etc/htmldocck.py | 14 | ||||
| -rw-r--r-- | src/tools/jsondocck/src/main.rs | 43 |
2 files changed, 42 insertions, 15 deletions
diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index d6b594aca71..06fc6518e3b 100755 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -297,10 +297,24 @@ LINE_PATTERN = re.compile( re.X | re.UNICODE, ) +DEPRECATED_LINE_PATTERN = re.compile( + r""" + //\s+@ +""", + re.X | re.UNICODE, +) + def get_commands(template): with io.open(template, encoding="utf-8") as f: for lineno, line in concat_multi_lines(f): + if DEPRECATED_LINE_PATTERN.search(line): + print_err( + lineno, + line, + "Deprecated command syntax, replace `// @` with `//@ `", + ) + continue m = LINE_PATTERN.search(line) if not m: continue diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index 7bfa7e3355d..54249fbd9ae 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; use std::process::ExitCode; -use std::sync::OnceLock; +use std::sync::LazyLock; use std::{env, fs}; use regex::{Regex, RegexBuilder}; @@ -151,8 +151,7 @@ impl CommandKind { } } -static LINE_PATTERN: OnceLock<Regex> = OnceLock::new(); -fn line_pattern() -> Regex { +static LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| { RegexBuilder::new( r#" //@\s+ @@ -165,7 +164,19 @@ fn line_pattern() -> Regex { .unicode(true) .build() .unwrap() -} +}); + +static DEPRECATED_LINE_PATTERN: LazyLock<Regex> = LazyLock::new(|| { + RegexBuilder::new( + r#" + //\s+@ + "#, + ) + .ignore_whitespace(true) + .unicode(true) + .build() + .unwrap() +}); fn print_err(msg: &str, lineno: usize) { eprintln!("Invalid command: {} on line {}", msg, lineno) @@ -184,21 +195,23 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> { for (lineno, line) in file.split('\n').enumerate() { let lineno = lineno + 1; - let cap = match LINE_PATTERN.get_or_init(line_pattern).captures(line) { - Some(c) => c, - None => continue, + if DEPRECATED_LINE_PATTERN.is_match(line) { + print_err("Deprecated command syntax, replace `// @` with `//@ `", lineno); + errors = true; + continue; + } + + let Some(cap) = LINE_PATTERN.captures(line) else { + continue; }; - let negated = cap.name("negated").unwrap().as_str() == "!"; + let negated = &cap["negated"] == "!"; let args_str = &cap["args"]; - let args = match shlex::split(args_str) { - Some(args) => args, - None => { - print_err(&format!("Invalid arguments to shlex::split: `{args_str}`",), lineno); - errors = true; - continue; - } + let Some(args) = shlex::split(args_str) else { + print_err(&format!("Invalid arguments to shlex::split: `{args_str}`",), lineno); + errors = true; + continue; }; if let Some((kind, path)) = CommandKind::parse(&cap["cmd"], negated, &args) { |
