Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ proc-macro = true
[dependencies]
syn = { version = "2.0.100", features = ["full", "extra-traits", "printing"] }
darling = "0.20"
ident_case = "1.0.1"
quote = "1.0.9"
proc-macro2 = "1.0.26"
lazy_static = "1.4.0"
anyhow = "1.0"
convert_case = "0.8.0"

[lints.rust]
missing_docs = "warn"
8 changes: 5 additions & 3 deletions crates/macros/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use quote::quote;
use syn::{Attribute, Expr, Fields, ItemStruct};

use crate::helpers::get_docs;
use crate::parsing::PhpRename;
use crate::parsing::{PhpRename, RenameRule};
use crate::prelude::*;

#[derive(FromAttributes, Debug, Default)]
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct ClassEntryAttribute {
pub fn parser(mut input: ItemStruct) -> Result<TokenStream> {
let attr = StructAttributes::from_attributes(&input.attrs)?;
let ident = &input.ident;
let name = attr.rename.rename(ident.to_string());
let name = attr.rename.rename(ident.to_string(), RenameRule::Pascal);
let docs = get_docs(&attr.attrs)?;
input.attrs.retain(|attr| !attr.path().is_ident("php"));

Expand Down Expand Up @@ -107,7 +107,9 @@ struct Property<'a> {

impl Property<'_> {
pub fn name(&self) -> String {
self.attr.rename.rename(self.ident.to_string())
self.attr
.rename
.rename(self.ident.to_string(), RenameRule::Camel)
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/macros/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use quote::{format_ident, quote};
use syn::ItemConst;

use crate::helpers::get_docs;
use crate::parsing::PhpRename;
use crate::parsing::{PhpRename, RenameRule};
use crate::prelude::*;

const INTERNAL_CONST_DOC_PREFIX: &str = "_internal_const_docs_";
Expand All @@ -23,7 +23,9 @@ pub(crate) struct PhpConstAttribute {
pub fn parser(mut item: ItemConst) -> Result<TokenStream> {
let attr = PhpConstAttribute::from_attributes(&item.attrs)?;

let name = attr.rename.rename(item.ident.to_string());
let name = attr
.rename
.rename(item.ident.to_string(), RenameRule::ScreamingSnake);
let name_ident = format_ident!("{INTERNAL_CONST_NAME_PREFIX}{}", item.ident);

let docs = get_docs(&attr.attrs)?;
Expand Down
6 changes: 4 additions & 2 deletions crates/macros/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use syn::spanned::Spanned as _;
use syn::{Expr, FnArg, GenericArgument, ItemFn, PatType, PathArguments, Type, TypePath};

use crate::helpers::get_docs;
use crate::parsing::{PhpRename, Visibility};
use crate::parsing::{PhpRename, RenameRule, Visibility};
use crate::prelude::*;
use crate::syn_ext::DropLifetimes;

Expand Down Expand Up @@ -46,7 +46,9 @@ pub fn parser(mut input: ItemFn) -> Result<TokenStream> {

let func = Function::new(
&input.sig,
php_attr.rename.rename(input.sig.ident.to_string()),
php_attr
.rename
.rename(input.sig.ident.to_string(), RenameRule::Snake),
args,
php_attr.optional,
docs,
Expand Down
15 changes: 8 additions & 7 deletions crates/macros/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use syn::{Expr, Ident, ItemImpl};
use crate::constant::PhpConstAttribute;
use crate::function::{Args, CallType, Function, MethodReceiver};
use crate::helpers::get_docs;
use crate::parsing::{MethodRename, PhpRename, Rename, RenameRule, Visibility};
use crate::parsing::{PhpRename, RenameRule, Visibility};
use crate::prelude::*;

/// Method types.
Expand Down Expand Up @@ -48,8 +48,7 @@ pub fn parser(mut input: ItemImpl) -> Result<TokenStream> {
let mut parsed = ParsedImpl::new(
path,
args.rename_methods.unwrap_or(RenameRule::Camel),
args.rename_constants
.unwrap_or(RenameRule::ScreamingSnakeCase),
args.rename_constants.unwrap_or(RenameRule::ScreamingSnake),
);
parsed.parse(input.items.iter_mut())?;

Expand Down Expand Up @@ -184,8 +183,9 @@ impl<'a> ParsedImpl<'a> {
match items {
syn::ImplItem::Const(c) => {
let attr = PhpConstAttribute::from_attributes(&c.attrs)?;
let name = c.ident.rename(self.rename_constants);
let name = attr.rename.rename(name);
let name = attr
.rename
.rename(c.ident.to_string(), self.rename_constants);
let docs = get_docs(&attr.attrs)?;
c.attrs.retain(|attr| !attr.path().is_ident("php"));

Expand All @@ -197,8 +197,9 @@ impl<'a> ParsedImpl<'a> {
}
syn::ImplItem::Fn(method) => {
let attr = PhpFunctionImplAttribute::from_attributes(&method.attrs)?;
let name = method.sig.ident.rename_method(self.rename_methods);
let name = attr.rename.rename(name);
let name = attr
.rename
.rename_method(method.sig.ident.to_string(), self.rename_methods);
let docs = get_docs(&attr.attrs)?;
method.attrs.retain(|attr| !attr.path().is_ident("php"));

Expand Down
Loading