From 7614b96fe45240dafe91ae549e712b560e2d4c10 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 31 Dec 2022 14:45:13 +0100 Subject: RTIC v2: Initial commit rtic-syntax is now part of RTIC repository --- macros/src/syntax/parse/monotonic.rs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 macros/src/syntax/parse/monotonic.rs (limited to 'macros/src/syntax/parse/monotonic.rs') diff --git a/macros/src/syntax/parse/monotonic.rs b/macros/src/syntax/parse/monotonic.rs new file mode 100644 index 0000000..0583233 --- /dev/null +++ b/macros/src/syntax/parse/monotonic.rs @@ -0,0 +1,42 @@ +use proc_macro2::Span; +use syn::Attribute; +use syn::{parse, spanned::Spanned, ItemType, Visibility}; + +use crate::syntax::parse::util::FilterAttrs; +use crate::syntax::{ + ast::{Monotonic, MonotonicArgs}, + parse::util, +}; + +impl MonotonicArgs { + pub(crate) fn parse(attr: Attribute) -> parse::Result { + crate::syntax::parse::monotonic_args(attr.path, attr.tokens) + } +} + +impl Monotonic { + pub(crate) fn parse(args: MonotonicArgs, item: &ItemType, span: Span) -> parse::Result { + if item.vis != Visibility::Inherited { + return Err(parse::Error::new( + span, + "this field must have inherited / private visibility", + )); + } + + let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs.clone()); + + if !attrs.is_empty() { + return Err(parse::Error::new( + attrs[0].path.span(), + "Monotonic does not support attributes other than `#[cfg]`", + )); + } + + Ok(Monotonic { + cfgs, + ident: item.ident.clone(), + ty: item.ty.clone(), + args, + }) + } +} -- cgit v1.2.3