forked from genotrance/nimtreesitter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenlang.nims
89 lines (73 loc) · 1.92 KB
/
genlang.nims
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
import ospaths, strutils, strformat
let
langs = @["bash", "c", "cpp", "css", "go", "html", "javascript",
"ocaml", "php", "python", "ruby", "rust", "typescript",
"agda", "c_sharp", "haskell", "java", "scala", "nim"]
broken = @["julia"]
var
gen = false
git = false
test = false
install = false
uninstall = false
clean = false
lib = false
for i in 3 .. paramCount():
echo paramStr(i)
case paramStr(i):
of "--gen":
gen = true
of "--git":
git = true
of "--test":
test = true
of "--uninstall":
uninstall = true
of "--clean":
clean = true
of "--lib":
lib = true
of "--install":
install = true
if clean:
withDir("treesitter"):
rmDir("treesitter")
if test:
withDir("treesitter"):
exec "nimble develop -y"
exec "nimble setup"
exec "nimble test"
for lang in langs:
let flang = "treesitter_" & lang
if gen:
mkDir(flang)
mkDir(flang/"tests")
for file in ["treesitter_lang.cfg", "treesitter_lang.nimble", "tests"/"ttreesitter_lang.nim"]:
let nfile = file.replace("lang", lang)
cpFile("lang"/file, flang/nfile)
writeFile(flang/nfile,
readFile(flang/nfile).
replace("${LANG}", lang).
replace("${HLANG}", lang.replace("_", "-")))
withDir(flang):
if clean:
rmDir("treesitter")
rmDir(flang)
if test:
exec "nimble develop -y"
exec "nimble setup"
exec "nimble test"
if install:
exec "nimble setup"
exec "nimble install"
if lib:
echo "build dynamic lib"
exec fmt"nim --app:lib c treesitter_{lang}/{lang}.nim"
if uninstall:
discard gorgeEx("nimble uninstall -y " & flang)
if git:
exec "git add " & flang & ".cfg"
exec "git add " & flang & ".nimble"
exec "git add -f tests/ttreesitter_" & lang & ".nim"
if uninstall:
discard gorgeEx("nimble uninstall -y treesitter")