Skip to content

Commit 043581a

Browse files
committed
Support /// comments (fixes #25)
1 parent 86a3ea7 commit 043581a

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-script"
3-
version = "0.14.0"
3+
version = "0.15.0"
44
edition = "2018"
55
authors = ["Fredrik Fornwall <fredrik@fornwall.net>"]
66
description = "Command-line tool to run Rust \"scripts\" which can make use of crates."

src/manifest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ lazy_static! {
2020
static ref RE_MARGIN: Regex = Regex::new(r"^\s*\*( |$)").unwrap();
2121
static ref RE_SPACE: Regex = Regex::new(r"^(\s+)").unwrap();
2222
static ref RE_NESTING: Regex = Regex::new(r"/\*|\*/").unwrap();
23-
static ref RE_COMMENT: Regex = Regex::new(r"^\s*//!").unwrap();
23+
static ref RE_COMMENT: Regex = Regex::new(r"^\s*//(!|/)").unwrap();
2424
static ref RE_SHEBANG: Regex = Regex::new(r"^#![^\[].*?(\r\n|\n)").unwrap();
2525
static ref RE_CRATE_COMMENT: Regex = {
2626
Regex::new(
2727
r"(?x)
2828
# We need to find the first `/*!` or `//!` that *isn't* preceeded by something that would make it apply to anything other than the crate itself. Because we can't do this accurately, we'll just require that the doc comment is the *first* thing in the file (after the optional shebang, which should already have been stripped).
2929
^\s*
30-
(/\*!|//!)
30+
(/\*!|//(!|/))
3131
"
3232
).unwrap()
3333
};
@@ -938,7 +938,7 @@ fn extract_comment(s: &str) -> MainResult<String> {
938938

939939
if let Some(stripped) = s.strip_prefix("/*!") {
940940
extract_block(stripped)
941-
} else if s.starts_with("//!") {
941+
} else if s.starts_with("//!") || s.starts_with("///") {
942942
extract_line(s)
943943
} else {
944944
Err("no doc comment found".into())

tests/data/outer-line-doc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// ```cargo
2+
/// [dependencies]
3+
/// boolinator = "=0.1.0"
4+
/// ```
5+
use boolinator::Boolinator;
6+
7+
pub fn main() {
8+
println!("--output--");
9+
println!("{:?}", true.as_some(1));
10+
}

tests/tests/script.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ fn test_pub_fn_main() {
171171
.unwrap()
172172
}
173173

174+
#[test]
175+
fn test_outer_line_doc() {
176+
let out = rust_script!("tests/data/outer-line-doc.rs").unwrap();
177+
scan!(out.stdout_output();
178+
("Some(1)") => ()
179+
)
180+
.unwrap()
181+
}
182+
174183
#[test]
175184
fn test_whitespace_before_main() {
176185
let out = rust_script!("tests/data/whitespace-before-main.rs").unwrap();

0 commit comments

Comments
 (0)