-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgen.sh
More file actions
executable file
·50 lines (44 loc) · 1.39 KB
/
gen.sh
File metadata and controls
executable file
·50 lines (44 loc) · 1.39 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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
if ! command -v goyacc &>/dev/null; then
echo "installing goyacc"
if ! go install -v -mod=readonly golang.org/x/tools/cmd/goyacc@v0.30.0; then
echo "failed to install goyacc" >&2
exit 1
fi
fi
if ! command -v ragel &>/dev/null; then
install_cmd=()
if command -v apt &>/dev/null; then
install_cmd=(sudo apt-get install ragel)
elif command -v brew &>/dev/null; then
install_cmd=(env HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install ragel)
fi
installed=0
if ((${#install_cmd[@]} > 0)); then
echo "installing ragel: ${install_cmd[*]}"
"${install_cmd[@]}"
# shellcheck disable=SC2181
if [[ $? -eq 0 ]]; then
installed=1
fi
fi
if [[ $installed -eq 0 ]]; then
echo "please install ragel using your package manager" >&2
exit 1
fi
fi
echo "⚙️ generating lexer"
ragel -Z lexer.rl
# add autogenerated comment
sed -i.bak '1s#^#// Code generated by ragel. DO NOT EDIT.\n#' lexer.go
gofmt -w lexer.go
rm lexer.go.bak
echo "⚙️ generating parser"
goyacc -v y.output -o parser.gen.go -p rule parser.y
# add a new method to the interface generated by goyacc
sed -i.bak '/type ruleLexer interface {/a Result(n Rule)' parser.gen.go
gofmt -w parser.gen.go
rm parser.gen.go.bak
echo "✅ done!"