diff options
Diffstat (limited to 'spec/inputs/macro.yue')
-rw-r--r-- | spec/inputs/macro.yue | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue index 5d5f1a9..191f09f 100644 --- a/spec/inputs/macro.yue +++ b/spec/inputs/macro.yue | |||
@@ -60,6 +60,11 @@ macro NumAndStr = (num, str) -> | |||
60 | 60 | ||
61 | print $NumAndStr 123, 'xyz' | 61 | print $NumAndStr 123, 'xyz' |
62 | 62 | ||
63 | macro NumAndStr2 = (num`Num, str`SingleString) -> | | ||
64 | [#{num}, #{str}] | ||
65 | |||
66 | print $NumAndStr2 456, 'abc' | ||
67 | |||
63 | $asserts item == nil | 68 | $asserts item == nil |
64 | 69 | ||
65 | $myconfig false | 70 | $myconfig false |
@@ -100,13 +105,14 @@ macro filter = (items, action)-> | |||
100 | $showMacro "filter", "[_ for _ in *#{items} when #{action}]" | 105 | $showMacro "filter", "[_ for _ in *#{items} when #{action}]" |
101 | 106 | ||
102 | macro reduce = (items, def, action)-> | 107 | macro reduce = (items, def, action)-> |
103 | $showMacro "reduce", "if ##{items} == 0 | 108 | $showMacro "reduce", | |
104 | #{def} | 109 | if ##{items} == 0 |
105 | else | 110 | #{def} |
106 | _1 = #{def} | 111 | else |
107 | for _2 in *#{items} | 112 | _1 = #{def} |
108 | _1 = #{action} | 113 | for _2 in *#{items} |
109 | _1" | 114 | _1 = #{action} |
115 | _1 | ||
110 | 116 | ||
111 | macro foreach = (items, action)-> | 117 | macro foreach = (items, action)-> |
112 | $showMacro "foreach", "for _ in *#{items} | 118 | $showMacro "foreach", "for _ in *#{items} |
@@ -154,13 +160,15 @@ macro curry = (...)-> | |||
154 | f = $curry x,y,z,do | 160 | f = $curry x,y,z,do |
155 | print x,y,z | 161 | print x,y,z |
156 | 162 | ||
157 | macro get_inner = (var)-> "do | 163 | macro get_inner = (var)-> | |
158 | a = 1 | 164 | do |
159 | a + 1" | 165 | a = 1 |
166 | a + 1 | ||
160 | 167 | ||
161 | macro get_inner_hygienic = (var)-> "(-> | 168 | macro get_inner_hygienic = (var)-> | |
162 | local a = 1 | 169 | (-> |
163 | a + 1)!" | 170 | local a = 1 |
171 | a + 1)! | ||
164 | 172 | ||
165 | do | 173 | do |
166 | a = 8 | 174 | a = 8 |
@@ -196,6 +204,18 @@ end | |||
196 | 204 | ||
197 | print x | 205 | print x |
198 | 206 | ||
207 | import "yue" | ||
208 | macro lua = (code`YAMLMultiline) -> { | ||
209 | code: yue.loadstring(code)! | ||
210 | type: "lua" | ||
211 | } | ||
212 | |||
213 | $lua | | ||
214 | local function f2(a) | ||
215 | return a + 1 | ||
216 | end | ||
217 | x = x + f2(3) | ||
218 | |||
199 | macro def = (fname, ...)-> | 219 | macro def = (fname, ...)-> |
200 | args = {...} | 220 | args = {...} |
201 | last = table.remove args | 221 | last = table.remove args |
@@ -317,7 +337,13 @@ $chainC( | |||
317 | Destroy! | 337 | Destroy! |
318 | ) | 338 | ) |
319 | 339 | ||
320 | macro tb = -> "{'abc', a:123, <call>:=> 998}" | 340 | macro tb = -> | |
341 | { | ||
342 | 'abc' | ||
343 | a: 123 | ||
344 | <call>: => 998 | ||
345 | } | ||
346 | |||
321 | print $tb[1], $tb.a, ($tb)!, $tb! | 347 | print $tb[1], $tb.a, ($tb)!, $tb! |
322 | 348 | ||
323 | print "current line: #{ $LINE }" | 349 | print "current line: #{ $LINE }" |