This commit is contained in:
2026-02-07 20:36:00 +08:00
commit f46084d3fe
16 changed files with 1432 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/target
.idea

977
Cargo.lock generated Normal file
View File

@@ -0,0 +1,977 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "anstream"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys 0.61.2",
]
[[package]]
name = "backtrace"
version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-link",
]
[[package]]
name = "bitflags"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "bytes"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "clap"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
[[package]]
name = "clap_mangen"
version = "0.2.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ea63a92086df93893164221ad4f24142086d535b3a0957b9b9bea2dc86301"
dependencies = [
"clap",
"roff",
]
[[package]]
name = "color-eyre"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "dirs"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.61.2",
]
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "errno"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "gimli"
version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
[[package]]
name = "hashbrown"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "indenter"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5"
[[package]]
name = "indexmap"
version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "itoa"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.180"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]]
name = "libredox"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616"
dependencies = [
"bitflags",
"libc",
]
[[package]]
name = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"scopeguard",
]
[[package]]
name = "magma"
version = "0.1.0"
dependencies = [
"clap",
"clap_mangen",
"color-eyre",
"dirs",
"pest",
"pest_derive",
"semver",
"serde",
"tokio",
"toml",
]
[[package]]
name = "memchr"
version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
]
[[package]]
name = "mio"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc"
dependencies = [
"libc",
"wasi",
"windows-sys 0.61.2",
]
[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "owo-colors"
version = "4.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52"
[[package]]
name = "parking_lot"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-link",
]
[[package]]
name = "pest"
version = "2.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9eb05c21a464ea704b53158d358a31e6425db2f63a1a7312268b05fe2b75f7"
dependencies = [
"memchr",
"serde",
"serde_json",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68f9dbced329c441fa79d80472764b1a2c7e57123553b8519b36663a2fb234ed"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bb96d5051a78f44f43c8f712d8e810adb0ebf923fc9ed2655a7f66f63ba8ee5"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pest_meta"
version = "2.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "602113b5b5e8621770cfd490cfd90b9f84ab29bd2b0e49ad83eb6d186cef2365"
dependencies = [
"pest",
"sha2",
]
[[package]]
name = "pin-project-lite"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]]
name = "roff"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3"
[[package]]
name = "rustc-demangle"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
dependencies = [
"serde",
"serde_core",
]
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "serde_spanned"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
dependencies = [
"serde_core",
]
[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
dependencies = [
"errno",
"libc",
]
[[package]]
name = "smallvec"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "socket2"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0"
dependencies = [
"libc",
"windows-sys 0.60.2",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.114"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
]
[[package]]
name = "tokio"
version = "1.49.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
dependencies = [
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.61.2",
]
[[package]]
name = "tokio-macros"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "toml"
version = "0.9.11+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "0.7.5+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
dependencies = [
"serde_core",
]
[[package]]
name = "toml_parser"
version = "1.0.6+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.0.6+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"
[[package]]
name = "tracing"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
name = "typenum"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
[[package]]
name = "ucd-trie"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-targets"
version = "0.53.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
[[package]]
name = "windows_i686_gnu"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
[[package]]
name = "windows_i686_msvc"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
[[package]]
name = "winnow"
version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
[[package]]
name = "zmij"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"

16
Cargo.toml Normal file
View File

@@ -0,0 +1,16 @@
[package]
name = "magma"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.5.54", features = ["cargo", "derive"] }
clap_mangen = "0.2.31"
pest = { version = "2.8.5", features = ["pretty-print"] }
pest_derive = { version = "2.8.5", features = ["grammar-extras"] }
color-eyre = "0.6.5"
tokio = { version = "1.49.0", features = ["full"] }
serde = { version = "1.0.228", features = ["derive"] }
toml = "0.9.11"
semver = { version = "1.0.27", features = ["serde"] }
dirs = "6.0.0"

7
assets/main.mg Normal file
View File

@@ -0,0 +1,7 @@
function load() {
command say "hello world!";
// on load
}
function tick() {
// on tick
}

2
build.rs Normal file
View File

@@ -0,0 +1,2 @@
fn main() {
}

72
src/cli/mod.rs Normal file
View File

@@ -0,0 +1,72 @@
mod project_initializer;
mod project_compiler;
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use tokio::fs;
use crate::cli::project_compiler::ProjectCompiler;
use crate::cli::project_initializer::ProjectInitializer;
use crate::helpers;
use crate::helpers::FILE_EXTENSION;
use crate::types::MagmaProjectConfig;
#[derive(Parser)]
#[command(author, version, about = "Redoxide cli", long_about = None)]
pub(crate) struct Cli {
#[command(subcommand)]
pub command: Commands
}
#[derive(Subcommand)]
pub(crate) enum Commands {
/// Initialize a new redoxide project
Init {
/// Project name (defaults to current directory name)
#[arg(value_name = "PROJECT_NAME")]
name: Option<String>,
/// Directory path where the project will be created
#[arg(short, long, value_name = "PATH")]
path: Option<PathBuf>,
},
/// Compile a redoxide project or a redoxide file
Compile {
/// Path to the redoxide file or project to compile
#[arg(value_name = "PATH")]
path: Option<PathBuf>,
/// Output file name
#[arg(short, long, value_name = "OUT_FILE")]
out_file: Option<String>
}
}
impl Cli {
pub async fn run(&self) -> color_eyre::Result<()> {
match &self.command {
Commands::Init { name, path } => {
let project_initializer = ProjectInitializer::new(name.clone(), path.clone())?;
project_initializer.init().await?;
},
Commands::Compile { path, out_file } => {
let path = path.clone().unwrap_or(std::env::current_dir()?);
let path = helpers::expand_tilde(path)?.canonicalize()?;
if path.is_dir() {
let config_path = path.join(format!(".{}", FILE_EXTENSION));
if !config_path.exists() {
return Err(color_eyre::eyre::eyre!("No magma project found in {}", path.display()));
}
let config_content = fs::read(config_path).await?;
let config = toml::from_slice::<MagmaProjectConfig>(&config_content)?;
let out_dir = path.join(&config.out_dir);
if !out_dir.exists() {
fs::create_dir_all(&out_dir).await?;
}
let mut compiler = ProjectCompiler::new(config, out_dir);
compiler.run(&path).await?;
} else {
return Err(color_eyre::eyre::eyre!("Path must be a directory for compilation"));
}
}
}
Ok(())
}
}

View File

@@ -0,0 +1,22 @@
use std::path::PathBuf;
use crate::compiler::MagmaCompiler;
use crate::types::{MagmaProjectConfig};
pub(crate) struct ProjectCompiler {
compiler: MagmaCompiler,
out_dir: PathBuf
}
impl ProjectCompiler {
pub fn new(config: MagmaProjectConfig, out_dir: PathBuf) -> Self {
Self {
compiler: MagmaCompiler::new(config),
out_dir
}
}
pub async fn run(&mut self, path: &PathBuf) -> color_eyre::Result<()> {
self.compiler.compile(path).await?;
Ok(())
}
}

View File

@@ -0,0 +1,46 @@
use std::path::PathBuf;
use tokio::fs;
use crate::helpers::FILE_EXTENSION;
use crate::types::MagmaProjectConfig;
pub(crate) struct ProjectInitializer {
name: String,
path: PathBuf,
}
impl ProjectInitializer {
pub fn new(name: Option<String>, path: Option<PathBuf>) -> color_eyre::Result<Self> {
let project_path = path.unwrap_or(std::env::current_dir()?);
let project_name = name.unwrap_or(
project_path.
file_name()
.and_then(|n|n.to_str())
.unwrap_or("magma-project")
.to_string()
);
Ok(Self { name: project_name, path: project_path })
}
pub async fn init(&self) -> color_eyre::Result<()> {
if !self.path.exists() {
fs::create_dir_all(&self.path).await?;
}
let magma_file = self.path.join(format!(".{}", FILE_EXTENSION));
let magma_config = MagmaProjectConfig::default();
fs::write(&magma_file, toml::to_string(&magma_config)?).await?;
let src_dir = self.path.join("src");
fs::create_dir_all(&src_dir).await?;
let main_file = src_dir.join(format!("main.{}", FILE_EXTENSION));
fs::write(&main_file, include_str!("../../assets/main.mg")).await?;
println!("✓ Initialized magma project: {}", self.name);
println!("\tLocation: {}", self.path.display());
println!("\tCreated:");
println!("\t\t- .mg");
println!("\t\t- src/");
println!("\t\t- src/main.mg");
Ok(())
}
}

94
src/compiler/mod.rs Normal file
View File

@@ -0,0 +1,94 @@
use std::path::PathBuf;
use pest::iterators::{Pair, Pairs};
use pest::Parser;
use crate::parser::{MagmaParser, Rule};
use crate::types::{MagmaProjectConfig, McFunctionFile};
pub(crate) struct MagmaCompiler {
out_functions: Vec<McFunctionFile>,
config: MagmaProjectConfig
}
impl MagmaCompiler {
pub(crate) fn new(config: MagmaProjectConfig) -> Self {
Self {
out_functions: Vec::new(),
config
}
}
pub async fn compile(&mut self, path: &PathBuf) -> color_eyre::Result<()> {
let main_file_path = path.join(&self.config.entrypoint);
let main_file_content = tokio::fs::read_to_string(&main_file_path).await?;
let parse_result = MagmaParser::parse(Rule::program, &main_file_content)?;
for pair in parse_result {
self.parse(pair)?;
}
Ok(())
}
fn parse(&mut self, pair: Pair<Rule>) -> color_eyre::Result<()> {
match pair.as_rule() {
Rule::functionExpression => {
let mut pairs = pair.into_inner();
let identifier = pairs.next().unwrap();
let args = if let Some(rule) = pairs.peek()
&& rule.as_rule() == Rule::functionArgs
{
Some(pairs.next().unwrap())
} else { None };
let statements = if let Some(rule) = pairs.peek()
&& rule.as_rule() == Rule::block
{ unbox_rule(pairs.next().unwrap()) }
else { None };
self.parse_function(None, identifier, args, statements)?;
}
_ => {}
}
Ok(())
}
fn parse_function(
&self,
namespace: Option<String>,
identifier: Pair<Rule>,
args: Option<Pair<Rule>>,
statements: Option<Pairs<Rule>>
) -> color_eyre::Result<McFunctionFile> {
let mut file = McFunctionFile::new(namespace, identifier.as_str().to_string());
let Some(statements) = statements else {
return Ok(file);
};
for statement in statements {
let Some(statement) = self.parse_statement(statement)? else {
continue;
};
file.add_line(statement);
}
println!("{}", file.lines().join("\n"));
Ok(file)
}
fn parse_statement(&self, statement: Pair<Rule>) -> color_eyre::Result<Option<String>> {
match statement.as_rule() {
Rule::commandLine => {
let command = statement.into_inner().next().unwrap();
Ok(Some(self.parse_command(command)?))
}
_ => {
Ok(None)
}
}
}
fn parse_command(&self, command: Pair<Rule>) -> color_eyre::Result<String> {
Ok(command.as_str().to_string())
}
}
fn unbox_rule(rule: Pair<Rule>) -> Option<Pairs<Rule>> {
let mut block = rule.into_inner();
if let Some(inner) = block.next() {
Some(inner.into_inner())
} else { None }
}

92
src/grammar.pest Normal file
View File

@@ -0,0 +1,92 @@
program = _{ SOI ~ expression* ~ EOI }
// expressions
expression = _{ namespaceExpression | fileScopeNamespaceExpression | functionExpression | includeExpression }
fileScopeNamespaceExpression = {
"namespace" ~ namespaceIdentifier ~ ";"
}
namespaceExpression = {
"namespace" ~ namespaceIdentifier ~ "{" ~ functionExpression* ~ "}"
}
functionExpression = {
"function" ~ identifier ~ "(" ~ functionArgs? ~ ")" ~ block
}
functionArgs = {
identifier ~ ("," ~ identifier)*
}
includeExpression = {
"include" ~ string ~ ";"
}
// rules
block = { "{" ~ statements* ~ "}" }
value = _{ identifier | number | string }
namespaceIdentifier = @{ identifier ~ ("." ~ identifier)* }
identifier = @{ (ASCII_ALPHA) ~ (ASCII_ALPHANUMERIC | "_")* }
number = @{ "-"? ~ ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT+)? }
string = @{ "\"" ~ ( escapeCharacters | !"\"" ~ ANY )* ~ "\"" }
statements = { commandStatement | returnStatement | ifStatement }
// statements
ifStatement = {
"if" ~ "(" ~ condition ~ ")" ~ block ~ elseIfStatement* ~ elseStatement?
}
elseIfStatement = {
"else" ~ "if" ~ "(" ~ condition ~ ")" ~ block
}
elseStatement = {
"else" ~ block
}
returnStatement = { "return" ~ value ~ ";" }
assignmentStatement = { identifier ~ "=" ~ binaryExpression ~ ";" }
commandStatement = _{ commandLine | commandBlock }
// mc commands
commandLine = { "command" ~ command }
commandBlock = { "command" ~ "{" ~ command* ~ "}" }
command = { mcArg+ ~ ";" }
mcArg = _{ nbtBlock | string | mcPrimitive }
nbtBlock = { "{" ~ (nbtBlock | string | !("}" | "{") ~ ANY)* ~ "}" }
mcPrimitive = @{ (!(";" | "{" | "}" | "\"" | WHITESPACE) ~ ANY)+ }
// Binary operations with precedence (using PEG climbing)
binaryExpression = { term ~ (addOp ~ term)* }
term = { factor ~ (mulOp ~ factor)* }
factor = { value | commandLine | "(" ~ binaryExpression ~ ")" }
addOp = { PLUS | SUBTRACT }
PLUS = { "+" }
SUBTRACT = { "-" }
mulOp = { MULTIPLY | DIVIDE | MODULO }
MULTIPLY = { "*" }
DIVIDE = { "/" }
MODULO = { "%" }
// boolean
condition = { booleanExpression }
booleanExpression = { booleanTerm ~ (boolOp ~ booleanTerm)* }
booleanTerm = { NOT* ~ comparison | value | "(" ~ booleanExpression ~ ")" }
comparison = { value ~ comparator ~ value }
comparator = { EQUAL | NOT_EQUAL | GREATER | GREATER_EQUAL | LESS | LESS_EQUAL }
NOT = { "!" }
NOT_EQUAL = { "!=" }
EQUAL = { "==" }
GREATER = { ">" }
LESS = { "<" }
GREATER_EQUAL = { ">=" }
LESS_EQUAL = { "<=" }
boolOp = { OR | AND }
OR = { "||" }
AND = { "&&" }
// constants
escapeCharacters = @{ "\\" ~ ("\"" | "\\" | "n" | "r" | "t") }
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
COMMENT = _{ multiLineComment | singleLineComment }
multiLineComment = { "/*" ~ (!"*/" ~ ANY)* ~ "*/" }
singleLineComment = { "//" ~ (!NEWLINE ~ ANY)* }

