1
0
Fork 0

chore(trixy): Rename `language_macros` to `trixy`

The motivation behind this change is to comply with the naming scheme:
starting crate names with `tri`
This commit is contained in:
Benedikt Peetz 2023-12-16 11:43:12 +01:00
parent 44a1ad77ea
commit cd2dbc516a
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
12 changed files with 135 additions and 136 deletions

22
Cargo.lock generated
View File

@ -1358,16 +1358,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "language_macros"
version = "0.1.0"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"syn 2.0.41",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -2797,7 +2787,6 @@ dependencies = [
"directories",
"indexmap 2.1.0",
"keymaps",
"language_macros",
"matrix-sdk",
"mlua",
"once_cell",
@ -2805,10 +2794,21 @@ dependencies = [
"serde",
"tokio",
"tokio-util",
"trixy",
"tui",
"tui-textarea",
]
[[package]]
name = "trixy"
version = "0.1.0"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"syn 2.0.41",
]
[[package]]
name = "try-lock"
version = "0.2.5"

View File

@ -18,7 +18,7 @@ matrix-sdk = "0.6"
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
# lua stuff
language_macros = { path = "./language_macros" }
trixy = { path = "./trixy" }
keymaps = { path = "./keymaps", features = ["crossterm"] }
mlua = { version = "0.9.2", features = ["lua54", "async", "send", "serialize"] }
once_cell = "1.19.0"

View File

@ -1,110 +0,0 @@
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![,])?,
})
}
}

View File

@ -1,5 +1,5 @@
[package]
name = "language_macros"
name = "trixy"
version = "0.1.0"
edition = "2021"

103
trixy/src/config/mod.rs Normal file
View File

@ -0,0 +1,103 @@
//! This module is responsible for parsing the config passed to the macro call:
//! For example:
//! ```no_run
//! trixy_generate! {
//! path: ./trintrix_command_interface.tri
//! languages: rust, lua, c
//! }
//! ```
use std::path::PathBuf;
use proc_macro2::Ident;
use syn::{parse::Parse, punctuated::Punctuated, LitStr, Result, Token};
mod kw {
syn::custom_keyword!(path);
syn::custom_keyword!(languages);
}
#[derive(Debug)]
pub enum Language {
Rust,
Lua,
C,
}
#[derive(Debug)]
struct Languages {
#[allow(dead_code)]
languages: kw::languages,
#[allow(dead_code)]
colon: Token![:],
raw: Punctuated<Language, Token![,]>,
}
#[derive(Debug)]
struct Path {
#[allow(dead_code)]
path: kw::path,
#[allow(dead_code)]
colon: Token![:],
raw: PathBuf,
}
#[derive(Debug)]
pub struct TrixyConfig {
/// The Path to the base command interface config file
path: Path,
/// The languages the commands should be exposed in
languages: Languages,
}
impl TrixyConfig {
pub fn get_path(&self) -> PathBuf {
self.path.raw
}
}
impl Parse for TrixyConfig {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
Ok(Self {
path: input.parse()?,
languages: input.parse()?,
})
}
}
impl Parse for Path {
fn parse(input: syn::parse::ParseStream) -> Result<Self> {
let path: kw::path = input.parse()?;
let colon: Token![:] = input.parse()?;
let raw = PathBuf::from(input.parse::<LitStr>()?.value());
Ok(Self { path, colon, raw })
}
}
impl Parse for Languages {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let languages: kw::languages = input.parse()?;
let colon: Token![:] = input.parse()?;
let raw = Punctuated::<Language, Token![,]>::parse_separated_nonempty(input)?;
Ok(Self {
languages,
colon,
raw,
})
}
}
impl Parse for Language {
fn parse(input: syn::parse::ParseStream) -> Result<Self> {
let ident: Ident = input.parse()?;
match &ident.to_string()[..] {
"rust" | "Rust" => Ok(Self::Rust),
"lua" | "Lua" => Ok(Self::Lua),
"c" | "C" => Ok(Self::C),
other => Err(input.error(format!(
"The language: `{}` is not a registered language!",
other
))),
}
}
}

View File

@ -1,12 +1,16 @@
use command_enum_parsing::DataCommandEnum;
use config::TrixyConfig;
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::parse_macro_input;
use crate::trixy_lang::parse_trixy_lang;
mod generate;
mod command_enum_parsing;
mod config;
mod generate;
mod trixy_lang;
/// This is the heart of the command api
/// It mainly does two things:
@ -74,18 +78,20 @@ mod command_enum_parsing;
/// }
/// ```
#[proc_macro]
pub fn parse_command_enum(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DataCommandEnum);
pub fn trixy_generate(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as TrixyConfig);
// Build the language wrappers
let lua_wrapper: TokenStream2 = generate::lua_wrapper(&input);
let trixy_code = parse_trixy_lang(input.get_path());
todo!()
// // Build the language wrappers
// let lua_wrapper: TokenStream2 = generate::lua_wrapper(&input);
//
// // Build the final enum
// let command_enum = generate::command_enum(&input);
// Build the final enum
let command_enum = generate::command_enum(&input);
let output = quote! {
#command_enum
#lua_wrapper
};
output.into()
// let output = quote! {
// #command_enum
// #lua_wrapper
// };
// output.into()
}