diff --git a/Cargo.toml b/Cargo.toml index 6079de9..03aad73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ quote = "1" proc-macro2 = "1" proc-macro-error = "1" itertools = "0.10" -syn = "1" +syn = "2.0.1" include_dir = "0.7" [dev-dependencies] pretty_assertions = "1" diff --git a/src/attrs.rs b/src/attrs.rs index fb8fdcd..c768d2e 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -40,7 +40,7 @@ pub enum Attr { impl Attr { pub fn as_ident(&self) -> Option<&Ident> { match self { - Attr::Forward(attr) => attr.path.get_ident(), + Attr::Forward(attr) => attr.path().get_ident(), Attr::DocComment(ident, _) => Some(ident), Attr::DiagramStart(ident) => Some(ident), Attr::DiagramEntry(ident, _) => Some(ident), @@ -85,15 +85,17 @@ impl quote::ToTokens for Attrs { match attr { Attr::Forward(attr) => { // check if filepath is supplied - if attr.path.is_ident("path") { - for token in attr.tokens.to_token_stream().into_iter() { - if let proc_macro2::TokenTree::Literal(value) = token { - let data = - std::fs::read_to_string(value.to_string().replace("\"", "")) - .expect("Unable to read mermaid file"); - loaded_from_file = Some(generate_diagram_rustdoc( - vec![data.as_str()].into_iter(), - )); + if attr.path().is_ident("path") { + if let syn::Meta::List(ref ml) = attr.meta { + for token in ml.tokens.to_token_stream().into_iter() { + if let proc_macro2::TokenTree::Literal(value) = token { + let data = + std::fs::read_to_string(value.to_string().replace("\"", "")) + .expect("Unable to read mermaid file"); + loaded_from_file = Some(generate_diagram_rustdoc( + vec![data.as_str()].into_iter(), + )); + } } } } @@ -234,16 +236,17 @@ fn generate_diagram_rustdoc<'a>(parts: impl Iterator) -> TokenStre impl Attrs { pub fn push_attrs(&mut self, attrs: Vec) { use syn::Lit::*; - use syn::Meta::*; + use syn::Expr; + use syn::ExprLit; let mut current_location = Location::OutsideDiagram; let mut diagram_start_ident = None; for attr in attrs { - match &attr.parse_meta() { - Ok(NameValue(MetaNameValue { - lit: Str(s), path, .. - })) if path.is_ident("doc") => { + match attr.meta.require_name_value() { + Ok(MetaNameValue { + value: Expr::Lit(ExprLit {lit: Str(s), .. }), path, .. + }) if path.is_ident("doc") => { let ident = path.get_ident().unwrap(); for attr in split_attr_body(ident, &s.value(), &mut current_location) { if attr.is_diagram_start() { diff --git a/src/lib.rs b/src/lib.rs index 22ac959..415eb07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,7 +99,7 @@ pub fn aquamarine(_args: TokenStream, input: TokenStream) -> TokenStream { fn check_input_attrs(input: &[Attribute]) { for attr in input { - if attr.path.is_ident("aquamarine") { + if attr.path().is_ident("aquamarine") { abort!( attr, "multiple `aquamarine` attributes on one entity are illegal"