17
src/helpers/mod.rs Normal file
View File

@@ -0,0 +1,17 @@
use std::path::PathBuf;
pub const FILE_EXTENSION: &str = "mg";
pub(crate) fn expand_tilde(path: PathBuf) -> color_eyre::Result<PathBuf> {
if path.starts_with("~") {
let Some(home) = dirs::home_dir() else {
return Err(color_eyre::eyre::eyre!("No home directory found"));
};
if path == PathBuf::from("~") {
return Ok(home);
}
let relative = path.strip_prefix("~")?;
return Ok(home.join(relative));
}
Ok(path)
}

13
src/main.rs Normal file
View File

@@ -0,0 +1,13 @@
use clap::Parser;
mod parser;
mod cli;
mod types;
mod helpers;
mod compiler;
#[tokio::main]
async fn main() -> color_eyre::Result<()> {
cli::Cli::parse().run().await?;
Ok(())
}

9
src/parser/mod.rs Normal file
View File

@@ -0,0 +1,9 @@
use pest_derive::Parser;
#[derive(Parser)]
#[grammar = "grammar.pest"]
pub struct MagmaParser;
impl MagmaParser {
}

View File

@@ -0,0 +1,35 @@
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::helpers::FILE_EXTENSION;
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct MagmaProjectConfig {
pub version: Version,
pub entrypoint: PathBuf,
pub out_dir: PathBuf
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Version {
pub pack: [u8; 2],
pub redoxide: semver::Version,
}
impl Default for MagmaProjectConfig {
fn default() -> Self {
Self {
version: Default::default(),
entrypoint: PathBuf::from(format!("src/main.{}", FILE_EXTENSION)),
out_dir: PathBuf::from("out")
}
}
}
impl Default for Version {
fn default() -> Self {
Self {
pack: [94, 1],
redoxide: semver::Version::parse(env!("CARGO_PKG_VERSION")).unwrap()
}
}
}

View File

@@ -0,0 +1,23 @@
pub(crate) struct McFunctionFile {
content: Vec<String>,
namespace: Option<String>,
name: String
}
impl McFunctionFile {
pub fn new(namespace: Option<String>, name: String) -> Self {
Self {
content: Vec::new(),
namespace,
name
}
}
pub fn add_line(&mut self, line: String) {
self.content.push(line);
}
pub fn lines(&self) -> &Vec<String> {
&self.content
}
}

5
src/types/mod.rs Normal file
View File

@@ -0,0 +1,5 @@
mod magma_project_config;
mod mcfunction_file;
pub use magma_project_config::*;
pub(crate) use mcfunction_file::*;