aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/macro.yue
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/macro.yue')
-rw-r--r--spec/inputs/macro.yue38
1 files changed, 29 insertions, 9 deletions
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue
index 2dd15ac..366a3d9 100644
--- a/spec/inputs/macro.yue
+++ b/spec/inputs/macro.yue
@@ -69,9 +69,9 @@ $foreach $filter($map({1,2,3}, _ * 2), _ > 4), print _
69 69
70val = $pipe( 70val = $pipe(
71 {1, 2, 3} 71 {1, 2, 3}
72 $map(_ * 2) 72 [[$map(_ * 2)]]
73 $filter(_ > 4) 73 [[$filter(_ > 4)]]
74 $reduce(0, _1 + _2) 74 [[$reduce(0, _1 + _2)]]
75) 75)
76 76
77macro plus = (a, b)-> "#{a} + #{b}" 77macro plus = (a, b)-> "#{a} + #{b}"
@@ -110,8 +110,8 @@ do
110 a += $get_inner_hygienic! 110 a += $get_inner_hygienic!
111 print a 111 print a
112 112
113macro lua = (codes)-> { 113macro lua = (code)-> {
114 :codes 114 :code
115 type: "lua" 115 type: "lua"
116} 116}
117 117
@@ -136,7 +136,7 @@ macro def = (fname, ...)->
136 args = {...} 136 args = {...}
137 last = table.remove args 137 last = table.remove args
138 { 138 {
139 codes: $showMacro "def", "local function #{fname}(#{table.concat args, ', '}) 139 code: $showMacro "def", "local function #{fname}(#{table.concat args, ', '})
140 #{last} 140 #{last}
141end" 141end"
142 type: "lua" 142 type: "lua"
@@ -155,7 +155,7 @@ $def sel, a, b, c, [[
155$def dummy,[[]] 155$def dummy,[[]]
156 156
157macro insertComment = (text)-> { 157macro insertComment = (text)-> {
158 codes: "-- #{text\match '[\'"](.*)[\'"]'}" 158 code: "-- #{text\match '[\'"](.*)[\'"]'}"
159 type: "lua" 159 type: "lua"
160} 160}
161 161
@@ -239,7 +239,7 @@ macro chainC = (...)->
239 else 239 else
240 callable = itemCodes 240 callable = itemCodes
241 { 241 {
242 codes: $showMacro "chainC", callable 242 code: $showMacro "chainC", callable
243 type: "lua" 243 type: "lua"
244 } 244 }
245 245
@@ -253,7 +253,27 @@ $chainC(
253 Destroy! 253 Destroy!
254) 254)
255 255
256macro tb = -> "{'abc', a:123, call#:=> 998}"
257print $tb[1], $tb.a, ($tb)!, $tb!
258
259print "current line: #{ $LINE }"
260
261macro todoInner = (module, line, msg)->
262 print "TODO#{msg and ': ' .. msg or ''} in file #{module}, at line #{line}"
263 {
264 code: "-- TODO#{msg and ': ' .. msg or ''}"
265 type: "lua"
266 }
267
268macro todo = (msg)->
269 if msg
270 "$todoInner $MODULE, $LINE, #{msg}"
271 else
272 "$todoInner $MODULE, $LINE"
273
274$todo
275
256macro implicitReturnMacroIsAllowed = -> "print 'abc'\n123" 276macro implicitReturnMacroIsAllowed = -> "print 'abc'\n123"
257 277
258$implicitReturnMacroIsAllowed! 278$implicitReturnMacroIsAllowed
259 279