🎉 Initialized repository based on 2023 code

This commit is contained in:
LeMoonStar 2024-11-30 13:39:19 +01:00
commit cc42c33b5d
65 changed files with 3897 additions and 0 deletions

1
aoc-macro/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

46
aoc-macro/Cargo.lock generated Normal file
View file

@ -0,0 +1,46 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aoc-macro"
version = "0.1.0"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

13
aoc-macro/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "aoc-macro"
version = "0.1.0"
edition = "2021"
[lib]
proc-macro=true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
quote = "^1.0"
syn = "^1.0"

108
aoc-macro/src/lib.rs Normal file
View file

@ -0,0 +1,108 @@
use proc_macro::TokenStream;
use quote::quote;
// Again, huge thanks to andi_makes
// this is basically a copy of his macros, with very slight modifications.
#[proc_macro]
pub fn mod_days(_input: TokenStream) -> TokenStream {
let mut res = String::new();
for i in 1..26 {
res += &format!("mod d{:02};", i);
}
res.parse().unwrap()
}
/*#[proc_macro]
pub fn match_and_run_day(_input: TokenStream) -> TokenStream {
let mut res = "match day {".to_string();
for i in 1..26 {
res += &format!("{} => Day::<{}>::run_timed(input),", i, i);
}
res += "_ => panic!(\"Days out of Bounds! No presents for you!\")};";
res.parse().unwrap()
}*/
#[proc_macro]
pub fn match_and_run_day_both(_input: TokenStream) -> TokenStream {
let r = 1_u8..26; // == [1,25]
let res = quote! {
match day {
#(#r => {
Day::<#r>::run_timed(input.trim_end())
})*
_ => panic!("Days out of Bounds! No presents for you!"),
}
};
res.into()
}
#[proc_macro]
pub fn match_and_run_day_one(_input: TokenStream) -> TokenStream {
let r = 1_u8..26; // == [1,25]
let res = quote! {
match day {
#(#r => {
Day::<#r>::run_one_timed(input.trim_end())
})*
_ => panic!("Days out of Bounds! No presents for you!"),
}
};
res.into()
}
#[proc_macro]
pub fn match_and_run_day_two(_input: TokenStream) -> TokenStream {
let r = 1_u8..26; // == [1,25]
let res = quote! {
match day {
#(#r => {
Day::<#r>::run_two_timed(input.trim_end())
})*
_ => panic!("Days out of Bounds! No presents for you!"),
}
};
res.into()
}
#[proc_macro]
pub fn match_and_test_day_both(_input: TokenStream) -> TokenStream {
let r = 1_u8..26; // == [1,25]
let res = quote! {
match day {
#(#r => {
Day::<#r>::test()
})*
_ => panic!("Days out of Bounds! No presents for you!"),
}
};
res.into()
}
#[proc_macro]
pub fn match_and_test_day_one(_input: TokenStream) -> TokenStream {
let r = 1_u8..26; // == [1,25]
let res = quote! {
match day {
#(#r => {
Day::<#r>::test_one()
})*
_ => panic!("Days out of Bounds! No presents for you!"),
}
};
res.into()
}
#[proc_macro]
pub fn match_and_test_day_two(_input: TokenStream) -> TokenStream {
let r = 1_u8..26; // == [1,25]
let res = quote! {
match day {
#(#r => {
Day::<#r>::test_two()
})*
_ => panic!("Days out of Bounds! No presents for you!"),
}
};
res.into()
}