aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-05-23 12:22:21 +0800
committerLi Jin <dragon-fly@qq.com>2025-05-23 12:22:21 +0800
commitcf0a0f37bf07eb8e9435febe96e3adfe45004f91 (patch)
tree480cb978564d77ac088a505704e7df34863e8cb7 /spec
parent7bf2832d653027932fd845ba1462dd385ac32ab8 (diff)
downloadyuescript-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.yue9
-rw-r--r--spec/outputs/codes_from_doc.lua33
-rw-r--r--spec/outputs/codes_from_doc_zh.lua33
-rw-r--r--spec/outputs/with.lua27
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
155do
156 f with item
157 if .id > 0
158 break .content
159
160 a = with tb
161 if .v
162 break .a
163
155nil 164nil
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."
694print("I am " .. tostring(math.random() * 100) .. "% sure.") 694print("I am " .. tostring(math.random() * 100) .. "% sure.")
695local integer = 1000000 695local integer = 1000000
696local hex = 0xEFBBBF 696local hex = 0xEFBBBF
697local binary = 19
697local my_function 698local my_function
698my_function = function() end 699my_function = function() end
699my_function() 700my_function()
@@ -2228,6 +2229,38 @@ local inventory = {
2228 } 2229 }
2229 } 2230 }
2230} 2231}
2232local map
2233map = 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
2242end
2243local filter
2244filter = 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
2255end
2256local reduce
2257reduce = 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
2263end
2231print(reduce(filter(map({ 2264print(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 并包括一个换行。"
694print("我有" .. tostring(math.random() * 100) .. "%的把握。") 694print("我有" .. tostring(math.random() * 100) .. "%的把握。")
695local integer = 1000000 695local integer = 1000000
696local hex = 0xEFBBBF 696local hex = 0xEFBBBF
697local binary = 19
697local my_function 698local my_function
698my_function = function() end 699my_function = function() end
699my_function() 700my_function()
@@ -2222,6 +2223,38 @@ local inventory = {
2222 } 2223 }
2223 } 2224 }
2224} 2225}
2226local map
2227map = 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
2236end
2237local filter
2238filter = 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
2249end
2250local reduce
2251reduce = 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
2257end
2225print(reduce(filter(map({ 2258print(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
189end 189end
190do
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
216end
190return nil 217return nil