diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-05-23 12:22:21 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-05-23 12:22:21 +0800 |
| commit | cf0a0f37bf07eb8e9435febe96e3adfe45004f91 (patch) | |
| tree | 480cb978564d77ac088a505704e7df34863e8cb7 /spec | |
| parent | 7bf2832d653027932fd845ba1462dd385ac32ab8 (diff) | |
| download | yuescript-cf0a0f37bf07eb8e9435febe96e3adfe45004f91.tar.gz yuescript-cf0a0f37bf07eb8e9435febe96e3adfe45004f91.tar.bz2 yuescript-cf0a0f37bf07eb8e9435febe96e3adfe45004f91.zip | |
Added break with value to with syntax.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/with.yue | 9 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 33 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 33 | ||||
| -rw-r--r-- | spec/outputs/with.lua | 27 |
4 files changed, 102 insertions, 0 deletions
diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue index 19b7be1..3fee48e 100644 --- a/spec/inputs/with.yue +++ b/spec/inputs/with.yue | |||
| @@ -152,4 +152,13 @@ do | |||
| 152 | return with {} | 152 | return with {} |
| 153 | return [123] | 153 | return [123] |
| 154 | 154 | ||
| 155 | do | ||
| 156 | f with item | ||
| 157 | if .id > 0 | ||
| 158 | break .content | ||
| 159 | |||
| 160 | a = with tb | ||
| 161 | if .v | ||
| 162 | break .a | ||
| 163 | |||
| 155 | nil | 164 | nil |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 177c33d..3ee20bb 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -694,6 +694,7 @@ local some_string = "Here is a string\n that has a line break in it." | |||
| 694 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 694 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
| 695 | local integer = 1000000 | 695 | local integer = 1000000 |
| 696 | local hex = 0xEFBBBF | 696 | local hex = 0xEFBBBF |
| 697 | local binary = 19 | ||
| 697 | local my_function | 698 | local my_function |
| 698 | my_function = function() end | 699 | my_function = function() end |
| 699 | my_function() | 700 | my_function() |
| @@ -2228,6 +2229,38 @@ local inventory = { | |||
| 2228 | } | 2229 | } |
| 2229 | } | 2230 | } |
| 2230 | } | 2231 | } |
| 2232 | local map | ||
| 2233 | map = function(arr, action) | ||
| 2234 | local _accum_0 = { } | ||
| 2235 | local _len_0 = 1 | ||
| 2236 | for _index_0 = 1, #arr do | ||
| 2237 | local item = arr[_index_0] | ||
| 2238 | _accum_0[_len_0] = action(item) | ||
| 2239 | _len_0 = _len_0 + 1 | ||
| 2240 | end | ||
| 2241 | return _accum_0 | ||
| 2242 | end | ||
| 2243 | local filter | ||
| 2244 | filter = function(arr, cond) | ||
| 2245 | local _accum_0 = { } | ||
| 2246 | local _len_0 = 1 | ||
| 2247 | for _index_0 = 1, #arr do | ||
| 2248 | local item = arr[_index_0] | ||
| 2249 | if cond(item) then | ||
| 2250 | _accum_0[_len_0] = item | ||
| 2251 | _len_0 = _len_0 + 1 | ||
| 2252 | end | ||
| 2253 | end | ||
| 2254 | return _accum_0 | ||
| 2255 | end | ||
| 2256 | local reduce | ||
| 2257 | reduce = function(arr, init, action) | ||
| 2258 | for _index_0 = 1, #arr do | ||
| 2259 | local item = arr[_index_0] | ||
| 2260 | init = action(init, item) | ||
| 2261 | end | ||
| 2262 | return init | ||
| 2263 | end | ||
| 2231 | print(reduce(filter(map({ | 2264 | print(reduce(filter(map({ |
| 2232 | 1, | 2265 | 1, |
| 2233 | 2, | 2266 | 2, |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 6349010..52204b7 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -694,6 +694,7 @@ local some_string = "这是一个字符串\n 并包括一个换行。" | |||
| 694 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 694 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
| 695 | local integer = 1000000 | 695 | local integer = 1000000 |
| 696 | local hex = 0xEFBBBF | 696 | local hex = 0xEFBBBF |
| 697 | local binary = 19 | ||
| 697 | local my_function | 698 | local my_function |
| 698 | my_function = function() end | 699 | my_function = function() end |
| 699 | my_function() | 700 | my_function() |
| @@ -2222,6 +2223,38 @@ local inventory = { | |||
| 2222 | } | 2223 | } |
| 2223 | } | 2224 | } |
| 2224 | } | 2225 | } |
| 2226 | local map | ||
| 2227 | map = function(arr, action) | ||
| 2228 | local _accum_0 = { } | ||
| 2229 | local _len_0 = 1 | ||
| 2230 | for _index_0 = 1, #arr do | ||
| 2231 | local item = arr[_index_0] | ||
| 2232 | _accum_0[_len_0] = action(item) | ||
| 2233 | _len_0 = _len_0 + 1 | ||
| 2234 | end | ||
| 2235 | return _accum_0 | ||
| 2236 | end | ||
| 2237 | local filter | ||
| 2238 | filter = function(arr, cond) | ||
| 2239 | local _accum_0 = { } | ||
| 2240 | local _len_0 = 1 | ||
| 2241 | for _index_0 = 1, #arr do | ||
| 2242 | local item = arr[_index_0] | ||
| 2243 | if cond(item) then | ||
| 2244 | _accum_0[_len_0] = item | ||
| 2245 | _len_0 = _len_0 + 1 | ||
| 2246 | end | ||
| 2247 | end | ||
| 2248 | return _accum_0 | ||
| 2249 | end | ||
| 2250 | local reduce | ||
| 2251 | reduce = function(arr, init, action) | ||
| 2252 | for _index_0 = 1, #arr do | ||
| 2253 | local item = arr[_index_0] | ||
| 2254 | init = action(init, item) | ||
| 2255 | end | ||
| 2256 | return init | ||
| 2257 | end | ||
| 2225 | print(reduce(filter(map({ | 2258 | print(reduce(filter(map({ |
| 2226 | 1, | 2259 | 1, |
| 2227 | 2, | 2260 | 2, |
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 1a795c1..20c5d44 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua | |||
| @@ -187,4 +187,31 @@ do | |||
| 187 | return _with_0[123] | 187 | return _with_0[123] |
| 188 | end | 188 | end |
| 189 | end | 189 | end |
| 190 | do | ||
| 191 | f((function() | ||
| 192 | local _with_0 = item | ||
| 193 | do | ||
| 194 | local _accum_0 | ||
| 195 | while true do | ||
| 196 | if _with_0.id > 0 then | ||
| 197 | _accum_0 = _with_0.content | ||
| 198 | break | ||
| 199 | end | ||
| 200 | end | ||
| 201 | _with_0 = _accum_0 | ||
| 202 | end | ||
| 203 | return _with_0 | ||
| 204 | end)()) | ||
| 205 | local a | ||
| 206 | local _with_0 = tb | ||
| 207 | local _accum_0 | ||
| 208 | while true do | ||
| 209 | if _with_0.v then | ||
| 210 | _accum_0 = _with_0.a | ||
| 211 | break | ||
| 212 | end | ||
| 213 | end | ||
| 214 | _with_0 = _accum_0 | ||
| 215 | a = _with_0 | ||
| 216 | end | ||
| 190 | return nil | 217 | return nil |
