forked from AineeJames/c3-zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_treesitter.sh
More file actions
executable file
·45 lines (33 loc) · 1.13 KB
/
run_treesitter.sh
File metadata and controls
executable file
·45 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
set -euo pipefail
GRAMMAR_DIR="/Users/f00lg/github/c3/c3-zed/grammars/c3"
HIGHLIGHTS_DIR="queries/highlights.scm"
HIGHLIGHTS_DIR="/Users/f00lg/github/c3/c3-zed/languages/c3/highlights.scm"
INPUT_FILE="${1:-/Users/f00lg/github/c3/c3-zed/test.c3}"
OUT_DIR="${2:-/Users/f00lg/github/c3/c3-zed}"
RUN_TESTS="${RUN_TESTS:-0}"
BASENAME="$(basename "${INPUT_FILE%.*}")"
HIGHLIGHT_OUT="${OUT_DIR}/${BASENAME}.highlights.txt"
TREE_OUT="${OUT_DIR}/${BASENAME}.tree.txt"
if [[ ! -f "$INPUT_FILE" ]]; then
echo "Input file not found: $INPUT_FILE" >&2
exit 1
fi
if [[ ! -d "$GRAMMAR_DIR" ]]; then
echo "Grammar dir not found: $GRAMMAR_DIR" >&2
exit 1
fi
mkdir -p "$OUT_DIR"
cd "$GRAMMAR_DIR"
TS_CLI=(npx -y tree-sitter-cli@0.26.5)
"${TS_CLI[@]}" generate
if [[ "$RUN_TESTS" == "1" ]]; then
if ! "${TS_CLI[@]}" test; then
echo "Warning: tree-sitter tests failed; continuing to produce output files." >&2
fi
fi
"${TS_CLI[@]}" query -p "$GRAMMAR_DIR" "$HIGHLIGHTS_DIR" "$INPUT_FILE" > "$HIGHLIGHT_OUT"
"${TS_CLI[@]}" parse -p "$GRAMMAR_DIR" "$INPUT_FILE" > "$TREE_OUT"
echo "Wrote:"
echo " $HIGHLIGHT_OUT"
echo " $TREE_OUT"