mirror of
https://github.com/uutils/uutils-args.git
synced 2026-06-10 16:13:08 -07:00
migrate to syn 2.0
This commit is contained in:
+1
-1
@@ -12,4 +12,4 @@ proc_macro = true
|
||||
proc-macro2 = "1.0.47"
|
||||
pulldown-cmark = "0.9.2"
|
||||
quote = "1.0.21"
|
||||
syn = { version = "1.0.103", features = ["full"] }
|
||||
syn = { version = "2.0.18 ", features = ["full"] }
|
||||
|
||||
+17
-9
@@ -2,7 +2,7 @@ use std::ops::RangeInclusive;
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{Attribute, Fields, FieldsUnnamed, Ident, Lit, Meta, Variant};
|
||||
use syn::{Attribute, Fields, FieldsUnnamed, Ident, Meta, Variant};
|
||||
|
||||
use crate::{
|
||||
attributes::{parse_argument_attribute, ArgAttr, ArgumentsAttr},
|
||||
@@ -31,7 +31,7 @@ pub(crate) enum ArgType {
|
||||
|
||||
pub(crate) fn parse_arguments_attr(attrs: &[Attribute]) -> ArgumentsAttr {
|
||||
for attr in attrs {
|
||||
if attr.path.is_ident("arguments") {
|
||||
if attr.path().is_ident("arguments") {
|
||||
return ArgumentsAttr::parse(attr);
|
||||
}
|
||||
}
|
||||
@@ -107,13 +107,21 @@ pub(crate) fn parse_argument(v: Variant) -> Vec<Argument> {
|
||||
fn collect_help(attrs: &[Attribute]) -> String {
|
||||
let mut help = Vec::new();
|
||||
for attr in attrs {
|
||||
let Ok(meta) = attr.parse_meta() else { continue; };
|
||||
let Meta::NameValue(name_value) = meta else { continue; };
|
||||
if !name_value.path.is_ident("doc") {
|
||||
continue;
|
||||
if attr.path().is_ident("doc") {
|
||||
let value = match &attr.meta {
|
||||
Meta::NameValue(name_value) => &name_value.value,
|
||||
_ => panic!("doc attribute must be a name and a value"),
|
||||
};
|
||||
let lit = match value {
|
||||
syn::Expr::Lit(expr_lit) => &expr_lit.lit,
|
||||
_ => panic!("argument to doc attribute must be a string literal"),
|
||||
};
|
||||
let litstr = match lit {
|
||||
syn::Lit::Str(litstr) => litstr,
|
||||
_ => panic!("argument to doc attribute must be a string literal"),
|
||||
};
|
||||
help.push(litstr.value().trim().to_string());
|
||||
}
|
||||
let Lit::Str(litstr) = name_value.lit else { continue; };
|
||||
help.push(litstr.value().trim().to_string())
|
||||
}
|
||||
help.join("\n")
|
||||
}
|
||||
@@ -121,7 +129,7 @@ fn collect_help(attrs: &[Attribute]) -> String {
|
||||
fn get_arg_attributes(attrs: &[Attribute]) -> Vec<ArgAttr> {
|
||||
attrs
|
||||
.iter()
|
||||
.filter(|a| a.path.is_ident("option") || a.path.is_ident("positional"))
|
||||
.filter(|a| a.path().is_ident("option") || a.path().is_ident("positional"))
|
||||
.map(parse_argument_attribute)
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ pub(crate) enum ArgAttr {
|
||||
}
|
||||
|
||||
pub(crate) fn parse_argument_attribute(attr: &Attribute) -> ArgAttr {
|
||||
if attr.path.is_ident("option") {
|
||||
if attr.path().is_ident("option") {
|
||||
ArgAttr::Option(OptionAttr::parse(attr))
|
||||
} else if attr.path.is_ident("positional") {
|
||||
} else if attr.path().is_ident("positional") {
|
||||
ArgAttr::Positional(PositionalAttr::parse(attr))
|
||||
} else {
|
||||
panic!("Internal error: invalid argument attribute");
|
||||
@@ -183,7 +183,7 @@ impl Parse for AttributeArguments {
|
||||
if (input.peek(LitInt) && input.peek2(Token![..])) || input.peek(Token![..]) {
|
||||
// We're dealing with a range
|
||||
let range = input.parse::<ExprRange>()?;
|
||||
let from = match range.from.as_deref() {
|
||||
let from = match range.start.as_deref() {
|
||||
Some(Expr::Lit(ExprLit {
|
||||
lit: Lit::Int(i), ..
|
||||
})) => i.base10_parse::<usize>().unwrap(),
|
||||
@@ -192,7 +192,7 @@ impl Parse for AttributeArguments {
|
||||
};
|
||||
|
||||
let inclusive = matches!(range.limits, RangeLimits::Closed(_));
|
||||
let to = match range.to.as_deref() {
|
||||
let to = match range.end.as_deref() {
|
||||
Some(Expr::Lit(ExprLit {
|
||||
lit: Lit::Int(i), ..
|
||||
})) => {
|
||||
|
||||
@@ -125,7 +125,7 @@ fn initial_struct(data: syn::DataStruct) -> proc_macro2::TokenStream {
|
||||
|
||||
fn parse_field_attr(attrs: &[Attribute]) -> InitialField {
|
||||
for attr in attrs {
|
||||
if attr.path.is_ident("initial") {
|
||||
if attr.path().is_ident("initial") {
|
||||
return InitialField::from_attribute(attr).expect("Failed to parse initial attribute");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ pub fn value(input: TokenStream) -> TokenStream {
|
||||
let variant_name = variant.ident.to_string();
|
||||
let attrs = variant.attrs.clone();
|
||||
for attr in attrs {
|
||||
if !attr.path.is_ident("value") {
|
||||
if !attr.path().is_ident("value") {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user