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

View File

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

View File

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

View File

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

View File

@ -21,10 +21,10 @@
#[cfg(feature = "macros")]
pub mod macros;
#[cfg(feature = "types")]
pub mod types;
#[cfg(feature = "parser")]
pub mod parser;
#[cfg(feature = "types")]
pub mod types;
pub mod __private {
//! 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 r#type;
// pub use attribute::*;
// pub use enumeration::*;
// pub use function::*;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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