Skip to content

Commit a63c8c5

Browse files
committed
node_macro: cleanup attr parsing
1 parent 2d11d96 commit a63c8c5

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

node-graph/node-macro/src/parsing.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ impl Parse for NodeFnAttributes {
191191

192192
let nested = content.call(Punctuated::<Meta, Comma>::parse_terminated)?;
193193
for meta in nested {
194-
match meta {
195-
Meta::List(meta) if meta.path.is_ident("category") => {
194+
let name = meta.path().get_ident().ok_or_else(|| Error::new_spanned(meta.path(), "Node macro expects a known Ident, not a path"))?;
195+
match name.to_string().as_str() {
196+
"category" => {
197+
let meta = meta.require_list()?;
196198
if category.is_some() {
197199
return Err(Error::new_spanned(meta, "Multiple 'category' attributes are not allowed"));
198200
}
@@ -201,14 +203,16 @@ impl Parse for NodeFnAttributes {
201203
.map_err(|_| Error::new_spanned(meta, "Expected a string literal for 'category', e.g., category(\"Value\")"))?;
202204
category = Some(lit);
203205
}
204-
Meta::List(meta) if meta.path.is_ident("name") => {
206+
"name" => {
207+
let meta = meta.require_list()?;
205208
if display_name.is_some() {
206209
return Err(Error::new_spanned(meta, "Multiple 'name' attributes are not allowed"));
207210
}
208211
let parsed_name: LitStr = meta.parse_args().map_err(|_| Error::new_spanned(meta, "Expected a string for 'name', e.g., name(\"Memoize\")"))?;
209212
display_name = Some(parsed_name);
210213
}
211-
Meta::List(meta) if meta.path.is_ident("path") => {
214+
"path" => {
215+
let meta = meta.require_list()?;
212216
if path.is_some() {
213217
return Err(Error::new_spanned(meta, "Multiple 'path' attributes are not allowed"));
214218
}
@@ -217,13 +221,15 @@ impl Parse for NodeFnAttributes {
217221
.map_err(|_| Error::new_spanned(meta, "Expected a valid path for 'path', e.g., path(crate::MemoizeNode)"))?;
218222
path = Some(parsed_path);
219223
}
220-
Meta::Path(path) if path.is_ident("skip_impl") => {
224+
"skip_impl" => {
225+
let path = meta.require_path_only()?;
221226
if skip_impl {
222227
return Err(Error::new_spanned(path, "Multiple 'skip_impl' attributes are not allowed"));
223228
}
224229
skip_impl = true;
225230
}
226-
Meta::List(meta) if meta.path.is_ident("properties") => {
231+
"properties" => {
232+
let meta = meta.require_list()?;
227233
if properties_string.is_some() {
228234
return Err(Error::new_spanned(path, "Multiple 'properties_string' attributes are not allowed"));
229235
}
@@ -239,7 +245,7 @@ impl Parse for NodeFnAttributes {
239245
indoc!(
240246
r#"
241247
Unsupported attribute in `node`.
242-
Supported attributes are 'category', 'path' and 'name'.
248+
Supported attributes are 'category', 'path' 'name', 'skip_impl' and 'properties'.
243249
244250
Example usage:
245251
#[node_macro::node(category("Value"), name("Test Node"))]

0 commit comments

Comments
 (0)