Before

…lines 1–513 unchanged (513 lines)
514
515/**
516Locates a manifest embedded in Rust source.
517
518Returns `Some((manifest, source))` if it finds a manifest, `None` otherwise.
519*/
520fn find_embedded_manifest(s: &str) -> Option<(Manifest, &str)> {
521 find_short_comment_manifest(s).or_else(|| find_code_block_manifest(s))
522}
523
524#[test]
525fn test_find_embedded_manifest() {
526 use self::Manifest::*;
…lines 527–725 unchanged (199 lines)
726 );
727}
728
729/**
730Locates a "short comment manifest" in Rust source.
731*/
732fn find_short_comment_manifest(s: &str) -> Option<(Manifest, &str)> {
733 let re: Regex = Regex::new(r"^(?i)\s*//\s*cargo-deps\s*:(.*?)(\r\n|\n)").unwrap();
734 /*
735 This is pretty simple: the only valid syntax for this is for the first, non-blank line to contain a single-line comment whose first token is `cargo-deps:`. That's it.
736 */
737 if let Some(cap) = re.captures(s) {
738 if let Some(m) = cap.get(1) {
739 return Some((Manifest::DepList(m.as_str()), s));
740 }
741 }
742 None
743}
744
745/**
746Locates a "code block manifest" in Rust source.
747*/
748fn find_code_block_manifest(s: &str) -> Option<(Manifest, &str)> {
749 let re_crate_comment: Regex = {
750 Regex::new(
751 r"(?x)
752 # 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).
753 ^\s*
754 (/\*!|//(!|/))
…lines 755–1361 unchanged (607 lines)

After

…lines 1–513 unchanged (513 lines)
514
515/**
516Locates a manifest embedded in Rust source.
517
518Returns `Some((manifest, source))` if it finds a manifest, `None` otherwise.
519*/
520fn find_embedded_manifest(s: &str) -> Option<(Manifest<'_>, &str)> {
521 find_short_comment_manifest(s).or_else(|| find_code_block_manifest(s))
522}
523
524#[test]
525fn test_find_embedded_manifest() {
526 use self::Manifest::*;
…lines 527–725 unchanged (199 lines)
726 );
727}
728
729/**
730Locates a "short comment manifest" in Rust source.
731*/
732fn find_short_comment_manifest(s: &str) -> Option<(Manifest<'_>, &str)> {
733 let re: Regex = Regex::new(r"^(?i)\s*//\s*cargo-deps\s*:(.*?)(\r\n|\n)").unwrap();
734 /*
735 This is pretty simple: the only valid syntax for this is for the first, non-blank line to contain a single-line comment whose first token is `cargo-deps:`. That's it.
736 */
737 if let Some(cap) = re.captures(s) {
738 if let Some(m) = cap.get(1) {
739 return Some((Manifest::DepList(m.as_str()), s));
740 }
741 }
742 None
743}
744
745/**
746Locates a "code block manifest" in Rust source.
747*/
748fn find_code_block_manifest(s: &str) -> Option<(Manifest<'_>, &str)> {
749 let re_crate_comment: Regex = {
750 Regex::new(
751 r"(?x)
752 # 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).
753 ^\s*
754 (/\*!|//(!|/))
…lines 755–1361 unchanged (607 lines)

Before

source_file
block_comment
/* "/*"
inner_doc_comment_marker "!"
doc_comment "\nThis module is concerned with how `rust-script` extracts th"...
*/ "*/"
use_declaration
use "use"
scoped_identifier
identifier "pulldown_cmark"
:: "::"
identifier "TagEnd"
; ";"
use_declaration
use "use"
identifier "regex"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
self "self"
:: "::"
identifier "regex"
:: "::"
identifier "Regex"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "collections"
:: "::"
identifier "HashMap"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "path"
:: "::"
identifier "Path"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "path"
:: "::"
identifier "PathBuf"
; ";"
use_declaration
use "use"
scoped_identifier
crate "crate"
:: "::"
identifier "consts"
; ";"
use_declaration
use "use"
scoped_use_list
scoped_identifier
crate "crate"
:: "::"
identifier "error"
:: "::"
use_list
{ "{"
identifier "MainError"
, ","
identifier "MainResult"
} "}"
; ";"
use_declaration
use "use"
scoped_identifier
crate "crate"
:: "::"
identifier "templates"
; ";"
use_declaration
use "use"
scoped_identifier
crate "crate"
:: "::"
identifier "Input"
; ";"
use_declaration
use "use"
scoped_use_list
identifier "log"
:: "::"
use_list
{ "{"
identifier "error"
, ","
identifier "info"
} "}"
; ";"
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nSplits input into a complete Cargo manifest and unadultered"...
*/ "*/"
attribute_item
# "#"
[ "["
attribute
identifier "allow"
token_tree
( "("
identifier "clippy"
:: "::"
identifier "too_many_arguments"
) ")"
] "]"
function_item (+902 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "cfg"
token_tree
( "("
identifier "test"
) ")"
] "]"
const_item
visibility_modifier
pub "pub"
const "const"
identifier "STRIP_SECTION"
: ":"
reference_type
& "&"
primitive_type "str"
= "="
raw_string_literal
string_content "[profile.release]\nstrip = true\n"
; ";"
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+781 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nReturns a slice of the input string with the leading sheban"...
*/ "*/"
function_item (+89 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nRepresents the kind, and content of, an embedded manifest.\n"
*/ "*/"
attribute_item
# "#"
[ "["
attribute
identifier "derive"
token_tree
( "("
identifier "Debug"
, ","
identifier "Eq"
, ","
identifier "PartialEq"
) ")"
] "]"
enum_item (+61 nodes collapsed)
impl_item (+364 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nLocates a manifest embedded in Rust source.\n\nReturns `Some("...
*/ "*/"
function_item
fn "fn"
identifier "find_embedded_manifest"
parameters
( "("
parameter
identifier "s"
: ":"
reference_type
& "&"
primitive_type "str"
) ")"
-> "->"
generic_type
type_identifier "Option"
type_arguments
< "<"
tuple_type
( "("
type_identifier "Manifest"
, ","
reference_type
& "&"
primitive_type "str"
) ")"
> ">"
block (+26 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+492 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nLocates a \"short comment manifest\" in Rust source.\n"
*/ "*/"
function_item
fn "fn"
identifier "find_short_comment_manifest"
parameters
( "("
parameter
identifier "s"
: ":"
reference_type
& "&"
primitive_type "str"
) ")"
-> "->"
generic_type
type_identifier "Option"
type_arguments
< "<"
tuple_type
( "("
type_identifier "Manifest"
, ","
reference_type
& "&"
primitive_type "str"
) ")"
> ">"
block (+107 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nLocates a \"code block manifest\" in Rust source.\n"
*/ "*/"
function_item
fn "fn"
identifier "find_code_block_manifest"
parameters
( "("
parameter
identifier "s"
: ":"
reference_type
& "&"
primitive_type "str"
) ")"
-> "->"
generic_type
type_identifier "Option"
type_arguments
< "<"
tuple_type
( "("
type_identifier "Manifest"
, ","
reference_type
& "&"
primitive_type "str"
) ")"
> ">"
block (+206 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nExtracts the first `Cargo` fenced code block from a chunk o"...
*/ "*/"
function_item (+251 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+148 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nExtracts the contents of a Rust doc comment.\n"
*/ "*/"
function_item (+1213 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+157 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGenerates a default Cargo manifest for the given input.\n"
*/ "*/"
function_item (+809 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGenerates a partial Cargo manifest containing the specified"...
*/ "*/"
function_item (+257 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGiven two Cargo manifests, merges the second *into* the fir"...
*/ "*/"
function_item (+308 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGiven a Cargo manifest, attempts to rewrite relative file p"...
*/ "*/"
function_item (+365 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nIterates over the specified TOML values via a path specific"...
*/ "*/"
function_item (+259 nodes collapsed)

After

source_file
block_comment
/* "/*"
inner_doc_comment_marker "!"
doc_comment "\nThis module is concerned with how `rust-script` extracts th"...
*/ "*/"
use_declaration
use "use"
scoped_identifier
identifier "pulldown_cmark"
:: "::"
identifier "TagEnd"
; ";"
use_declaration
use "use"
identifier "regex"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
self "self"
:: "::"
identifier "regex"
:: "::"
identifier "Regex"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "collections"
:: "::"
identifier "HashMap"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "path"
:: "::"
identifier "Path"
; ";"
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "path"
:: "::"
identifier "PathBuf"
; ";"
use_declaration
use "use"
scoped_identifier
crate "crate"
:: "::"
identifier "consts"
; ";"
use_declaration
use "use"
scoped_use_list
scoped_identifier
crate "crate"
:: "::"
identifier "error"
:: "::"
use_list
{ "{"
identifier "MainError"
, ","
identifier "MainResult"
} "}"
; ";"
use_declaration
use "use"
scoped_identifier
crate "crate"
:: "::"
identifier "templates"
; ";"
use_declaration
use "use"
scoped_identifier
crate "crate"
:: "::"
identifier "Input"
; ";"
use_declaration
use "use"
scoped_use_list
identifier "log"
:: "::"
use_list
{ "{"
identifier "error"
, ","
identifier "info"
} "}"
; ";"
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nSplits input into a complete Cargo manifest and unadultered"...
*/ "*/"
attribute_item
# "#"
[ "["
attribute
identifier "allow"
token_tree
( "("
identifier "clippy"
:: "::"
identifier "too_many_arguments"
) ")"
] "]"
function_item (+902 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "cfg"
token_tree
( "("
identifier "test"
) ")"
] "]"
const_item
visibility_modifier
pub "pub"
const "const"
identifier "STRIP_SECTION"
: ":"
reference_type
& "&"
primitive_type "str"
= "="
raw_string_literal
string_content "[profile.release]\nstrip = true\n"
; ";"
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+781 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nReturns a slice of the input string with the leading sheban"...
*/ "*/"
function_item (+89 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nRepresents the kind, and content of, an embedded manifest.\n"
*/ "*/"
attribute_item
# "#"
[ "["
attribute
identifier "derive"
token_tree
( "("
identifier "Debug"
, ","
identifier "Eq"
, ","
identifier "PartialEq"
) ")"
] "]"
enum_item (+61 nodes collapsed)
impl_item (+364 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nLocates a manifest embedded in Rust source.\n\nReturns `Some("...
*/ "*/"
function_item
fn "fn"
identifier "find_embedded_manifest"
parameters
( "("
parameter
identifier "s"
: ":"
reference_type
& "&"
primitive_type "str"
) ")"
-> "->"
generic_type
type_identifier "Option"
type_arguments
< "<"
tuple_type
( "("
generic_type
type_identifier "Manifest"
type_arguments
< "<"
lifetime
' "'"
identifier "_"
> ">"
, ","
reference_type
& "&"
primitive_type "str"
) ")"
> ">"
block (+26 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+492 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nLocates a \"short comment manifest\" in Rust source.\n"
*/ "*/"
function_item
fn "fn"
identifier "find_short_comment_manifest"
parameters
( "("
parameter
identifier "s"
: ":"
reference_type
& "&"
primitive_type "str"
) ")"
-> "->"
generic_type
type_identifier "Option"
type_arguments
< "<"
tuple_type
( "("
generic_type
type_identifier "Manifest"
type_arguments
< "<"
lifetime
' "'"
identifier "_"
> ">"
, ","
reference_type
& "&"
primitive_type "str"
) ")"
> ">"
block (+107 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nLocates a \"code block manifest\" in Rust source.\n"
*/ "*/"
function_item
fn "fn"
identifier "find_code_block_manifest"
parameters
( "("
parameter
identifier "s"
: ":"
reference_type
& "&"
primitive_type "str"
) ")"
-> "->"
generic_type
type_identifier "Option"
type_arguments
< "<"
tuple_type
( "("
generic_type
type_identifier "Manifest"
type_arguments
< "<"
lifetime
' "'"
identifier "_"
> ">"
, ","
reference_type
& "&"
primitive_type "str"
) ")"
> ">"
block (+206 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nExtracts the first `Cargo` fenced code block from a chunk o"...
*/ "*/"
function_item (+251 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+148 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nExtracts the contents of a Rust doc comment.\n"
*/ "*/"
function_item (+1213 nodes collapsed)
attribute_item
# "#"
[ "["
attribute
identifier "test"
] "]"
function_item (+157 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGenerates a default Cargo manifest for the given input.\n"
*/ "*/"
function_item (+809 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGenerates a partial Cargo manifest containing the specified"...
*/ "*/"
function_item (+257 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGiven two Cargo manifests, merges the second *into* the fir"...
*/ "*/"
function_item (+308 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nGiven a Cargo manifest, attempts to rewrite relative file p"...
*/ "*/"
function_item (+365 nodes collapsed)
block_comment
/* "/*"
outer_doc_comment_marker "*"
doc_comment "\nIterates over the specified TOML values via a path specific"...
*/ "*/"
function_item (+259 nodes collapsed)