Created
July 23, 2025 11:57
-
-
Save nvlled/65b6c1b9385f28665baf6bb486612686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function usage() { | |
echo "usage: $0 <path-tree-sitter-c-dir> <destination-dir>" | |
echo | |
echo "description:" | |
echo " Creates tree-sitter template files for zig bindings" | |
echo " using the files from tree-sitter-c repository." | |
exit | |
} | |
src_dir="$1" | |
dest_dir="$2" | |
if [[ -z "$src_dir" ]] || [[ -z "$dest_dir" ]]; then | |
usage "$0" | |
fi | |
set -euo pipefail | |
mkdir -p "$dest_dir" | |
echo "copying files from '$src_dir' to '$dest_dir'"; | |
\cp -fv \ | |
"$src_dir/bindings/zig/root.zig" \ | |
"$src_dir/bindings/zig/test.zig" \ | |
"$src_dir/build.zig" \ | |
"$src_dir/build.zig.zon" \ | |
"$dest_dir" | |
cd "$dest_dir" | |
echo -e "\nreplacing hard-coded values with PARSER_VERSION or PARSER_NAME" | |
set -x | |
sed -i 's/tree_sitter_c/tree_sitter_PARSER_NAME/g' root.zig | |
sed -i 's/"tree-sitter-c"/"tree-sitter-PARSER_NAME"/g' build.zig test.zig | |
sed -i \ | |
'{ | |
s/\.version = ".*",/.version = "PARSER_VERSION",/ | |
s/\.name = \.[_0-9a-zA-Z]*/.name = .tree_sitter_PARSER_NAME/ | |
s/\.fingerprint = .*/.fingerprint = 0x0, \/\/ should be replaced with suggested value/ | |
}' \ | |
build.zig.zon | |
set +x | |
echo -e "\ndone." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment