style(treewide): format

This commit is contained in:
Benedikt Peetz 2024-03-26 17:28:21 +01:00
parent 5855d9bcb0
commit 5ada3cb83d
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
14 changed files with 150 additions and 143 deletions

View File

@ -24,21 +24,25 @@ edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.5.4", features = ["derive"], optional = true } clap = { version = "4.5.4", features = ["derive"], optional = true }
convert_case = {version = "0.6.0", optional = true} convert_case = { version = "0.6.0", optional = true }
proc-macro2 = {version = "1.0.79", optional = true} proc-macro2 = { version = "1.0.79", optional = true }
quote = {version = "1.0.35", optional = true} quote = { version = "1.0.35", optional = true }
syn = { version = "2.0.55", features = ["extra-traits", "full", "parsing"], optional = true } syn = { version = "2.0.55", features = [
thiserror = { version = "1.0.58", optional = true} "extra-traits",
pulldown-cmark = {version = "0.10.0", optional = true} "full",
"parsing",
], optional = true }
thiserror = { version = "1.0.58", optional = true }
pulldown-cmark = { version = "0.10.0", optional = true }
# macros # macros
prettyplease = {version = "0.2.17", optional = true} prettyplease = { version = "0.2.17", optional = true }
# parser # parser
regex = {version = "1.10.4", optional = true} regex = { version = "1.10.4", optional = true }
# types # types
libc ={ version = "0.2.153", optional = true} libc = { version = "0.2.153", optional = true }
log = { version = "0.4.21", optional = true} log = { version = "0.4.21", optional = true }
[dev-dependencies] [dev-dependencies]
# parser # parser
@ -49,9 +53,27 @@ pretty_assertions = "1.4.0"
default = ["parser", "types", "macros"] default = ["parser", "types", "macros"]
build-binary = ["parser", "types", "macros", "clap", "pulldown-cmark"] build-binary = ["parser", "types", "macros", "clap", "pulldown-cmark"]
parser = [ "regex", "thiserror", "convert_case" ] parser = ["regex", "thiserror", "convert_case"]
types = [ "parser", "libc", "log", "proc-macro2", "quote", "syn", "thiserror", "convert_case" ] types = [
macros = [ "parser", "types", "prettyplease", "proc-macro2", "quote", "syn", "convert_case" ] "parser",
"libc",
"log",
"proc-macro2",
"quote",
"syn",
"thiserror",
"convert_case",
]
macros = [
"parser",
"types",
"prettyplease",
"proc-macro2",
"quote",
"syn",
"convert_case",
"pulldown-cmark",
]
[[bin]] [[bin]]
name = "trixy" name = "trixy"

View File

