-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.sh
More file actions
executable file
·80 lines (71 loc) · 2.12 KB
/
gen.sh
File metadata and controls
executable file
·80 lines (71 loc) · 2.12 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -euo pipefail
ensure_upstream() {
local dest="upstream/$1"
local url="$2"
local rev="$3"
if [[ -d "$dest" ]]; then
git -C "$dest" fetch
else
git clone "$url" "$dest"
fi
git -C "$dest" checkout --force --quiet "$rev"
}
ensure_upstream tree-sitter https://github.com/tree-sitter/tree-sitter.git v0.20.0
ensure_upstream tree-sitter-json https://github.com/tree-sitter/tree-sitter-json.git v0.19.0
ensure_upstream tree-sitter-python https://github.com/tree-sitter/tree-sitter-python.git v0.19.0
go install modernc.org/ccgo/v3@v3.12.52
# Verify that gcc isn't secretly clang. This is a problem on macOS.
CC="${CC:-gcc}"
CCGO_CPP="${CCGO_CPP:-cpp}"
if "$CC" --version 2> /dev/null | grep clang &> /dev/null || \
"$CCGO_CPP" --version 2> /dev/null | grep clang &> /dev/null; then
echo "$CC and/or $CCGO_CPP are actually clang." 1>&2
echo "Set CC to a gcc compiler and CCGO_CPP to a gcc preprocessor." 1>&2
echo 1>&2
echo "On macOS:" 1>&2
echo 'brew install gcc && '\\ 1>&2
# shellcheck disable=SC2016
echo 'export CC="$(which gcc-11)" && '\\ 1>&2
# shellcheck disable=SC2016
echo 'export CCGO_CPP="$(which cpp-11)"' 1>&2
exit 1
fi
mkdir -p internal/lib
ccgo \
-pkgname=lib \
-export-defines '' \
-export-enums '' \
-export-externs X \
-export-structs S \
-export-fields '' \
-export-typedefs '' \
-trace-translation-units \
-o "internal/lib/treesitter_$(go env GOOS)_$(go env GOARCH).go" \
-I upstream/tree-sitter/lib/src \
-I upstream/tree-sitter/lib/include \
upstream/tree-sitter/lib/src/*.c
gen_parser() {
local name
name="$1"
shift
mkdir -p "internal/$name"
ccgo \
-pkgname="$name" \
-export-defines '' \
-export-enums '' \
-export-externs X \
-export-structs S \
-export-fields '' \
-export-typedefs '' \
-trace-translation-units \
-o "internal/$name/${name}_$(go env GOOS)_$(go env GOARCH).go" \
-I ./internal/lib \
-I upstream/tree-sitter/lib/include \
"$@"
}
gen_parser json \
upstream/tree-sitter-json/src/parser.c
gen_parser python \
upstream/tree-sitter-python/src/parser.c \
internal/python/patch/scanner.c