-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcpp.fnl
82 lines (78 loc) · 1.93 KB
/
cpp.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
79
80
81
82
(local {:snippet s
:snippet_node sn
:text_node t
:insert_node i
:function_node f
:choice_node c
:dynamic_node d
:restore_node r}
(require :luasnip))
(local {:lambda l
:rep rep
:partial p
:match m
:nonempty n
:dynamic_lambda dl}
(require :luasnip.extras))
(local {:fmt fmt
:fmta fmta}
(require :luasnip.extras.fmt))
(local types
(require :luasnip.util.types))
(local conds
(require :luasnip.extras.conditions))
(local conds-expand
(require :luasnip.extras.conditions.expand))
(fn return-type [args]
(if (= (. args 1 1) :void)
""
(.. " -> " (. args 1 1) " ")))
(fn params [args snip old-state ...]
(let [nodes {}]
(if (or (= (. args 1 1) "")
(= (. args 1 1) :void))
(table.insert nodes (t ""))
(do
(each [index node-type
(-> (.. (. args 1 1) ",")
(: :gmatch "(.-)%s*,%s*")
vim.iter
(: :enumerate))]
(table.insert nodes (t (.. node-type " ")))
(table.insert nodes (i index (.. :param index)))
(table.insert nodes (t ", ")))
(table.remove nodes (length nodes))))
(sn nil nodes)))
[(s :func
(fmt "
std::function<{}({})> {} = [{}]({}){}{{
{}
}};
"
[;; return type
(i 1 :void)
;; param types
(i 2 :int)
;; name
(i 3 :func)
;; captures
(c 4 [(t "")
(t "&")
(t "=")])
(d 5 params [2])
(f return-type [1])
(i 0)]))
(s :magic
(fmt "
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
"
{}))
(s :main
(fmt "
int main() {{
{}
return 0;
}}
"
[(i 0)]))]