@ -18,15 +18,15 @@
# If not, see <https://www.gnu.org/licenses/>. # If not, see <https://www.gnu.org/licenses/>.
tag_prefix = "v" tag_prefix = "v"
branch_whitelist = [ "main" ] branch_whitelist = ["main"]
ignore_merge_commits = false ignore_merge_commits = false
[commit_types] [commit_types]
pre_bump_hooks = [ pre_bump_hooks = [
"licensur -p -i" # update the license header in each file "licensur -p -i", # update the license header in each file
"nix build", # verify the project builds "nix build", # verify the project builds
"nix fmt" # format "nix fmt", # format
"cargo set-version {{version}}", # bump version in Cargo.toml "cargo set-version {{version}}", # bump version in Cargo.toml
] ]
post_bump_hooks = [ post_bump_hooks = [
@ -42,20 +42,4 @@ path = "NEWS.md"
remote = "git.nerdcult.net" remote = "git.nerdcult.net"
repository = "trixy" repository = "trixy"
owner = "trinitrix" owner = "trinitrix"
authors = [ authors = [{ signature = "Soispha", username = "soispha" }]
{ signature = "Soispha", username = "soispha" },
]
[packages]
trixy-lang_parser = { path = "trixy-lang_parser", changelog_path = "{path}/NEWS.md" }}
pre_bump_hooks = [
"nix build", # verify the project builds
"cargo fmt --all" # format
"cargo set-version {{version}}", # bump version in Cargo.toml
]
post_bump_hooks = [
"git push",
"cargo publish",
"git push origin v{{version}}", # push the new tag to origin
]

View File

@ -2,88 +2,88 @@
# Parts of a shell library {{{ # Parts of a shell library {{{
die() { die() {
error "$1"; error "$1"
if [ -n "$2" ]; then if [ -n "$2" ]; then
exit "$2"; exit "$2"
else else
exit 1; exit 1
fi fi
} }
print() { print() {
# The direct usage is intended as `print` is rather lowlevel # The direct usage is intended as `print` is rather lowlevel
# shellcheck disable=2059 # shellcheck disable=2059
printf "$*"; printf "$*"
}; }
println() { println() {
# The direct usage is intended as `println` is rather lowlevel # The direct usage is intended as `println` is rather lowlevel
# shellcheck disable=2059 # shellcheck disable=2059
printf "$*\n"; printf "$*\n"
}; }
eprint() { eprint() {
>&2 print "$@"; >&2 print "$@"
}; }
eprintln() { eprintln() {
>&2 println "$@"; >&2 println "$@"
}; }
if [ -n "$NO_COLOR" ];then if [ -n "$NO_COLOR" ]; then
error() { error() {
eprintln "==> ERROR:" "$*"; eprintln "==> ERROR:" "$*"
}; }
warning() { warning() {
eprintln "==> WARNING:" "$*"; eprintln "==> WARNING:" "$*"
}; }
debug() { debug() {
[ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "==> [Debug:]" "$*"; [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "==> [Debug:]" "$*"
}; }
debug2() { debug2() {
[ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln " -> [Debug:]" "$*"; [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln " -> [Debug:]" "$*"
}; }
msg() { msg() {
eprintln "==>" "$*"; eprintln "==>" "$*"
}; }
msg2() { msg2() {
eprintln " ->" "$*"; eprintln " ->" "$*"
}; }
prompt() { prompt() {
eprint "..>" "$*"; eprint "..>" "$*"
}; }
else else
# See https://stackoverflow.com/a/33206814 for ansi codes # See https://stackoverflow.com/a/33206814 for ansi codes
error() { error() {
eprintln "\033[1;91m==> ERROR:\033[0m" "\033[1;93m$*\033[0m"; eprintln "\033[1;91m==> ERROR:\033[0m" "\033[1;93m$*\033[0m"
}; }
warning() { warning() {
eprintln "\033[1;91m==> WARNING:\033[0m" "\033[1;93m$*\033[0m"; eprintln "\033[1;91m==> WARNING:\033[0m" "\033[1;93m$*\033[0m"
}; }
debug() { debug() {
[ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "\033[1;94m==> [Debug:]\033[0m" "\033[1;93m$*\033[0m"; [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "\033[1;94m==> [Debug:]\033[0m" "\033[1;93m$*\033[0m"
}; }
debug2() { debug2() {
[ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "\033[1;94m -> [Debug:]\033[0m" "\033[1;93m$*\033[0m"; [ -n "$SHELL_LIBRARY_DEBUG" ] && eprintln "\033[1;94m -> [Debug:]\033[0m" "\033[1;93m$*\033[0m"
}; }
msg() { msg() {
eprintln "\033[1;96m==>\033[0m" "\033[1;93m$*\033[0m"; eprintln "\033[1;96m==>\033[0m" "\033[1;93m$*\033[0m"
}; }
msg2() { msg2() {
eprintln "\033[1;96m ->\033[0m" "\033[1;93m$*\033[0m"; eprintln "\033[1;96m ->\033[0m" "\033[1;93m$*\033[0m"
}; }
prompt() { prompt() {
eprint "\033[1;96m..>\033[0m" "\033[1;93m$*\033[0m"; eprint "\033[1;96m..>\033[0m" "\033[1;93m$*\033[0m"
}; }
fi fi
mktmp() { mktmp() {
ensure_tmp_dir; ensure_tmp_dir
mktemp -p "$SHELL_LIBRARY_TEMP_PREFIX_DIR"; mktemp -p "$SHELL_LIBRARY_TEMP_PREFIX_DIR"
} }
ensure_tmp_dir() { ensure_tmp_dir() {
if ! [ -d "$SHELL_LIBRARY_TEMP_PREFIX_DIR" ];then if ! [ -d "$SHELL_LIBRARY_TEMP_PREFIX_DIR" ]; then
SHELL_LIBRARY_TEMP_PREFIX_DIR="$(mktemp -d)"; SHELL_LIBRARY_TEMP_PREFIX_DIR="$(mktemp -d)"
fi fi
}; }
# A new version of tmp, which allows you to specify the commandline args as normal # A new version of tmp, which allows you to specify the commandline args as normal
# arguments # arguments
@ -92,54 +92,53 @@ tmp() {
warn "Detected an old version of tmp, as there are spaces in the input string!" warn "Detected an old version of tmp, as there are spaces in the input string!"
fi fi
TEMP_DIR_WITH_DEL="$(mktmp)"; TEMP_DIR_WITH_DEL="$(mktmp)"
"$@" 1> "$TEMP_DIR_WITH_DEL"; "$@" 1>"$TEMP_DIR_WITH_DEL"
echo "$TEMP_DIR_WITH_DEL"; echo "$TEMP_DIR_WITH_DEL"
}; }
# Takes a path to search as argument. # Takes a path to search as argument.
# Also takes further arguments as names to search for. # Also takes further arguments as names to search for.
# Prints the path to a file, if a file matching the given name is found. # Prints the path to a file, if a file matching the given name is found.
search_dir_for_file() { search_dir_for_file() {
[ -d "$1" ] || die "Arg $1 is not a directory"; [ -d "$1" ] || die "Arg $1 is not a directory"
directory="$1" && shift 1; directory="$1" && shift 1
while read -r dir_entry; do while read -r dir_entry; do
dir_entry_count=$((dir_entry_count + 1)); dir_entry_count=$((dir_entry_count + 1))
dir_entry_basename="$(basename "$dir_entry")"; dir_entry_basename="$(basename "$dir_entry")"
for name in "$@";do for name in "$@"; do
if [ "$name" = "$dir_entry_basename" ]; then if [ "$name" = "$dir_entry_basename" ]; then
println "$dir_entry"; println "$dir_entry"
fi fi
done done
done < "$(tmp fd . "$directory" --type file --max-depth 1)" done <"$(tmp fd . "$directory" --type file --max-depth 1)"
print ""; print ""
} }
# Returns the path to the directory which contains all the specified files: # Returns the path to the directory which contains all the specified files:
# `search_upward_files file1 file2 file3` returns a path containing file1 ... # `search_upward_files file1 file2 file3` returns a path containing file1 ...
search_upward_files() { search_upward_files() {
directory="$(pwd)"; directory="$(pwd)"
final_directory=""; final_directory=""
output="$(mktmp)"; output="$(mktmp)"
while [ "$(wc -l < "$output")" = 0 ]; do while [ "$(wc -l <"$output")" = 0 ]; do
search_dir_for_file "$directory" "$@" > "$output"; search_dir_for_file "$directory" "$@" >"$output"
directory="$(dirname "$directory")"; directory="$(dirname "$directory")"
if [ "$directory" = "/" ]; then if [ "$directory" = "/" ]; then
warning "We bailed out, as there seems to be no directory containing $*"; warning "We bailed out, as there seems to be no directory containing $*"
final_directory=""; final_directory=""
return; return
fi fi
done done
final_directory="$(dirname "$(head -n1 "$output")")"; final_directory="$(dirname "$(head -n1 "$output")")"
print "$final_directory"; print "$final_directory"
} }
# }}} # }}}
help() { help() {
cat << EOF cat <<EOF
A test manager (for trixy integration tests) A test manager (for trixy integration tests)
USAGE: USAGE:
@ -170,11 +169,11 @@ ARGUMENTS:
EOF EOF
} }
ROOT_DIR="$(search_upward_files "Cargo.toml")"; ROOT_DIR="$(search_upward_files "Cargo.toml")"
new() { new() {
test_name="$1"; test_name="$1"
test_dir="$ROOT_DIR/tests/$test_name"; test_dir="$ROOT_DIR/tests/$test_name"
[ -d "$test_dir" ] && die "$test_dir already exists, refusing to override" [ -d "$test_dir" ] && die "$test_dir already exists, refusing to override"
@ -189,12 +188,12 @@ new() {
update() { update() {
test_name="$1" test_name="$1"
test_dir="$ROOT_DIR/tests/$test_name"; test_dir="$ROOT_DIR/tests/$test_name"
if [ -n "$test_name" ]; then if [ -n "$test_name" ]; then
cargo run --features build-binary -- \ cargo run --features build-binary -- \
"$test_dir/input.tri" generate all --no-vendored \ "$test_dir/input.tri" generate all --no-vendored \
> "$test_dir/expected.md" >"$test_dir/expected.md"
else else
fd . "$ROOT_DIR/tests" --type directory --max-depth=1 --exec basename | while read -r dir; do fd . "$ROOT_DIR/tests" --type directory --max-depth=1 --exec basename | while read -r dir; do
msg2 "Updating $dir.." msg2 "Updating $dir.."
@ -206,24 +205,23 @@ update() {
for arg in "$@"; do for arg in "$@"; do
case "$arg" in case "$arg" in
"--help" | "-h") "--help" | "-h")
help; help
exit 0; exit 0
;; ;;
esac esac
done done
case "$1" in case "$1" in
"update") "update")
shift 1; shift 1
[ -n "$1" ] && test_name="$1" [ -n "$1" ] && test_name="$1"
update "$test_name"; update "$test_name"
;; ;;
"new") "new")
shift 1; shift 1
test_name="$1"; test_name="$1"
[ -z "$test_name" ] && die "You must specify a TESTNAME" [ -z "$test_name" ] && die "You must specify a TESTNAME"
new "$test_name"; new "$test_name"
;; ;;
esac esac
# vim: ft=sh # vim: ft=sh

View File

@ -79,7 +79,7 @@ pub enum GenCommand {
/// Generate all code for every language /// Generate all code for every language
All { All {
#[arg(short, long, default_value_t=true)] #[arg(short, long, default_value_t = true)]
/// Don't generate vendored files (like c headers) /// Don't generate vendored files (like c headers)
no_vendored: bool, no_vendored: bool,
}, },

View File

@ -21,10 +21,10 @@
#[cfg(feature = "macros")] #[cfg(feature = "macros")]
pub mod macros; pub mod macros;
#[cfg(feature = "types")]
pub mod types;
#[cfg(feature = "parser")] #[cfg(feature = "parser")]
pub mod parser; pub mod parser;
#[cfg(feature = "types")]
pub mod types;
pub mod __private { pub mod __private {
//! This module contains crates needed for the generated code, it should not be used by humans. //! This module contains crates needed for the generated code, it should not be used by humans.

View File

@ -6,7 +6,6 @@ mod namespace;
mod structure; mod structure;
mod r#type; mod r#type;
// pub use attribute::*; // pub use attribute::*;
// pub use enumeration::*; // pub use enumeration::*;
// pub use function::*; // pub use function::*;

View File

@ -1,2 +1,2 @@
pub mod rust;
pub mod c; pub mod c;
pub mod rust;

View File

@ -1,2 +1,2 @@
pub mod structure;
pub mod enumeration; pub mod enumeration;
pub mod structure;

View File

@ -1,2 +1,2 @@
pub mod path;
pub mod module; pub mod module;
pub mod path;

View File

@ -1,2 +1,2 @@
pub mod host;
pub mod auxiliary; pub mod auxiliary;
pub mod host;

View File

@ -1,3 +1,3 @@
pub mod host;
pub mod auxiliary; pub mod auxiliary;
pub mod convert; pub mod convert;
pub mod host;

View File

@ -1,5 +1,7 @@
# Host files # Host files
File path: `out/dir/api.rs` File path: `out/dir/api.rs`
```rust ```rust
// Host code // Host code
/* Rust API */ /* Rust API */
@ -45,7 +47,9 @@ pub extern "C" fn trinitrix_hi(
``` ```
# Auxiliary files # Auxiliary files
File path: `dist/interface.h` File path: `dist/interface.h`
```c ```c
#if !defined TRIXY_MAIN_HEADER #if !defined TRIXY_MAIN_HEADER
#define TRIXY_MAIN_HEADER #define TRIXY_MAIN_HEADER
@ -70,5 +74,3 @@ const struct trinitrix trinitrix = {
#endif // if !defined TRIXY_MAIN_HEADER #endif // if !defined TRIXY_MAIN_HEADER
// vim: filetype=c // vim: filetype=c
``` ```

View File

@ -1,5 +1,7 @@
# Host files # Host files
File path: `out/dir/api.rs` File path: `out/dir/api.rs`
```rust ```rust
// Host code // Host code
/* Rust API */ /* Rust API */
@ -32,7 +34,9 @@ pub extern "C" fn name_one_from_second_namespace() -> core::ffi::c_int {
``` ```
# Auxiliary files # Auxiliary files
File path: `dist/interface.h` File path: `dist/interface.h`
```c ```c
#if !defined TRIXY_MAIN_HEADER #if !defined TRIXY_MAIN_HEADER
#define TRIXY_MAIN_HEADER #define TRIXY_MAIN_HEADER
@ -59,5 +63,3 @@ const struct name_one name_one = {
#endif // if !defined TRIXY_MAIN_HEADER #endif // if !defined TRIXY_MAIN_HEADER
// vim: filetype=c // vim: filetype=c
``` ```

View File

@ -61,7 +61,7 @@ mod trinitrix {
/// Allows you to insert things /// Allows you to insert things
Insert, Insert,
/// actives the command line /// actives the command line
Command Command,
} }
/// Change the active mode /// Change the active mode