forked from trinitrix/core
build(treewide): Move back to rust stable
This commit is contained in:
parent
181af51c08
commit
d7b93178e8
|
@ -158,7 +158,7 @@
|
||||||
overlays = [(import rust-overlay)];
|
overlays = [(import rust-overlay)];
|
||||||
};
|
};
|
||||||
|
|
||||||
nightly = true;
|
nightly = false;
|
||||||
rust =
|
rust =
|
||||||
if nightly
|
if nightly
|
||||||
then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)
|
then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
use syn::{braced, parse::Parse, punctuated::Punctuated, token, Attribute, Ident, Token, Type};
|
||||||
|
|
||||||
|
pub type NamespacePath = Punctuated<Ident, Token![::]>;
|
||||||
|
|
||||||
|
mod kw {
|
||||||
|
syn::custom_keyword!(commands);
|
||||||
|
syn::custom_keyword!(namespace);
|
||||||
|
syn::custom_keyword!(declare);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DataCommandEnum {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
commands_token: kw::commands,
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
brace_token: token::Brace,
|
||||||
|
|
||||||
|
pub fields: Punctuated<Field, Token![,]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Field {
|
||||||
|
Function(FunctionDeclaration),
|
||||||
|
Namespace(Namespace),
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Namespace {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
namespace_token: kw::namespace,
|
||||||
|
|
||||||
|
pub path: NamespacePath,
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
brace_token: token::Brace,
|
||||||
|
|
||||||
|
pub fields: Punctuated<Field, Token![,]>,
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct FunctionDeclaration {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
function_token: kw::declare,
|
||||||
|
|
||||||
|
pub name: Ident,
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
colon_token: Token![:],
|
||||||
|
|
||||||
|
pub ty: Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for DataCommandEnum {
|
||||||
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
|
let content;
|
||||||
|
Ok(DataCommandEnum {
|
||||||
|
commands_token: input.parse()?,
|
||||||
|
brace_token: braced!(content in input),
|
||||||
|
fields: content.parse_terminated(Field::parse, Token![,])?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Parse for Field {
|
||||||
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
|
let lookahead = input.lookahead1();
|
||||||
|
if input.peek(Token![#]) {
|
||||||
|
// FIXME(@soispha): We ignore doc comments, which should probably be replaced by adding
|
||||||
|
// them to the output <2023-09-19>
|
||||||
|
let _output = input.call(Attribute::parse_outer).unwrap_or(vec![]);
|
||||||
|
let lookahead = input.lookahead1();
|
||||||
|
|
||||||
|
if lookahead.peek(kw::namespace) {
|
||||||
|
input.parse().map(Field::Namespace)
|
||||||
|
} else if lookahead.peek(kw::declare) {
|
||||||
|
input.parse().map(Field::Function)
|
||||||
|
} else {
|
||||||
|
Err(lookahead.error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if lookahead.peek(kw::declare) {
|
||||||
|
input.parse().map(Field::Function)
|
||||||
|
} else if lookahead.peek(kw::namespace) {
|
||||||
|
input.parse().map(Field::Namespace)
|
||||||
|
} else {
|
||||||
|
Err(lookahead.error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for FunctionDeclaration {
|
||||||
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
|
Ok(FunctionDeclaration {
|
||||||
|
function_token: input.parse()?,
|
||||||
|
name: input.parse()?,
|
||||||
|
colon_token: input.parse()?,
|
||||||
|
ty: input.parse()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Parse for Namespace {
|
||||||
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
|
let content;
|
||||||
|
Ok(Namespace {
|
||||||
|
namespace_token: input.parse()?,
|
||||||
|
path: NamespacePath::parse_separated_nonempty(input)?,
|
||||||
|
brace_token: braced!(content in input),
|
||||||
|
fields: content.parse_terminated(Field::parse, Token![,])?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::{format_ident, quote, ToTokens};
|
use quote::{format_ident, quote, ToTokens};
|
||||||
use syn::{punctuated::Punctuated, Token, Type, Ident};
|
use syn::{punctuated::Punctuated, Ident, Token, Type};
|
||||||
|
|
||||||
use crate::{DataCommandEnum, Field};
|
use crate::{DataCommandEnum, command_enum_parsing::Field};
|
||||||
|
|
||||||
use super::get_input_type_of_bare_fn_field;
|
use super::get_input_type_of_bare_fn_field;
|
||||||
|
|
||||||
|
@ -71,12 +71,19 @@ fn turn_struct_field_to_enum(field: &Field) -> (TokenStream2, TokenStream2) {
|
||||||
turn_fields_to_enum(&namespace.fields);
|
turn_fields_to_enum(&namespace.fields);
|
||||||
let namespace_name: Ident = format_ident!(
|
let namespace_name: Ident = format_ident!(
|
||||||
"{}",
|
"{}",
|
||||||
namespace.path.iter().map(|name| name.to_string()).collect::<String>()
|
namespace
|
||||||
|
.path
|
||||||
|
.iter()
|
||||||
|
.map(|name| name.to_string())
|
||||||
|
.collect::<String>()
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_namespace_name: Ident = format_ident!(
|
let new_namespace_name: Ident = format_ident!(
|
||||||
"{}",
|
"{}",
|
||||||
namespace_name.to_string().from_case(Case::Snake).to_case(Case::Pascal)
|
namespace_name
|
||||||
|
.to_string()
|
||||||
|
.from_case(Case::Snake)
|
||||||
|
.to_case(Case::Pascal)
|
||||||
);
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -2,7 +2,10 @@ use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use syn::{punctuated::Punctuated, Token};
|
use syn::{punctuated::Punctuated, Token};
|
||||||
|
|
||||||
use crate::{DataCommandEnum, Field, FunctionDeclaration, NamespacePath};
|
use crate::{
|
||||||
|
command_enum_parsing::{Field, NamespacePath, FunctionDeclaration},
|
||||||
|
DataCommandEnum,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn generate_add_lua_functions_to_globals(input: &DataCommandEnum) -> TokenStream2 {
|
pub fn generate_add_lua_functions_to_globals(input: &DataCommandEnum) -> TokenStream2 {
|
||||||
fn turn_field_to_functions(
|
fn turn_field_to_functions(
|
||||||
|
@ -12,10 +15,8 @@ pub fn generate_add_lua_functions_to_globals(input: &DataCommandEnum) -> TokenSt
|
||||||
input
|
input
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| match field {
|
.map(|field| match field {
|
||||||
crate::Field::Function(function) => {
|
Field::Function(function) => generate_function_adder(function, namespace_path),
|
||||||
generate_function_adder(function, namespace_path)
|
Field::Namespace(namespace) => {
|
||||||
}
|
|
||||||
crate::Field::Namespace(namespace) => {
|
|
||||||
let mut passed_namespace =
|
let mut passed_namespace =
|
||||||
namespace_path.unwrap_or(&Default::default()).clone();
|
namespace_path.unwrap_or(&Default::default()).clone();
|
||||||
namespace
|
namespace
|
||||||
|
|
|
@ -5,7 +5,7 @@ use syn::{punctuated::Punctuated, token::Comma, GenericArgument, Lifetime, Token
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
generate::{get_input_type_of_bare_fn_field, get_return_type_of_bare_fn_field},
|
generate::{get_input_type_of_bare_fn_field, get_return_type_of_bare_fn_field},
|
||||||
DataCommandEnum, Field, FunctionDeclaration, NamespacePath,
|
DataCommandEnum, command_enum_parsing::{NamespacePath, Field, FunctionDeclaration},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn generate_rust_wrapper_functions(
|
pub fn generate_rust_wrapper_functions(
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub use command_enum::command_enum;
|
||||||
pub use lua_wrapper::lua_wrapper;
|
pub use lua_wrapper::lua_wrapper;
|
||||||
use syn::{ReturnType, Type, TypeBareFn};
|
use syn::{ReturnType, Type, TypeBareFn};
|
||||||
|
|
||||||
use crate::FunctionDeclaration;
|
use crate::command_enum_parsing::FunctionDeclaration;
|
||||||
|
|
||||||
pub fn get_bare_fn_input_type(function: &TypeBareFn) -> Option<Type> {
|
pub fn get_bare_fn_input_type(function: &TypeBareFn) -> Option<Type> {
|
||||||
if function.inputs.len() == 1 {
|
if function.inputs.len() == 1 {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
use command_enum_parsing::DataCommandEnum;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{
|
use syn::parse_macro_input;
|
||||||
braced, parse::Parse, parse_macro_input, punctuated::Punctuated, token, Attribute, Ident,
|
|
||||||
Token, Type,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod generate;
|
mod generate;
|
||||||
|
mod command_enum_parsing;
|
||||||
|
|
||||||
/// This is the heart of the command api
|
/// This is the heart of the command api
|
||||||
/// It mainly does two things:
|
/// It mainly does two things:
|
||||||
|
@ -73,115 +73,6 @@ mod generate;
|
||||||
/// };
|
/// };
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
|
||||||
struct DataCommandEnum {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
commands_token: kw::commands,
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
brace_token: token::Brace,
|
|
||||||
|
|
||||||
fields: Punctuated<Field, Token![,]>,
|
|
||||||
}
|
|
||||||
|
|
||||||
mod kw {
|
|
||||||
syn::custom_keyword!(commands);
|
|
||||||
syn::custom_keyword!(namespace);
|
|
||||||
syn::custom_keyword!(declare);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum Field {
|
|
||||||
Function(FunctionDeclaration),
|
|
||||||
Namespace(Namespace),
|
|
||||||
}
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct Namespace {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
namespace_token: kw::namespace,
|
|
||||||
|
|
||||||
path: NamespacePath,
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
brace_token: token::Brace,
|
|
||||||
|
|
||||||
fields: Punctuated<Field, Token![,]>,
|
|
||||||
}
|
|
||||||
type NamespacePath = Punctuated<Ident, Token![::]>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct FunctionDeclaration {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
function_token: kw::declare,
|
|
||||||
|
|
||||||
name: Ident,
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
colon_token: Token![:],
|
|
||||||
|
|
||||||
ty: Type,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for DataCommandEnum {
|
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
|
||||||
let content;
|
|
||||||
Ok(DataCommandEnum {
|
|
||||||
commands_token: input.parse()?,
|
|
||||||
brace_token: braced!(content in input),
|
|
||||||
fields: content.parse_terminated(Field::parse, Token![,])?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Parse for Field {
|
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
|
||||||
let lookahead = input.lookahead1();
|
|
||||||
if input.peek(Token![#]) {
|
|
||||||
// FIXME(@soispha): We ignore doc comments, which should probably be replaced by adding
|
|
||||||
// them to the output <2023-09-19>
|
|
||||||
let _output = input.call(Attribute::parse_outer).unwrap_or(vec![]);
|
|
||||||
let lookahead = input.lookahead1();
|
|
||||||
|
|
||||||
if lookahead.peek(kw::namespace) {
|
|
||||||
input.parse().map(Field::Namespace)
|
|
||||||
} else if lookahead.peek(kw::declare) {
|
|
||||||
input.parse().map(Field::Function)
|
|
||||||
} else {
|
|
||||||
Err(lookahead.error())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if lookahead.peek(kw::declare) {
|
|
||||||
input.parse().map(Field::Function)
|
|
||||||
} else if lookahead.peek(kw::namespace) {
|
|
||||||
input.parse().map(Field::Namespace)
|
|
||||||
} else {
|
|
||||||
Err(lookahead.error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for FunctionDeclaration {
|
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
|
||||||
Ok(FunctionDeclaration {
|
|
||||||
function_token: input.parse()?,
|
|
||||||
name: input.parse()?,
|
|
||||||
colon_token: input.parse()?,
|
|
||||||
ty: input.parse()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Parse for Namespace {
|
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
|
||||||
let content;
|
|
||||||
Ok(Namespace {
|
|
||||||
namespace_token: input.parse()?,
|
|
||||||
path: NamespacePath::parse_separated_nonempty(input)?,
|
|
||||||
brace_token: braced!(content in input),
|
|
||||||
fields: content.parse_terminated(Field::parse, Token![,])?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn parse_command_enum(input: TokenStream) -> TokenStream {
|
pub fn parse_command_enum(input: TokenStream) -> TokenStream {
|
||||||
let input = parse_macro_input!(input as DataCommandEnum);
|
let input = parse_macro_input!(input as DataCommandEnum);
|
||||||
|
|
Loading…
Reference in New Issue