Skip to content

Instantly share code, notes, and snippets.

@turicas
Created April 4, 2024 22:16
Show Gist options
  • Save turicas/a83ac50833b78707a306385de315de8f to your computer and use it in GitHub Desktop.
Save turicas/a83ac50833b78707a306385de315de8f to your computer and use it in GitHub Desktop.
Create ctags-like file using tree-sitter and awk
#!/bin/bash
filename="$1"
if [[ -z $filename ]]; then
echo "ERROR - usage: $0 <filename>"
exit 1
fi
transformation_code='
$3 ~ /^def/ {
gsub(/^\s*\| /, "", $2);
gsub(/^[^`]+`/, "", $3);
gsub(/`$/, "", $3);
print $1 "\t" filename "\t/" $3 "/;\"\t" $2
}
'
tree-sitter tags "$filename" \
| awk -F '\t' -v "filename=$filename" "$transformation_code"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment