diff options
Diffstat (limited to 'spec/inputs')
| -rw-r--r-- | spec/inputs/macro.yue | 54 | ||||
| -rw-r--r-- | spec/inputs/macro_export.yue | 31 | ||||
| -rw-r--r-- | spec/inputs/macro_teal.yue | 13 | ||||
| -rw-r--r-- | spec/inputs/macro_todo.yue | 7 | ||||
| -rw-r--r-- | spec/inputs/string.yue | 73 |
5 files changed, 140 insertions, 38 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 }" |
diff --git a/spec/inputs/macro_export.yue b/spec/inputs/macro_export.yue index 75fd813..22905b5 100644 --- a/spec/inputs/macro_export.yue +++ b/spec/inputs/macro_export.yue | |||
| @@ -8,13 +8,12 @@ export macro config = (debugging = true)-> | |||
| 8 | "" | 8 | "" |
| 9 | 9 | ||
| 10 | export macro showMacro = (name, res)-> | 10 | export macro showMacro = (name, res)-> |
| 11 | if debugMacro then " | 11 | if debugMacro then | |
| 12 | do | 12 | do |
| 13 | txt = #{res} | 13 | txt = #{res} |
| 14 | print '[macro ' .. #{name} .. ']' | 14 | print '[macro #{name}]' |
| 15 | print txt | 15 | print txt |
| 16 | txt | 16 | txt |
| 17 | " | ||
| 18 | else | 17 | else |
| 19 | res | 18 | res |
| 20 | 19 | ||
| @@ -35,14 +34,16 @@ export macro copy = (src, dst, ...)-> | |||
| 35 | src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_" | 34 | src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_" |
| 36 | "copy targets can not be _src_ or _dst_" | 35 | "copy targets can not be _src_ or _dst_" |
| 37 | ) | 36 | ) |
| 38 | " | 37 | copyFields = table.concat( |
| 39 | do | 38 | ["_dst_.#{field} = _src_.#{field}" for field in *{...}] |
| 40 | local _src_, _dst_ | 39 | "\n\t\t\t" |
| 41 | with _dst_ := #{dst} | 40 | ) |
| 42 | with _src_ := #{src} | 41 | | |
| 43 | #{table.concat for field in *{...} do " | 42 | do |
| 44 | _dst_.#{field} = _src_.#{field} | 43 | local _src_, _dst_ |
| 45 | "}" | 44 | with _dst_ := #{dst} |
| 45 | with _src_ := #{src} | ||
| 46 | #{copyFields} | ||
| 46 | 47 | ||
| 47 | export macro enum = (...) -> | 48 | export macro enum = (...) -> |
| 48 | items = {...} | 49 | items = {...} |
diff --git a/spec/inputs/macro_teal.yue b/spec/inputs/macro_teal.yue index 0cfd862..e51bcd7 100644 --- a/spec/inputs/macro_teal.yue +++ b/spec/inputs/macro_teal.yue | |||
| @@ -4,11 +4,16 @@ $ -> | |||
| 4 | options.target_extension = "tl" | 4 | options.target_extension = "tl" |
| 5 | package.path ..= ";./spec/lib/?.lua" | 5 | package.path ..= ";./spec/lib/?.lua" |
| 6 | 6 | ||
| 7 | macro to_lua = (code)-> | 7 | macro to_lua = (code)-> | |
| 8 | "require('yue').to_lua(#{code}, reserve_line_number:false, same_module:true)" | 8 | require('yue').to_lua #{code}, |
| 9 | reserve_line_number: false | ||
| 10 | same_module: true | ||
| 9 | 11 | ||
| 10 | macro trim = (name)-> | 12 | macro trim = (name)-> | |
| 11 | "if result := #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" | 13 | if result := #{name}\match '[\'"](.*)[\'"]' |
| 14 | result | ||
| 15 | else | ||
| 16 | #{name} | ||
| 12 | 17 | ||
| 13 | export macro local = (decl, value = nil)-> | 18 | export macro local = (decl, value = nil)-> |
| 14 | import "yue" as {options:{:tl_enabled}} | 19 | import "yue" as {options:{:tl_enabled}} |
diff --git a/spec/inputs/macro_todo.yue b/spec/inputs/macro_todo.yue index 752c9cb..c9c8f77 100644 --- a/spec/inputs/macro_todo.yue +++ b/spec/inputs/macro_todo.yue | |||
| @@ -5,9 +5,6 @@ export macro todoInner = (module, line, msg)-> | |||
| 5 | type: "lua" | 5 | type: "lua" |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | export macro todo = (msg)-> | 8 | export macro todo = (msg)-> | |
| 9 | if msg | 9 | $todoInner $FILE, $LINE#{msg and ", #{msg}" or ""} |
| 10 | "$todoInner $FILE, $LINE, #{msg}" | ||
| 11 | else | ||
| 12 | "$todoInner $FILE, $LINE" | ||
| 13 | 10 | ||
diff --git a/spec/inputs/string.yue b/spec/inputs/string.yue index f91383e..1f0fba8 100644 --- a/spec/inputs/string.yue +++ b/spec/inputs/string.yue | |||
| @@ -74,3 +74,76 @@ _ = "hello" | |||
| 74 | something"hello"\world! | 74 | something"hello"\world! |
| 75 | something "hello"\world! | 75 | something "hello"\world! |
| 76 | 76 | ||
| 77 | do | ||
| 78 | str = | | ||
| 79 | key: value | ||
| 80 | str = | | ||
| 81 | config: | ||
| 82 | enabled: true | ||
| 83 | level: 5 | ||
| 84 | str = | | ||
| 85 | header: start | ||
| 86 | |||
| 87 | footer: end | ||
| 88 | str = | | ||
| 89 | name: #{username} | ||
| 90 | str = | | ||
| 91 | count: #{total} items | ||
| 92 | str = | | ||
| 93 | user: #{name} | ||
| 94 | id: #{id} | ||
| 95 | str = | | ||
| 96 | path: "C:\\Program Files\\App" | ||
| 97 | desc: 'single "quote" test' | ||
| 98 | str = | | ||
| 99 | key: value | ||
| 100 | next: 123 | ||
| 101 | str = | | ||
| 102 | list: | ||
| 103 | - "one" | ||
| 104 | - "two" | ||
| 105 | str = | | ||
| 106 | -- comment | ||
| 107 | content text | ||
| 108 | -- comment | ||
| 109 | str = | | ||
| 110 | #{1 + 2} | ||
| 111 | #{2 + 3} | ||
| 112 | #{"a" .. "b"} | ||
| 113 | obj = | ||
| 114 | settings: | | ||
| 115 | mode: #{mode} | ||
| 116 | flags: | ||
| 117 | - #{flag1} | ||
| 118 | - default | ||
| 119 | fn = -> | | ||
| 120 | Hello | ||
| 121 | name: #{userName} | ||
| 122 | str = | | ||
| 123 | result: | ||
| 124 | status: #{if ok then "pass" else "fail"} | ||
| 125 | code: #{code} | ||
| 126 | summary = | | ||
| 127 | date: #{os.date()} | ||
| 128 | values: | ||
| 129 | - | ||
| 130 | a: #{aVal} | ||
| 131 | b: #{bVal or defaultB} | ||
| 132 | msg = send | | ||
| 133 | Hello, #{user}! | ||
| 134 | Today is #{os.date("%A")}. | ||
| 135 | desc = do | ||
| 136 | prefix = "Result" | ||
| 137 | | | ||
| 138 | #{prefix}: | ||
| 139 | value: #{compute!} | ||
| 140 | (| | ||
| 141 | 1 | ||
| 142 | 2 | ||
| 143 | 3 | ||
| 144 | |||
| 145 | |||
| 146 | export yaml = | | ||
| 147 | version: #{ver} | ||
| 148 | ok: true | ||
| 149 | |||
