Skip to content

Commit

Permalink
Make procedural-masquerade resilient to macro input pretty-printing c…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jun 20, 2020
1 parent 7c9854e commit 2976bf4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion procedural-masquerade/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "procedural-masquerade"
version = "0.1.6"
version = "0.1.7"
authors = ["Simon Sapin <simon.sapin@exyr.org>"]
description = "macro_rules for making proc_macro_derive pretending to be proc_macro"
documentation = "https://docs.rs/procedural-masquerade/"
Expand Down
19 changes: 14 additions & 5 deletions procedural-masquerade/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,23 @@ pub fn _extract_input(derive_input: &str) -> &str {
let mut input = derive_input;

for expected in &[
"#[allow(unused)]",
"#",
"[",
"allow",
"(",
"unused",
")",
"]",
"enum",
"ProceduralMasqueradeDummyType",
"{",
"Input",
"=",
"(0,",
"stringify!",
"(",
"0",
",",
"stringify",
"!",
"(",
] {
input = input.trim_start();
Expand All @@ -219,7 +228,7 @@ pub fn _extract_input(derive_input: &str) -> &str {
input = &input[expected.len()..];
}

for expected in [")", ").0,", "}"].iter().rev() {
for expected in [")", ")", ".", "0", ",", "}"].iter().rev() {
input = input.trim_end();
assert!(
input.ends_with(expected),
Expand Down Expand Up @@ -268,7 +277,7 @@ macro_rules! define_invoke_proc_macro {
// which is then ignored.
// Using `stringify!` enables passing arbitrary tokens
// rather than only what can be parsed as a const expression.
Input = (0, stringify! $paren ).0
Input = (0, stringify! $paren ).0,
}
}
}
Expand Down

0 comments on commit 2976bf4

Please sign in to comment.