forked from bakpakin/fennel.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fnl
executable file
·78 lines (70 loc) · 3.04 KB
/
build.fnl
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
#!/usr/bin/env fennel
(local unpack (or table.unpack _G.unpack))
(import-macros {: map-values} :bunko.macros)
(local {: keys} (require :bunko.table))
(local {: powerset} (require :bunko.set))
(local {: unkeys} (require :lib.utils))
(local {: write-lua-keywords-of-versions} (require :lib.write))
(local lua-versions (require :lib.lua-versions))
(fn usage [script-name synopsis ...]
"Print usage information."
(let [out io.stderr]
(-> [(string.format "Usage: %s %s" script-name synopsis) ...]
(#(table.concat $ "\n"))
(out:write))
(out:write "\n"))
(os.exit false))
(local commands {})
(local helps {})
(macro task [command args help & body]
"Define task to run."
`(do (tset helps ,command ,help)
(tset commands ,command (fn ,args ,(unpack body)))))
(macro shell-task [command help shell]
"Define simple shell task to run."
`(task ,command [] ,help (io.stderr:write (.. "Run " ,shell "\n"))
(let [(_# _# signal#) (os.execute ,shell)]
(os.exit signal#))))
(task :lua-keywords []
"Build syntax/fennel-lua.vim by scraping Lua reference manuals."
(let [target "syntax/fennel-lua.vim"
combinations-of-versions
(doto (icollect [_ versions (ipairs (powerset lua-versions))]
(let [versions (keys versions)]
(when (< 0 (length versions))
(doto versions table.sort))))
(table.sort (fn [l r] (match (values (length l) (length r))
(where (n m) (< m n)) true
(where (n m) (< n m)) false
_ (< (. l 1) (. r 1))))))]
(with-open [out (assert (io.open target :w))]
(out:write (.. "\" Vim syntax file\n"
"\" Language: Fennel\n"
"\" Last Change: " (os.date "%Y-%m-%d") "\n"
"\" Maintainer: NACAMURA Mitsuhiro <m15@m15a.dev>\n"
"\" URL: https://github.com/m15a/vim-fennel-syntax\n"
"\" License: MIT\n"
"\" NOTE: Automatically generated by build.fnl. DO NOT EDIT!\n"
"\n"
"if !exists('b:did_fennel_syntax')\n"
" finish\n"
"endif\n"
"\n"
"let s:lua_version = fennel#GetOption('lua_version', fennel#GetLuaVersion())\n"
"\n"))
(each [_ versions (ipairs combinations-of-versions)]
(write-lua-keywords-of-versions out (unkeys versions))))
(io.stderr:write (string.format "Generated %s\n" target))
(os.exit true)))
(shell-task :check-format
"Check Vim scripts are formatted."
"vint **/*.vim")
(let [script-name (. arg 0)
[command & rest] arg]
(match command
:lua-keywords (commands.lua-keywords)
:check-format (commands.check-format)
_ (usage script-name "COMMAND ARG...\n" "Commands:"
(map-values #(.. " " $ "\t" (. helps $))
(unpack (doto (keys commands)
(table.sort)))))))