forked from tweag/topiary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-wasm-grammars.sh
executable file
·159 lines (136 loc) · 4.86 KB
/
update-wasm-grammars.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
set -eu
cd web-playground/public/scripts/
# We don't use mktemp because Tree-sitter doesn't work across disparate filesystems
WORKDIR=./tmp/
mkdir -p $WORKDIR
readonly WORKDIR
trap 'echo -e "${BLUE}Cleanup...${NC}"; rm -rf "${WORKDIR}" a.out.{js,wasm}' EXIT
BLUE="$(tput setaf 4)"
readonly BLUE
ORANGE="$(tput setaf 3)"
readonly ORANGE
GREEN="$(tput setaf 2)"
readonly GREEN
NC="$(tput sgr0)"
readonly NC
CONFIG=$(nickel export --format json "$(git rev-parse --show-toplevel)/topiary-config/languages.ncl")
readonly CONFIG
echo -e "${BLUE}Updating all Topiary grammars. This process can take a few minutes."
ref_for_language() {
echo "$CONFIG" | jq -r ".languages.$1.grammar.rev"
}
repo_for_language() {
echo "$CONFIG" | jq -r ".languages.$1.grammar.git"
}
json() {
echo -e "${BLUE}JSON: Fetching${NC}"
REPO=$(repo_for_language "json")
git clone "${REPO}" "${WORKDIR}/tree-sitter-json" &> /dev/null
REV=$(ref_for_language "json")
pushd "${WORKDIR}/tree-sitter-json" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}JSON: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-json"
echo -e "${GREEN}JSON: Done${NC}"
}
nickel() {
echo -e "${BLUE}Nickel: Fetching${NC}"
REPO=$(repo_for_language "nickel")
git clone "${REPO}" "${WORKDIR}/tree-sitter-nickel" &> /dev/null
REV=$(ref_for_language "nickel")
pushd "${WORKDIR}/tree-sitter-nickel" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}Nickel: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-nickel"
echo -e "${GREEN}Nickel: Done${NC}"
}
ocaml() {
echo -e "${BLUE}OCaml: Fetching${NC}"
REPO=$(repo_for_language "ocaml")
git clone "${REPO}" "${WORKDIR}/tree-sitter-ocaml" &> /dev/null
REV=$(ref_for_language "ocaml")
pushd "${WORKDIR}/tree-sitter-ocaml" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}OCaml: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-ocaml/ocaml"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-ocaml/interface/"
echo -e "${GREEN}OCaml: Done${NC}"
}
ocamllex() {
echo -e "${BLUE}OCamllex: Fetching${NC}"
REPO=$(repo_for_language "ocamllex")
git clone "${REPO}" "${WORKDIR}/tree-sitter-ocamllex" &> /dev/null
REV=$(ref_for_language "ocamllex")
pushd "${WORKDIR}/tree-sitter-ocamllex" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}OCamllex: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-ocamllex"
echo -e "${GREEN}Ocamllex: Done${NC}"
}
bash() {
echo -e "${BLUE}Bash: Fetching${NC}"
REPO=$(repo_for_language "bash")
git clone "${REPO}" "${WORKDIR}/tree-sitter-bash" &> /dev/null
REV=$(ref_for_language "bash")
pushd "${WORKDIR}/tree-sitter-bash" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}Bash: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-bash"
echo -e "${GREEN}Bash: Done${NC}"
}
rust() {
echo -e "${BLUE}Rust: Fetching${NC}"
REPO=$(repo_for_language "rust")
git clone "${REPO}" "${WORKDIR}/tree-sitter-rust" &> /dev/null
REV=$(ref_for_language "rust")
pushd "${WORKDIR}/tree-sitter-rust" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}Rust: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-rust"
echo -e "${GREEN}Rust: Done${NC}"
}
toml() {
echo -e "${BLUE}TOML: Fetching${NC}"
REPO=$(repo_for_language "toml")
git clone "${REPO}" "${WORKDIR}/tree-sitter-toml" &> /dev/null
REV=$(ref_for_language "toml")
pushd "${WORKDIR}/tree-sitter-toml" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}TOML: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-toml"
echo -e "${GREEN}TOML: Done${NC}"
}
tree-sitter-query() {
echo -e "${BLUE}Query: Fetching${NC}"
REPO=$(repo_for_language "tree_sitter_query")
git clone "${REPO}" "${WORKDIR}/tree-sitter-query" &> /dev/null
REV=$(ref_for_language "tree_sitter_query")
pushd "${WORKDIR}/tree-sitter-query" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}Query: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-query"
echo -e "${GREEN}Query: Done${NC}"
}
css() {
echo -e "${BLUE}CSS: Fetching${NC}"
REPO=$(repo_for_language "css")
git clone "${REPO}" "${WORKDIR}/tree-sitter-css" &> /dev/null
REV=$(ref_for_language "css")
pushd "${WORKDIR}/tree-sitter-css" &> /dev/null
git checkout "$REV" &> /dev/null
popd &> /dev/null
echo -e "${ORANGE}CSS: Building${NC}"
tree-sitter build --wasm "${WORKDIR}/tree-sitter-css"
echo -e "${GREEN}CSS: Done${NC}"
}
(trap 'kill 0' SIGINT; json & nickel & ocaml & ocamllex & bash & rust & toml & tree-sitter-query & css & wait)
echo -e "${GREEN}Done! All grammars have been updated${NC}"