|
@@ -1,14 +1,17 @@
|
|
use crate::{get_node_meta_items, get_pb_meta_items, parse_lit_into_expr_path, symbol::*, ASTAttr, ASTResult};
|
|
use crate::{get_node_meta_items, get_pb_meta_items, parse_lit_into_expr_path, symbol::*, ASTAttr, ASTResult};
|
|
-use proc_macro2::{Group, Span, TokenStream, TokenTree};
|
|
|
|
|
|
+use proc_macro2::{Group, Ident, Span, TokenStream, TokenTree};
|
|
use quote::ToTokens;
|
|
use quote::ToTokens;
|
|
use syn::{
|
|
use syn::{
|
|
self,
|
|
self,
|
|
parse::{self, Parse},
|
|
parse::{self, Parse},
|
|
|
|
+ LitStr,
|
|
Meta::{List, NameValue, Path},
|
|
Meta::{List, NameValue, Path},
|
|
NestedMeta::{Lit, Meta},
|
|
NestedMeta::{Lit, Meta},
|
|
};
|
|
};
|
|
|
|
|
|
pub struct NodeStructAttrs {
|
|
pub struct NodeStructAttrs {
|
|
|
|
+ pub rename: Option<LitStr>,
|
|
|
|
+ pub is_children: bool,
|
|
node_index: Option<syn::LitInt>,
|
|
node_index: Option<syn::LitInt>,
|
|
get_node_value_with: Option<syn::ExprPath>,
|
|
get_node_value_with: Option<syn::ExprPath>,
|
|
set_node_value_with: Option<syn::ExprPath>,
|
|
set_node_value_with: Option<syn::ExprPath>,
|
|
@@ -18,14 +21,11 @@ impl NodeStructAttrs {
|
|
/// Extract out the `#[node(...)]` attributes from a struct field.
|
|
/// Extract out the `#[node(...)]` attributes from a struct field.
|
|
pub fn from_ast(ast_result: &ASTResult, index: usize, field: &syn::Field) -> Self {
|
|
pub fn from_ast(ast_result: &ASTResult, index: usize, field: &syn::Field) -> Self {
|
|
let mut node_index = ASTAttr::none(ast_result, NODE_INDEX);
|
|
let mut node_index = ASTAttr::none(ast_result, NODE_INDEX);
|
|
|
|
+ let mut rename = ASTAttr::none(ast_result, NODE_RENAME);
|
|
|
|
+ let mut is_children = ASTAttr::none(ast_result, NODE_CHILDREN);
|
|
let mut get_node_value_with = ASTAttr::none(ast_result, GET_NODE_VALUE_WITH);
|
|
let mut get_node_value_with = ASTAttr::none(ast_result, GET_NODE_VALUE_WITH);
|
|
let mut set_node_value_with = ASTAttr::none(ast_result, SET_NODE_VALUE_WITH);
|
|
let mut set_node_value_with = ASTAttr::none(ast_result, SET_NODE_VALUE_WITH);
|
|
|
|
|
|
- let ident = match &field.ident {
|
|
|
|
- Some(ident) => ident.to_string(),
|
|
|
|
- None => index.to_string(),
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
for meta_item in field
|
|
for meta_item in field
|
|
.attrs
|
|
.attrs
|
|
.iter()
|
|
.iter()
|
|
@@ -40,6 +40,18 @@ impl NodeStructAttrs {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Parse '#[node(children)]'
|
|
|
|
+ Meta(Path(path)) if path == NODE_CHILDREN => {
|
|
|
|
+ eprintln!("😄 {:?}", path);
|
|
|
|
+ is_children.set(path, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Parse '#[node(rename = x)]'
|
|
|
|
+ Meta(NameValue(m)) if m.path == NODE_RENAME => {
|
|
|
|
+ if let syn::Lit::Str(lit) = &m.lit {
|
|
|
|
+ rename.set(&m.path, lit.clone());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// Parse `#[node(get_node_value_with = "...")]`
|
|
// Parse `#[node(get_node_value_with = "...")]`
|
|
Meta(NameValue(m)) if m.path == GET_NODE_VALUE_WITH => {
|
|
Meta(NameValue(m)) if m.path == GET_NODE_VALUE_WITH => {
|
|
if let Ok(path) = parse_lit_into_expr_path(ast_result, GET_NODE_VALUE_WITH, &m.lit) {
|
|
if let Ok(path) = parse_lit_into_expr_path(ast_result, GET_NODE_VALUE_WITH, &m.lit) {
|
|
@@ -66,7 +78,9 @@ impl NodeStructAttrs {
|
|
}
|
|
}
|
|
|
|
|
|
NodeStructAttrs {
|
|
NodeStructAttrs {
|
|
|
|
+ rename: rename.get(),
|
|
node_index: node_index.get(),
|
|
node_index: node_index.get(),
|
|
|
|
+ is_children: is_children.get().unwrap_or(false),
|
|
get_node_value_with: get_node_value_with.get(),
|
|
get_node_value_with: get_node_value_with.get(),
|
|
set_node_value_with: set_node_value_with.get(),
|
|
set_node_value_with: set_node_value_with.get(),
|
|
}
|
|
}
|