trixy 0.4.0

A rust crate used to generate multi-language apis for your application
Documentation
/*
* Copyright (C) 2023 - 2024:
* The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

use convert_case::{Case, Casing};
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;

use crate::parser::command_spec::{Identifier, Type, Variant};

mod doc_identifier;

impl Identifier {
    pub fn to_auxiliary_c(&self, generic_args: &[Type]) -> TokenStream2 {
        let ident = self.to_rust_pascalized();
        match &self.variant {
            Variant::Structure { .. } => {
                let ident = self.to_rust_pascalized();
                quote! {
                    struct #ident
                }
            }
            Variant::Enumeration { .. } => {
                quote! {
                    enum #ident
                }
            }
            Variant::Result { .. } | Variant::Option { .. } | Variant::Vec { .. } => {
                let ident = Type::mangle_name(&self, generic_args);
                quote! {
                    struct #ident
                }
            }

            Variant::Primitive => match self.name.to_case(Case::Snake).as_str() {
                "string" => {
                    quote! {
                        const char *
                    }
                }
                // Unsigned
                "u_8" => quote! { uint8_t },
                "u_16" => quote! { uint16_t },
                "u_32" => quote! { uint32_t },
                "u_64" => quote! { uint64_t },
                // Signed
                "i_8" => quote! { int8_t },
                "i_16" => quote! { int16_t },
                "i_32" => quote! { int32_t },
                "i_64" => quote! { int64_t },
                // Float
                "f_32" => quote! { float },
                "f_64" => quote! { double },

                // Others
                "void" => quote! { void },
                other => {
                    todo!("'{}' is not yet supported", other)
                }
            },

            Variant::Namespace
            | Variant::RootNamespace
            | Variant::Function
            | Variant::NamedType
            | Variant::DocNamedType
            | Variant::Void => unreachable!("None of these variants should ever be used here"),
        }
    }
}