aboutsummaryrefslogtreecommitdiff
path: root/Scripts/update-parser.sh
diff options
context:
space:
mode:
authorDavid Czihak <git@dcz.at>2026-05-07 14:33:19 +0200
committerDavid Czihak <git@dcz.at>2026-05-07 14:33:19 +0200
commitddf2de739068b5ff0866ccb1d067f3cb53a4fc55 (patch)
tree1a77efe9d73a6172be3c37d29b321eadd4efe379 /Scripts/update-parser.sh
Initial commitv0.1.7
Diffstat (limited to 'Scripts/update-parser.sh')
-rwxr-xr-xScripts/update-parser.sh64
1 files changed, 64 insertions, 0 deletions
diff --git a/Scripts/update-parser.sh b/Scripts/update-parser.sh
new file mode 100755
index 0000000..f4fab95
--- /dev/null
+++ b/Scripts/update-parser.sh
@@ -0,0 +1,64 @@
1#!/bin/sh
2#
3# update-parser.sh — Bump vendored tree-sitter-zig and rebuild the dylib.
4#
5# Purpose:
6# Refresh the vendored snapshot under vendor/tree-sitter-zig/ to a newer
7# upstream commit, update VENDORING.md, and rebuild the parser dylib.
8#
9# What it does:
10# - clones tree-sitter-grammars/tree-sitter-zig into a temp dir
11# - checks out the requested ref (default: HEAD of the default branch)
12# - exits early if the upstream SHA matches the pinned SHA
13# - replaces src/, queries/, grammar.js, tree-sitter.json, LICENSE
14# with the upstream copies; leaves VENDORING.md and README.upstream.md
15# untouched
16# - rewrites the "Pinned commit:" line in VENDORING.md
17# - invokes build-parser.sh to rebuild Syntaxes/libtree-sitter-zig.dylib
18# - prints a GitHub compare link for the diff
19#
20# Usage:
21# ./Scripts/update-parser.sh # bump to upstream HEAD
22# ./Scripts/update-parser.sh <ref> # bump to a tag, branch, or SHA
23#
24# Caveats:
25# - any local edits inside the listed paths are overwritten — review
26# `git diff vendor/` afterwards before committing
27# - parses VENDORING.md by an exact "Pinned commit: <sha>" line prefix;
28# keep that line format intact
29#
30# Requirements:
31# git, plus everything build-parser.sh needs.
32
33set -eu
34
35ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
36VENDOR_DIR="$ROOT/vendor/tree-sitter-zig"
37UPSTREAM="https://github.com/tree-sitter-grammars/tree-sitter-zig.git"
38REF="${1:-HEAD}"
39
40TMP="$(mktemp -d)"
41trap 'rm -rf "$TMP"' EXIT
42
43git clone --quiet "$UPSTREAM" "$TMP/repo"
44git -C "$TMP/repo" checkout --quiet "$REF"
45SHA="$(git -C "$TMP/repo" rev-parse HEAD)"
46
47OLD_SHA="$(awk '/^Pinned commit:/ {print $3}' "$VENDOR_DIR/VENDORING.md")"
48if [ "$SHA" = "$OLD_SHA" ]; then
49 echo "Already at $SHA — nothing to do."
50 exit 0
51fi
52
53for path in src queries grammar.js tree-sitter.json LICENSE; do
54 rm -rf "$VENDOR_DIR/$path"
55 cp -R "$TMP/repo/$path" "$VENDOR_DIR/$path"
56done
57
58sed -i.bak "s/^Pinned commit: .*/Pinned commit: $SHA/" "$VENDOR_DIR/VENDORING.md"
59rm "$VENDOR_DIR/VENDORING.md.bak"
60
61"$ROOT/Scripts/build-parser.sh"
62
63echo "Updated $OLD_SHA -> $SHA"
64echo "Compare: https://github.com/tree-sitter-grammars/tree-sitter-zig/compare/$OLD_SHA...$SHA"