diff options
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | spec/inputs/assign.yue | 18 | ||||
-rw-r--r-- | spec/inputs/global.yue | 7 | ||||
-rw-r--r-- | spec/outputs/assign.lua | 25 | ||||
-rw-r--r-- | spec/outputs/class.lua | 44 | ||||
-rw-r--r-- | spec/outputs/codes_from_doc.lua | 28 | ||||
-rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 28 | ||||
-rw-r--r-- | spec/outputs/cond.lua | 14 | ||||
-rw-r--r-- | spec/outputs/global.lua | 6 | ||||
-rw-r--r-- | spec/outputs/macro.lua | 24 | ||||
-rw-r--r-- | spec/outputs/plus.lua | 3 | ||||
-rw-r--r-- | spec/outputs/unicode/cond.lua | 16 | ||||
-rw-r--r-- | spec/outputs/unicode/macro.lua | 6 | ||||
-rw-r--r-- | spec/outputs/unicode/plus.lua | 3 | ||||
-rw-r--r-- | spec/outputs/unicode/with.lua | 20 | ||||
-rw-r--r-- | spec/outputs/with.lua | 20 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 91 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp | 2 | ||||
-rw-r--r-- | src/yuescript/yuescript.h | 8 |
19 files changed, 198 insertions, 167 deletions
@@ -1,6 +1,6 @@ | |||
1 | MIT License | 1 | MIT License |
2 | 2 | ||
3 | Copyright (c) 2017-2025 Li Jin | 3 | Copyright (c) 2017-2025 Li Jin <dragon-fly@qq.com> |
4 | 4 | ||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | of this software and associated documentation files (the "Software"), to deal | 6 | of this software and associated documentation files (the "Software"), to deal |
diff --git a/spec/inputs/assign.yue b/spec/inputs/assign.yue index 514aeed..ad1eda3 100644 --- a/spec/inputs/assign.yue +++ b/spec/inputs/assign.yue | |||
@@ -109,4 +109,22 @@ do | |||
109 | val = 123 | 109 | val = 123 |
110 | a = b = c = val | 110 | a = b = c = val |
111 | 111 | ||
112 | do | ||
113 | -- update | ||
114 | a ..= "abc" | ||
115 | a //= 2 | ||
116 | a or= def | ||
117 | a and= false | ||
118 | a >>= 10 | ||
119 | a <<= 10 | ||
120 | a.b.c ??= 123 | ||
121 | a.b.c += 1 | ||
122 | a.b.c -= 2 | ||
123 | a.b.c *= 3 | ||
124 | a.b.c /= 4 | ||
125 | a.b.c %= 5 | ||
126 | a &= 6 | ||
127 | a |= 7 | ||
128 | a ^= 8 | ||
129 | |||
112 | nil | 130 | nil |
diff --git a/spec/inputs/global.yue b/spec/inputs/global.yue index 59cf764..ce1cc15 100644 --- a/spec/inputs/global.yue +++ b/spec/inputs/global.yue | |||
@@ -75,3 +75,10 @@ do | |||
75 | 75 | ||
76 | h = 100 | 76 | h = 100 |
77 | 77 | ||
78 | do | ||
79 | global x = y | ||
80 | global ^ | ||
81 | foobar = "all lowercase" | ||
82 | FooBar = "pascal case" | ||
83 | FOOBAR = "all uppercase" | ||
84 | |||
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua index 162a563..f889865 100644 --- a/spec/outputs/assign.lua +++ b/spec/outputs/assign.lua | |||
@@ -181,5 +181,30 @@ return _(function() | |||
181 | local b = val | 181 | local b = val |
182 | local c = val | 182 | local c = val |
183 | end | 183 | end |
184 | do | ||
185 | local a = a .. "abc" | ||
186 | a = a // 2 | ||
187 | a = a or def | ||
188 | a = a and false | ||
189 | a = a >> 10 | ||
190 | a = a << 10 | ||
191 | local _obj_0 = a.b | ||
192 | if _obj_0.c == nil then | ||
193 | _obj_0.c = 123 | ||
194 | end | ||
195 | local _obj_1 = a.b | ||
196 | _obj_1.c = _obj_1.c + 1 | ||
197 | local _obj_2 = a.b | ||
198 | _obj_2.c = _obj_2.c - 2 | ||
199 | local _obj_3 = a.b | ||
200 | _obj_3.c = _obj_3.c * 3 | ||
201 | local _obj_4 = a.b | ||
202 | _obj_4.c = _obj_4.c / 4 | ||
203 | local _obj_5 = a.b | ||
204 | _obj_5.c = _obj_5.c % 5 | ||
205 | a = a & 6 | ||
206 | a = a | 7 | ||
207 | a = a ^ 8 | ||
208 | end | ||
184 | return nil | 209 | return nil |
185 | end) | 210 | end) |
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index aaea33c..07efde4 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua | |||
@@ -1231,30 +1231,28 @@ do | |||
1231 | end | 1231 | end |
1232 | do | 1232 | do |
1233 | local CX | 1233 | local CX |
1234 | do | 1234 | local _class_0 |
1235 | local _class_0 | 1235 | local _base_0 = { } |
1236 | local _base_0 = { } | 1236 | if _base_0.__index == nil then |
1237 | if _base_0.__index == nil then | 1237 | _base_0.__index = _base_0 |
1238 | _base_0.__index = _base_0 | ||
1239 | end | ||
1240 | _class_0 = setmetatable({ | ||
1241 | __init = function(self) end, | ||
1242 | __base = _base_0, | ||
1243 | __name = "CX" | ||
1244 | }, { | ||
1245 | __index = _base_0, | ||
1246 | __call = function(cls, ...) | ||
1247 | local _self_0 = setmetatable({ }, _base_0) | ||
1248 | cls.__init(_self_0, ...) | ||
1249 | return _self_0 | ||
1250 | end | ||
1251 | }) | ||
1252 | _base_0.__class = _class_0 | ||
1253 | local self = _class_0; | ||
1254 | xa = 1 | ||
1255 | xb = 1 | ||
1256 | CX = _class_0 | ||
1257 | end | 1238 | end |
1239 | _class_0 = setmetatable({ | ||
1240 | __init = function(self) end, | ||
1241 | __base = _base_0, | ||
1242 | __name = "CX" | ||
1243 | }, { | ||
1244 | __index = _base_0, | ||
1245 | __call = function(cls, ...) | ||
1246 | local _self_0 = setmetatable({ }, _base_0) | ||
1247 | cls.__init(_self_0, ...) | ||
1248 | return _self_0 | ||
1249 | end | ||
1250 | }) | ||
1251 | _base_0.__class = _class_0 | ||
1252 | local self = _class_0; | ||
1253 | xa = 1 | ||
1254 | xb = 1 | ||
1255 | CX = _class_0 | ||
1258 | end | 1256 | end |
1259 | do | 1257 | do |
1260 | local CY | 1258 | local CY |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 74db469..27f8de5 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
@@ -467,8 +467,7 @@ local x = f() | |||
467 | local y = x | 467 | local y = x |
468 | local z = x | 468 | local z = x |
469 | do | 469 | do |
470 | local a | 470 | local a = 1 |
471 | a = 1 | ||
472 | local x, y, z | 471 | local x, y, z |
473 | print("forward declare all variables as locals") | 472 | print("forward declare all variables as locals") |
474 | x = function() | 473 | x = function() |
@@ -478,8 +477,7 @@ do | |||
478 | instance = Item:new() | 477 | instance = Item:new() |
479 | end | 478 | end |
480 | do | 479 | do |
481 | local X | 480 | local X = 1 |
482 | X = 1 | ||
483 | local B | 481 | local B |
484 | print("only forward declare upper case variables") | 482 | print("only forward declare upper case variables") |
485 | local a = 1 | 483 | local a = 1 |
@@ -488,19 +486,17 @@ end | |||
488 | do | 486 | do |
489 | a = 1 | 487 | a = 1 |
490 | print("declare all variables as globals") | 488 | print("declare all variables as globals") |
491 | local x | ||
492 | x = function() | 489 | x = function() |
493 | return 1 + y + z | 490 | return 1 + y + z |
494 | end | 491 | end |
495 | local y, z = 2, 3 | 492 | y, z = 2, 3 |
496 | end | 493 | end |
497 | do | 494 | do |
498 | X = 1 | 495 | X = 1 |
499 | print("only declare upper case variables as globals") | 496 | print("only declare upper case variables as globals") |
500 | local a = 1 | 497 | local a = 1 |
501 | local B = 2 | 498 | B = 2 |
502 | local Temp | 499 | local Temp = "a local value" |
503 | Temp = "a local value" | ||
504 | end | 500 | end |
505 | local thing = { | 501 | local thing = { |
506 | 1, | 502 | 1, |
@@ -2478,8 +2474,7 @@ local x = f() | |||
2478 | local y = x | 2474 | local y = x |
2479 | local z = x | 2475 | local z = x |
2480 | do | 2476 | do |
2481 | local a | 2477 | local a = 1 |
2482 | a = 1 | ||
2483 | local x, y, z | 2478 | local x, y, z |
2484 | print("forward declare all variables as locals") | 2479 | print("forward declare all variables as locals") |
2485 | x = function() | 2480 | x = function() |
@@ -2489,8 +2484,7 @@ do | |||
2489 | instance = Item:new() | 2484 | instance = Item:new() |
2490 | end | 2485 | end |
2491 | do | 2486 | do |
2492 | local X | 2487 | local X = 1 |
2493 | X = 1 | ||
2494 | local B | 2488 | local B |
2495 | print("only forward declare upper case variables") | 2489 | print("only forward declare upper case variables") |
2496 | local a = 1 | 2490 | local a = 1 |
@@ -2499,19 +2493,17 @@ end | |||
2499 | do | 2493 | do |
2500 | a = 1 | 2494 | a = 1 |
2501 | print("declare all variables as globals") | 2495 | print("declare all variables as globals") |
2502 | local x | ||
2503 | x = function() | 2496 | x = function() |
2504 | return 1 + y + z | 2497 | return 1 + y + z |
2505 | end | 2498 | end |
2506 | local y, z = 2, 3 | 2499 | y, z = 2, 3 |
2507 | end | 2500 | end |
2508 | do | 2501 | do |
2509 | X = 1 | 2502 | X = 1 |
2510 | print("only declare upper case variables as globals") | 2503 | print("only declare upper case variables as globals") |
2511 | local a = 1 | 2504 | local a = 1 |
2512 | local B = 2 | 2505 | B = 2 |
2513 | local Temp | 2506 | local Temp = "a local value" |
2514 | Temp = "a local value" | ||
2515 | end | 2507 | end |
2516 | local thing = { | 2508 | local thing = { |
2517 | 1, | 2509 | 1, |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 1a10555..ffa0483 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
@@ -467,8 +467,7 @@ local x = f() | |||
467 | local y = x | 467 | local y = x |
468 | local z = x | 468 | local z = x |
469 | do | 469 | do |
470 | local a | 470 | local a = 1 |
471 | a = 1 | ||
472 | local x, y, z | 471 | local x, y, z |
473 | print("预先声明后续所有变量为局部变量") | 472 | print("预先声明后续所有变量为局部变量") |
474 | x = function() | 473 | x = function() |
@@ -478,8 +477,7 @@ do | |||
478 | instance = Item:new() | 477 | instance = Item:new() |
479 | end | 478 | end |
480 | do | 479 | do |
481 | local X | 480 | local X = 1 |
482 | X = 1 | ||
483 | local B | 481 | local B |
484 | print("只预先声明后续大写的变量为局部变量") | 482 | print("只预先声明后续大写的变量为局部变量") |
485 | local a = 1 | 483 | local a = 1 |
@@ -488,19 +486,17 @@ end | |||
488 | do | 486 | do |
489 | a = 1 | 487 | a = 1 |
490 | print("预先声明所有变量为全局变量") | 488 | print("预先声明所有变量为全局变量") |
491 | local x | ||
492 | x = function() | 489 | x = function() |
493 | return 1 + y + z | 490 | return 1 + y + z |
494 | end | 491 | end |
495 | local y, z = 2, 3 | 492 | y, z = 2, 3 |
496 | end | 493 | end |
497 | do | 494 | do |
498 | x = 1 | 495 | x = 1 |
499 | print("只预先声明大写的变量为全局变量") | 496 | print("只预先声明大写的变量为全局变量") |
500 | local a = 1 | 497 | local a = 1 |
501 | local B = 2 | 498 | B = 2 |
502 | local Temp | 499 | local Temp = "一个局部值" |
503 | Temp = "一个局部值" | ||
504 | end | 500 | end |
505 | local thing = { | 501 | local thing = { |
506 | 1, | 502 | 1, |
@@ -2472,8 +2468,7 @@ local x = f() | |||
2472 | local y = x | 2468 | local y = x |
2473 | local z = x | 2469 | local z = x |
2474 | do | 2470 | do |
2475 | local a | 2471 | local a = 1 |
2476 | a = 1 | ||
2477 | local x, y, z | 2472 | local x, y, z |
2478 | print("预先声明后续所有变量为局部变量") | 2473 | print("预先声明后续所有变量为局部变量") |
2479 | x = function() | 2474 | x = function() |
@@ -2483,8 +2478,7 @@ do | |||
2483 | instance = Item:new() | 2478 | instance = Item:new() |
2484 | end | 2479 | end |
2485 | do | 2480 | do |
2486 | local X | 2481 | local X = 1 |
2487 | X = 1 | ||
2488 | local B | 2482 | local B |
2489 | print("只预先声明后续大写的变量为局部变量") | 2483 | print("只预先声明后续大写的变量为局部变量") |
2490 | local a = 1 | 2484 | local a = 1 |
@@ -2493,19 +2487,17 @@ end | |||
2493 | do | 2487 | do |
2494 | a = 1 | 2488 | a = 1 |
2495 | print("预先声明所有变量为全局变量") | 2489 | print("预先声明所有变量为全局变量") |
2496 | local x | ||
2497 | x = function() | 2490 | x = function() |
2498 | return 1 + y + z | 2491 | return 1 + y + z |
2499 | end | 2492 | end |
2500 | local y, z = 2, 3 | 2493 | y, z = 2, 3 |
2501 | end | 2494 | end |
2502 | do | 2495 | do |
2503 | x = 1 | 2496 | x = 1 |
2504 | print("只预先声明大写的变量为全局变量") | 2497 | print("只预先声明大写的变量为全局变量") |
2505 | local a = 1 | 2498 | local a = 1 |
2506 | local B = 2 | 2499 | B = 2 |
2507 | local Temp | 2500 | local Temp = "一个局部值" |
2508 | Temp = "一个局部值" | ||
2509 | end | 2501 | end |
2510 | local thing = { | 2502 | local thing = { |
2511 | 1, | 2503 | 1, |
diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua index 083419a..e194909 100644 --- a/spec/outputs/cond.lua +++ b/spec/outputs/cond.lua | |||
@@ -313,14 +313,12 @@ do | |||
313 | end | 313 | end |
314 | end | 314 | end |
315 | do | 315 | do |
316 | do | 316 | local _des_0 = { } |
317 | local _des_0 = { } | 317 | if _des_0 then |
318 | if _des_0 then | 318 | _M = _des_0 |
319 | _M = _des_0 | 319 | local Thing = _M.Thing |
320 | local Thing = _M.Thing | 320 | local _obj_0 = _M |
321 | local _obj_0 = _M | 321 | a, b = _obj_0.a, _obj_0.b |
322 | a, b = _obj_0.a, _obj_0.b | ||
323 | end | ||
324 | end | 322 | end |
325 | end | 323 | end |
326 | do | 324 | do |
diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index 7e74387..54a21a9 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua | |||
@@ -87,3 +87,9 @@ do | |||
87 | end | 87 | end |
88 | local h = 100 | 88 | local h = 100 |
89 | end | 89 | end |
90 | do | ||
91 | x = y | ||
92 | local foobar = "all lowercase" | ||
93 | FooBar = "pascal case" | ||
94 | FOOBAR = "all uppercase" | ||
95 | end | ||
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index aa74ed9..4d31574 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua | |||
@@ -191,13 +191,11 @@ end | |||
191 | do | 191 | do |
192 | local a = 8 | 192 | local a = 8 |
193 | a = (function() | 193 | a = (function() |
194 | local a | 194 | local a = 1 |
195 | a = 1 | ||
196 | return a + 1 | 195 | return a + 1 |
197 | end)() | 196 | end)() |
198 | a = a + (function() | 197 | a = a + (function() |
199 | local a | 198 | local a = 1 |
200 | a = 1 | ||
201 | return a + 1 | 199 | return a + 1 |
202 | end)() | 200 | end)() |
203 | print(a) | 201 | print(a) |
@@ -274,18 +272,12 @@ local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()): | |||
274 | end)):Destroy() | 272 | end)):Destroy() |
275 | do | 273 | do |
276 | do | 274 | do |
277 | local _1 | 275 | local _1 = origin.transform.root.gameObject:Parents() |
278 | _1 = origin.transform.root.gameObject:Parents() | 276 | local _2 = _1:Descendants() |
279 | local _2 | 277 | local _3 = _2:SelectEnable() |
280 | _2 = _1:Descendants() | 278 | local _4 = _3:SelectVisible() |
281 | local _3 | 279 | local _5 = _4:TagEqual("fx") |
282 | _3 = _2:SelectEnable() | 280 | local _6 = _5:Where(function(x) |
283 | local _4 | ||
284 | _4 = _3:SelectVisible() | ||
285 | local _5 | ||
286 | _5 = _4:TagEqual("fx") | ||
287 | local _6 | ||
288 | _6 = _5:Where(function(x) | ||
289 | return x.name:EndsWith("(Clone)") | 281 | return x.name:EndsWith("(Clone)") |
290 | end) | 282 | end) |
291 | _6:Destroy() | 283 | _6:Destroy() |
diff --git a/spec/outputs/plus.lua b/spec/outputs/plus.lua index bd89bfe..dda0660 100644 --- a/spec/outputs/plus.lua +++ b/spec/outputs/plus.lua | |||
@@ -65,7 +65,6 @@ backpack = { | |||
65 | local start = { | 65 | local start = { |
66 | something = "cold" | 66 | something = "cold" |
67 | } | 67 | } |
68 | local bathe | 68 | local bathe = { |
69 | bathe = { | ||
70 | on = "fire" | 69 | on = "fire" |
71 | } | 70 | } |
diff --git a/spec/outputs/unicode/cond.lua b/spec/outputs/unicode/cond.lua index 7229001..5e86228 100644 --- a/spec/outputs/unicode/cond.lua +++ b/spec/outputs/unicode/cond.lua | |||
@@ -314,15 +314,13 @@ do | |||
314 | end | 314 | end |
315 | end | 315 | end |
316 | do | 316 | do |
317 | do | 317 | local _des_0 = { } |
318 | local _des_0 = { } | 318 | if _des_0 then |
319 | if _des_0 then | 319 | __u6a21_u5757 = _des_0 |
320 | __u6a21_u5757 = _des_0 | 320 | local _u4e1c_u897f = __u6a21_u5757["东西"] |
321 | local _u4e1c_u897f = __u6a21_u5757["东西"] | 321 | local a_u529f_u80fd, b_u529f_u80fd |
322 | local a_u529f_u80fd, b_u529f_u80fd | 322 | local _obj_0 = __u6a21_u5757 |
323 | local _obj_0 = __u6a21_u5757 | 323 | a_u529f_u80fd, b_u529f_u80fd = _obj_0["a功能"], _obj_0["b功能"] |
324 | a_u529f_u80fd, b_u529f_u80fd = _obj_0["a功能"], _obj_0["b功能"] | ||
325 | end | ||
326 | end | 324 | end |
327 | end | 325 | end |
328 | do | 326 | do |
diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua index e2195e4..099080f 100644 --- a/spec/outputs/unicode/macro.lua +++ b/spec/outputs/unicode/macro.lua | |||
@@ -167,13 +167,11 @@ end | |||
167 | do | 167 | do |
168 | local _u53d8_u91cfa = 8 | 168 | local _u53d8_u91cfa = 8 |
169 | _u53d8_u91cfa = (function() | 169 | _u53d8_u91cfa = (function() |
170 | local _u53d8_u91cfa | 170 | local _u53d8_u91cfa = 1 |
171 | _u53d8_u91cfa = 1 | ||
172 | return _u53d8_u91cfa + 1 | 171 | return _u53d8_u91cfa + 1 |
173 | end)() | 172 | end)() |
174 | _u53d8_u91cfa = _u53d8_u91cfa + (function() | 173 | _u53d8_u91cfa = _u53d8_u91cfa + (function() |
175 | local _u53d8_u91cfa | 174 | local _u53d8_u91cfa = 1 |
176 | _u53d8_u91cfa = 1 | ||
177 | return _u53d8_u91cfa + 1 | 175 | return _u53d8_u91cfa + 1 |
178 | end)() | 176 | end)() |
179 | _u6253_u5370(_u53d8_u91cfa) | 177 | _u6253_u5370(_u53d8_u91cfa) |
diff --git a/spec/outputs/unicode/plus.lua b/spec/outputs/unicode/plus.lua index 75e4aac..adce62e 100644 --- a/spec/outputs/unicode/plus.lua +++ b/spec/outputs/unicode/plus.lua | |||
@@ -67,7 +67,6 @@ _u80cc_u5305 = { | |||
67 | local _u5f00_u59cb = { | 67 | local _u5f00_u59cb = { |
68 | ["东西"] = "冷" | 68 | ["东西"] = "冷" |
69 | } | 69 | } |
70 | local _u6d17_u6fa1 | 70 | local _u6d17_u6fa1 = { |
71 | _u6d17_u6fa1 = { | ||
72 | ["在"] = "火" | 71 | ["在"] = "火" |
73 | } | 72 | } |
diff --git a/spec/outputs/unicode/with.lua b/spec/outputs/unicode/with.lua index 7a5ba00..3a32a27 100644 --- a/spec/outputs/unicode/with.lua +++ b/spec/outputs/unicode/with.lua | |||
@@ -161,17 +161,15 @@ do | |||
161 | } | 161 | } |
162 | end | 162 | end |
163 | do | 163 | do |
164 | do | 164 | local _with_0 = _u5b9e_u5fc3_u77e9_u5f62({ |
165 | local _with_0 = _u5b9e_u5fc3_u77e9_u5f62({ | 165 | ["宽"] = w, |
166 | ["宽"] = w, | 166 | ["高"] = h, |
167 | ["高"] = h, | 167 | ["颜色"] = 0x66000000 |
168 | ["颜色"] = 0x66000000 | 168 | }) |
169 | }) | 169 | _u63a9_u7801 = _with_0 |
170 | _u63a9_u7801 = _with_0 | 170 | if _with_0 ~= nil then |
171 | if _with_0 ~= nil then | 171 | _with_0["触摸启用"] = true |
172 | _with_0["触摸启用"] = true | 172 | _with_0["吞噬触摸"] = true |
173 | _with_0["吞噬触摸"] = true | ||
174 | end | ||
175 | end | 173 | end |
176 | end | 174 | end |
177 | do | 175 | do |
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 5d33bdb..1a795c1 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua | |||
@@ -158,17 +158,15 @@ do | |||
158 | } | 158 | } |
159 | end | 159 | end |
160 | do | 160 | do |
161 | do | 161 | local _with_0 = SolidRect({ |
162 | local _with_0 = SolidRect({ | 162 | width = w, |
163 | width = w, | 163 | height = h, |
164 | height = h, | 164 | color = 0x66000000 |
165 | color = 0x66000000 | 165 | }) |
166 | }) | 166 | mask = _with_0 |
167 | mask = _with_0 | 167 | if _with_0 ~= nil then |
168 | if _with_0 ~= nil then | 168 | _with_0.touchEnabled = true |
169 | _with_0.touchEnabled = true | 169 | _with_0.swallowTouches = true |
170 | _with_0.swallowTouches = true | ||
171 | end | ||
172 | end | 170 | end |
173 | end | 171 | end |
174 | do | 172 | do |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index e7fe0c0..e3c9d31 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
76 | }; | 76 | }; |
77 | 77 | ||
78 | const std::string_view version = "0.27.0"sv; | 78 | const std::string_view version = "0.27.2"sv; |
79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
80 | 80 | ||
81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
@@ -437,7 +437,6 @@ private: | |||
437 | #endif | 437 | #endif |
438 | std::unique_ptr<std::unordered_map<std::string, VarType>> vars; | 438 | std::unique_ptr<std::unordered_map<std::string, VarType>> vars; |
439 | std::unique_ptr<std::unordered_set<std::string>> allows; | 439 | std::unique_ptr<std::unordered_set<std::string>> allows; |
440 | std::unique_ptr<std::unordered_set<std::string>> globals; | ||
441 | }; | 440 | }; |
442 | std::list<Scope> _scopes; | 441 | std::list<Scope> _scopes; |
443 | static const std::string Empty; | 442 | static const std::string Empty; |
@@ -516,10 +515,8 @@ private: | |||
516 | int mode = int(std::isupper(name[0]) ? GlobalMode::Capital : GlobalMode::Any); | 515 | int mode = int(std::isupper(name[0]) ? GlobalMode::Capital : GlobalMode::Any); |
517 | const auto& current = _scopes.back(); | 516 | const auto& current = _scopes.back(); |
518 | if (int(current.mode) >= mode) { | 517 | if (int(current.mode) >= mode) { |
519 | if (!current.globals) { | 518 | isDefined = true; |
520 | isDefined = true; | 519 | current.vars->insert_or_assign(name, VarType::Global); |
521 | current.vars->insert_or_assign(name, VarType::Global); | ||
522 | } | ||
523 | } | 520 | } |
524 | decltype(_scopes.back().allows.get()) allows = nullptr; | 521 | decltype(_scopes.back().allows.get()) allows = nullptr; |
525 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { | 522 | for (auto it = _scopes.rbegin(); it != _scopes.rend(); ++it) { |
@@ -892,10 +889,6 @@ private: | |||
892 | void addGlobalVar(const std::string& name, ast_node* x) { | 889 | void addGlobalVar(const std::string& name, ast_node* x) { |
893 | if (isLocal(name)) throw CompileError("can not declare a local variable to be global"sv, x); | 890 | if (isLocal(name)) throw CompileError("can not declare a local variable to be global"sv, x); |
894 | auto& scope = _scopes.back(); | 891 | auto& scope = _scopes.back(); |
895 | if (!scope.globals) { | ||
896 | scope.globals = std::make_unique<std::unordered_set<std::string>>(); | ||
897 | } | ||
898 | scope.globals->insert(name); | ||
899 | scope.vars->insert_or_assign(name, VarType::Global); | 892 | scope.vars->insert_or_assign(name, VarType::Global); |
900 | } | 893 | } |
901 | 894 | ||
@@ -1486,7 +1479,7 @@ private: | |||
1486 | } | 1479 | } |
1487 | } | 1480 | } |
1488 | 1481 | ||
1489 | bool isPureBackcall(Exp_t* exp) const { | 1482 | bool isPurePipeChain(Exp_t* exp) const { |
1490 | return exp->opValues.empty() && exp->pipeExprs.size() > 1; | 1483 | return exp->opValues.empty() && exp->pipeExprs.size() > 1; |
1491 | } | 1484 | } |
1492 | 1485 | ||
@@ -1869,7 +1862,7 @@ private: | |||
1869 | } | 1862 | } |
1870 | } else if (expList->exprs.size() == 1) { | 1863 | } else if (expList->exprs.size() == 1) { |
1871 | auto exp = static_cast<Exp_t*>(expList->exprs.back()); | 1864 | auto exp = static_cast<Exp_t*>(expList->exprs.back()); |
1872 | if (isPureBackcall(exp)) { | 1865 | if (isPurePipeChain(exp)) { |
1873 | transformExp(exp, out, ExpUsage::Common); | 1866 | transformExp(exp, out, ExpUsage::Common); |
1874 | break; | 1867 | break; |
1875 | } | 1868 | } |
@@ -2061,7 +2054,7 @@ private: | |||
2061 | } | 2054 | } |
2062 | } | 2055 | } |
2063 | 2056 | ||
2064 | void transformAssignment(ExpListAssign_t* assignment, str_list& out, bool optionalDestruct = false) { | 2057 | bool transformAssignment(ExpListAssign_t* assignment, str_list& out, bool optionalDestruct = false) { |
2065 | checkAssignable(assignment->expList); | 2058 | checkAssignable(assignment->expList); |
2066 | BLOCK_START | 2059 | BLOCK_START |
2067 | auto assign = ast_cast<Assign_t>(assignment->action); | 2060 | auto assign = ast_cast<Assign_t>(assignment->action); |
@@ -2176,7 +2169,7 @@ private: | |||
2176 | temp.push_back(indent() + "end"s + nll(assignment)); | 2169 | temp.push_back(indent() + "end"s + nll(assignment)); |
2177 | } | 2170 | } |
2178 | out.push_back(join(temp)); | 2171 | out.push_back(join(temp)); |
2179 | return; | 2172 | return false; |
2180 | BLOCK_END | 2173 | BLOCK_END |
2181 | } | 2174 | } |
2182 | { | 2175 | { |
@@ -2248,7 +2241,7 @@ private: | |||
2248 | transformAssignment(afterAssignment, temp); | 2241 | transformAssignment(afterAssignment, temp); |
2249 | } | 2242 | } |
2250 | out.push_back(join(temp)); | 2243 | out.push_back(join(temp)); |
2251 | return; | 2244 | return false; |
2252 | } else if (ast_is<TableAppendingOp_t>(chainValue->items.back())) { | 2245 | } else if (ast_is<TableAppendingOp_t>(chainValue->items.back())) { |
2253 | str_list temp; | 2246 | str_list temp; |
2254 | auto [beforeAssignment, afterAssignment] = splitAssignment(); | 2247 | auto [beforeAssignment, afterAssignment] = splitAssignment(); |
@@ -2300,7 +2293,7 @@ private: | |||
2300 | transformAssignment(afterAssignment, temp); | 2293 | transformAssignment(afterAssignment, temp); |
2301 | } | 2294 | } |
2302 | out.push_back(join(temp)); | 2295 | out.push_back(join(temp)); |
2303 | return; | 2296 | return false; |
2304 | } else { | 2297 | } else { |
2305 | break; | 2298 | break; |
2306 | } | 2299 | } |
@@ -2322,7 +2315,7 @@ private: | |||
2322 | std::string preDefine = getPreDefineLine(assignment); | 2315 | std::string preDefine = getPreDefineLine(assignment); |
2323 | transformIf(ifNode, out, ExpUsage::Assignment, assignList); | 2316 | transformIf(ifNode, out, ExpUsage::Assignment, assignList); |
2324 | out.back().insert(0, preDefine); | 2317 | out.back().insert(0, preDefine); |
2325 | return; | 2318 | return false; |
2326 | } | 2319 | } |
2327 | case id<Switch_t>(): { | 2320 | case id<Switch_t>(): { |
2328 | auto switchNode = static_cast<Switch_t*>(value); | 2321 | auto switchNode = static_cast<Switch_t*>(value); |
@@ -2330,7 +2323,7 @@ private: | |||
2330 | std::string preDefine = getPreDefineLine(assignment); | 2323 | std::string preDefine = getPreDefineLine(assignment); |
2331 | transformSwitch(switchNode, out, ExpUsage::Assignment, assignList); | 2324 | transformSwitch(switchNode, out, ExpUsage::Assignment, assignList); |
2332 | out.back().insert(0, preDefine); | 2325 | out.back().insert(0, preDefine); |
2333 | return; | 2326 | return false; |
2334 | } | 2327 | } |
2335 | case id<With_t>(): { | 2328 | case id<With_t>(): { |
2336 | auto withNode = static_cast<With_t*>(value); | 2329 | auto withNode = static_cast<With_t*>(value); |
@@ -2338,7 +2331,7 @@ private: | |||
2338 | std::string preDefine = getPreDefineLine(assignment); | 2331 | std::string preDefine = getPreDefineLine(assignment); |
2339 | transformWith(withNode, out, expList); | 2332 | transformWith(withNode, out, expList); |
2340 | out.back().insert(0, preDefine); | 2333 | out.back().insert(0, preDefine); |
2341 | return; | 2334 | return false; |
2342 | } | 2335 | } |
2343 | case id<Do_t>(): { | 2336 | case id<Do_t>(): { |
2344 | auto expList = assignment->expList.get(); | 2337 | auto expList = assignment->expList.get(); |
@@ -2346,7 +2339,7 @@ private: | |||
2346 | std::string preDefine = getPreDefineLine(assignment); | 2339 | std::string preDefine = getPreDefineLine(assignment); |
2347 | transformDo(doNode, out, ExpUsage::Assignment, expList); | 2340 | transformDo(doNode, out, ExpUsage::Assignment, expList); |
2348 | out.back().insert(0, preDefine); | 2341 | out.back().insert(0, preDefine); |
2349 | return; | 2342 | return false; |
2350 | } | 2343 | } |
2351 | case id<Comprehension_t>(): { | 2344 | case id<Comprehension_t>(): { |
2352 | auto comp = static_cast<Comprehension_t*>(value); | 2345 | auto comp = static_cast<Comprehension_t*>(value); |
@@ -2358,42 +2351,42 @@ private: | |||
2358 | } else { | 2351 | } else { |
2359 | transformComprehension(comp, out, ExpUsage::Assignment, expList); | 2352 | transformComprehension(comp, out, ExpUsage::Assignment, expList); |
2360 | } | 2353 | } |
2361 | return; | 2354 | return false; |
2362 | } | 2355 | } |
2363 | case id<TblComprehension_t>(): { | 2356 | case id<TblComprehension_t>(): { |
2364 | auto expList = assignment->expList.get(); | 2357 | auto expList = assignment->expList.get(); |
2365 | std::string preDefine = getPreDefineLine(assignment); | 2358 | std::string preDefine = getPreDefineLine(assignment); |
2366 | transformTblComprehension(static_cast<TblComprehension_t*>(value), out, ExpUsage::Assignment, expList); | 2359 | transformTblComprehension(static_cast<TblComprehension_t*>(value), out, ExpUsage::Assignment, expList); |
2367 | out.back().insert(0, preDefine); | 2360 | out.back().insert(0, preDefine); |
2368 | return; | 2361 | return false; |
2369 | } | 2362 | } |
2370 | case id<For_t>(): { | 2363 | case id<For_t>(): { |
2371 | auto expList = assignment->expList.get(); | 2364 | auto expList = assignment->expList.get(); |
2372 | std::string preDefine = getPreDefineLine(assignment); | 2365 | std::string preDefine = getPreDefineLine(assignment); |
2373 | transformForInPlace(static_cast<For_t*>(value), out, expList); | 2366 | transformForInPlace(static_cast<For_t*>(value), out, expList); |
2374 | out.back().insert(0, preDefine); | 2367 | out.back().insert(0, preDefine); |
2375 | return; | 2368 | return false; |
2376 | } | 2369 | } |
2377 | case id<ForEach_t>(): { | 2370 | case id<ForEach_t>(): { |
2378 | auto expList = assignment->expList.get(); | 2371 | auto expList = assignment->expList.get(); |
2379 | std::string preDefine = getPreDefineLine(assignment); | 2372 | std::string preDefine = getPreDefineLine(assignment); |
2380 | transformForEachInPlace(static_cast<ForEach_t*>(value), out, expList); | 2373 | transformForEachInPlace(static_cast<ForEach_t*>(value), out, expList); |
2381 | out.back().insert(0, preDefine); | 2374 | out.back().insert(0, preDefine); |
2382 | return; | 2375 | return false; |
2383 | } | 2376 | } |
2384 | case id<ClassDecl_t>(): { | 2377 | case id<ClassDecl_t>(): { |
2385 | auto expList = assignment->expList.get(); | 2378 | auto expList = assignment->expList.get(); |
2386 | std::string preDefine = getPreDefineLine(assignment); | 2379 | std::string preDefine = getPreDefineLine(assignment); |
2387 | transformClassDecl(static_cast<ClassDecl_t*>(value), out, ExpUsage::Assignment, expList); | 2380 | transformClassDecl(static_cast<ClassDecl_t*>(value), out, ExpUsage::Assignment, expList); |
2388 | out.back().insert(0, preDefine); | 2381 | out.back().insert(0, preDefine); |
2389 | return; | 2382 | return false; |
2390 | } | 2383 | } |
2391 | case id<While_t>(): { | 2384 | case id<While_t>(): { |
2392 | auto expList = assignment->expList.get(); | 2385 | auto expList = assignment->expList.get(); |
2393 | std::string preDefine = getPreDefineLine(assignment); | 2386 | std::string preDefine = getPreDefineLine(assignment); |
2394 | transformWhileInPlace(static_cast<While_t*>(value), out, expList); | 2387 | transformWhileInPlace(static_cast<While_t*>(value), out, expList); |
2395 | out.back().insert(0, preDefine); | 2388 | out.back().insert(0, preDefine); |
2396 | return; | 2389 | return false; |
2397 | } | 2390 | } |
2398 | case id<TableLit_t>(): { | 2391 | case id<TableLit_t>(): { |
2399 | auto tableLit = static_cast<TableLit_t*>(value); | 2392 | auto tableLit = static_cast<TableLit_t*>(value); |
@@ -2402,7 +2395,7 @@ private: | |||
2402 | std::string preDefine = getPreDefineLine(assignment); | 2395 | std::string preDefine = getPreDefineLine(assignment); |
2403 | transformSpreadTable(tableLit->values.objects(), out, ExpUsage::Assignment, expList, false); | 2396 | transformSpreadTable(tableLit->values.objects(), out, ExpUsage::Assignment, expList, false); |
2404 | out.back().insert(0, preDefine); | 2397 | out.back().insert(0, preDefine); |
2405 | return; | 2398 | return false; |
2406 | } | 2399 | } |
2407 | break; | 2400 | break; |
2408 | } | 2401 | } |
@@ -2413,31 +2406,31 @@ private: | |||
2413 | std::string preDefine = getPreDefineLine(assignment); | 2406 | std::string preDefine = getPreDefineLine(assignment); |
2414 | transformSpreadTable(tableBlock->values.objects(), out, ExpUsage::Assignment, expList, false); | 2407 | transformSpreadTable(tableBlock->values.objects(), out, ExpUsage::Assignment, expList, false); |
2415 | out.back().insert(0, preDefine); | 2408 | out.back().insert(0, preDefine); |
2416 | return; | 2409 | return false; |
2417 | } | 2410 | } |
2418 | break; | 2411 | break; |
2419 | } | 2412 | } |
2420 | } | 2413 | } |
2421 | auto exp = ast_cast<Exp_t>(value); | 2414 | auto exp = ast_cast<Exp_t>(value); |
2422 | BREAK_IF(!exp); | 2415 | BREAK_IF(!exp); |
2423 | if (isPureBackcall(exp)) { | 2416 | if (isPurePipeChain(exp)) { |
2424 | auto expList = assignment->expList.get(); | 2417 | auto expList = assignment->expList.get(); |
2425 | transformExp(exp, out, ExpUsage::Assignment, expList); | 2418 | transformExp(exp, out, ExpUsage::Assignment, expList); |
2426 | return; | 2419 | return false; |
2427 | } else if (isPureNilCoalesed(exp)) { | 2420 | } else if (isPureNilCoalesed(exp)) { |
2428 | auto expList = assignment->expList.get(); | 2421 | auto expList = assignment->expList.get(); |
2429 | transformNilCoalesedExp(exp, out, ExpUsage::Assignment, expList); | 2422 | transformNilCoalesedExp(exp, out, ExpUsage::Assignment, expList); |
2430 | return; | 2423 | return false; |
2431 | } else if (auto unary = unaryGeneratingAnonFunc(exp)) { | 2424 | } else if (auto unary = unaryGeneratingAnonFunc(exp)) { |
2432 | std::string preDefine = getPreDefineLine(assignment); | 2425 | std::string preDefine = getPreDefineLine(assignment); |
2433 | auto expList = assignment->expList.get(); | 2426 | auto expList = assignment->expList.get(); |
2434 | transformUnaryExp(unary, out, ExpUsage::Assignment, expList); | 2427 | transformUnaryExp(unary, out, ExpUsage::Assignment, expList); |
2435 | out.back().insert(0, preDefine); | 2428 | out.back().insert(0, preDefine); |
2436 | return; | 2429 | return false; |
2437 | } else if (isConditionChaining(exp)) { | 2430 | } else if (isConditionChaining(exp)) { |
2438 | auto expList = assignment->expList.get(); | 2431 | auto expList = assignment->expList.get(); |
2439 | transformExp(exp, out, ExpUsage::Assignment, expList); | 2432 | transformExp(exp, out, ExpUsage::Assignment, expList); |
2440 | return; | 2433 | return false; |
2441 | } | 2434 | } |
2442 | auto singleVal = singleValueFrom(exp); | 2435 | auto singleVal = singleValueFrom(exp); |
2443 | BREAK_IF(!singleVal); | 2436 | BREAK_IF(!singleVal); |
@@ -2451,13 +2444,13 @@ private: | |||
2451 | std::string preDefine = getPreDefineLine(assignment); | 2444 | std::string preDefine = getPreDefineLine(assignment); |
2452 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList, false, optionalDestruct); | 2445 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList, false, optionalDestruct); |
2453 | out.back().insert(0, preDefine); | 2446 | out.back().insert(0, preDefine); |
2454 | return; | 2447 | return false; |
2455 | } | 2448 | } |
2456 | case ChainType::HasKeyword: | 2449 | case ChainType::HasKeyword: |
2457 | case ChainType::HasUnicode: | 2450 | case ChainType::HasUnicode: |
2458 | case ChainType::Macro: | 2451 | case ChainType::Macro: |
2459 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList); | 2452 | transformChainValue(chainValue, out, ExpUsage::Assignment, expList); |
2460 | return; | 2453 | return false; |
2461 | case ChainType::Common: | 2454 | case ChainType::Common: |
2462 | case ChainType::EndWithEOP: | 2455 | case ChainType::EndWithEOP: |
2463 | case ChainType::Metatable: | 2456 | case ChainType::Metatable: |
@@ -2468,6 +2461,7 @@ private: | |||
2468 | auto info = extractDestructureInfo(assignment, false, optionalDestruct); | 2461 | auto info = extractDestructureInfo(assignment, false, optionalDestruct); |
2469 | if (info.destructures.empty()) { | 2462 | if (info.destructures.empty()) { |
2470 | transformAssignmentCommon(assignment, out); | 2463 | transformAssignmentCommon(assignment, out); |
2464 | return true; | ||
2471 | } else { | 2465 | } else { |
2472 | auto x = assignment; | 2466 | auto x = assignment; |
2473 | str_list temp; | 2467 | str_list temp; |
@@ -2733,6 +2727,7 @@ private: | |||
2733 | } | 2727 | } |
2734 | out.push_back(join(temp)); | 2728 | out.push_back(join(temp)); |
2735 | } | 2729 | } |
2730 | return false; | ||
2736 | } | 2731 | } |
2737 | 2732 | ||
2738 | void transformAssignItem(ast_node* value, str_list& out) { | 2733 | void transformAssignItem(ast_node* value, str_list& out) { |
@@ -5313,7 +5308,7 @@ private: | |||
5313 | if (auto valueList = returnNode->valueList.as<ExpListLow_t>()) { | 5308 | if (auto valueList = returnNode->valueList.as<ExpListLow_t>()) { |
5314 | if (valueList->exprs.size() == 1) { | 5309 | if (valueList->exprs.size() == 1) { |
5315 | auto exp = static_cast<Exp_t*>(valueList->exprs.back()); | 5310 | auto exp = static_cast<Exp_t*>(valueList->exprs.back()); |
5316 | if (isPureBackcall(exp)) { | 5311 | if (isPurePipeChain(exp)) { |
5317 | transformExp(exp, out, ExpUsage::Return); | 5312 | transformExp(exp, out, ExpUsage::Return); |
5318 | return; | 5313 | return; |
5319 | } else if (isPureNilCoalesed(exp)) { | 5314 | } else if (isPureNilCoalesed(exp)) { |
@@ -9399,7 +9394,6 @@ private: | |||
9399 | auto classDecl = static_cast<ClassDecl_t*>(item); | 9394 | auto classDecl = static_cast<ClassDecl_t*>(item); |
9400 | if (classDecl->name) { | 9395 | if (classDecl->name) { |
9401 | if (auto var = classDecl->name->item.as<Variable_t>()) { | 9396 | if (auto var = classDecl->name->item.as<Variable_t>()) { |
9402 | markVarsGlobal(GlobalMode::Any); | ||
9403 | addGlobalVar(variableToString(var), classDecl->name->item); | 9397 | addGlobalVar(variableToString(var), classDecl->name->item); |
9404 | } | 9398 | } |
9405 | } | 9399 | } |
@@ -9414,7 +9408,6 @@ private: | |||
9414 | } | 9408 | } |
9415 | break; | 9409 | break; |
9416 | case id<GlobalValues_t>(): { | 9410 | case id<GlobalValues_t>(): { |
9417 | markVarsGlobal(GlobalMode::Any); | ||
9418 | auto values = global->item.to<GlobalValues_t>(); | 9411 | auto values = global->item.to<GlobalValues_t>(); |
9419 | if (values->valueList) { | 9412 | if (values->valueList) { |
9420 | auto expList = x->new_ptr<ExpList_t>(); | 9413 | auto expList = x->new_ptr<ExpList_t>(); |
@@ -10676,6 +10669,7 @@ private: | |||
10676 | 10669 | ||
10677 | void transformLocal(Local_t* local, str_list& out) { | 10670 | void transformLocal(Local_t* local, str_list& out) { |
10678 | str_list temp; | 10671 | str_list temp; |
10672 | bool defined = local->defined; | ||
10679 | if (!local->defined) { | 10673 | if (!local->defined) { |
10680 | local->defined = true; | 10674 | local->defined = true; |
10681 | transformLocalDef(local, temp); | 10675 | transformLocalDef(local, temp); |
@@ -10704,7 +10698,26 @@ private: | |||
10704 | assign->values.push_back(tableBlock); | 10698 | assign->values.push_back(tableBlock); |
10705 | } | 10699 | } |
10706 | assignment->action.set(assign); | 10700 | assignment->action.set(assign); |
10707 | transformAssignment(assignment, temp); | 10701 | bool oneLined = transformAssignment(assignment, temp); |
10702 | for (auto val : assign->values.objects()) { | ||
10703 | if (auto value = singleValueFrom(val)) { | ||
10704 | if (auto spValue = value->item.as<SimpleValue_t>()) { | ||
10705 | if (auto funLit = spValue->value.as<FunLit_t>()) { | ||
10706 | if (!funLit->noRecursion) { | ||
10707 | oneLined = false; | ||
10708 | } | ||
10709 | break; | ||
10710 | } | ||
10711 | } | ||
10712 | } | ||
10713 | } | ||
10714 | if (!defined && oneLined && temp.size() == 2) { | ||
10715 | auto pos = temp.back().find_first_not_of(" \t"sv); | ||
10716 | if (pos != std::string::npos) { | ||
10717 | temp.back().insert(pos, "local "); | ||
10718 | temp.pop_front(); | ||
10719 | } | ||
10720 | } | ||
10708 | } | 10721 | } |
10709 | break; | 10722 | break; |
10710 | } | 10723 | } |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 5993ed5..ceb1f7c 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -519,7 +519,7 @@ YueParser::YueParser() { | |||
519 | UpdateOp = | 519 | UpdateOp = |
520 | expr("..") | "//" | "or" | "and" | | 520 | expr("..") | "//" | "or" | "and" | |
521 | ">>" | "<<" | "??" | | 521 | ">>" | "<<" | "??" | |
522 | set("+-*/%&|"); | 522 | set("+-*/%&|^"); |
523 | 523 | ||
524 | Update = UpdateOp >> '=' >> space >> Exp; | 524 | Update = UpdateOp >> '=' >> space >> Exp; |
525 | 525 | ||
diff --git a/src/yuescript/yuescript.h b/src/yuescript/yuescript.h index ebe90cb..83a4350 100644 --- a/src/yuescript/yuescript.h +++ b/src/yuescript/yuescript.h | |||
@@ -187,10 +187,10 @@ local function dump(what) | |||
187 | depth = depth or 0 | 187 | depth = depth or 0 |
188 | local t = type(what) | 188 | local t = type(what) |
189 | if "string" == t then | 189 | if "string" == t then |
190 | return "\"" .. tostring(what) .. "\"\n" | 190 | return "\"" .. tostring(what) .. "\"" |
191 | elseif "table" == t then | 191 | elseif "table" == t then |
192 | if seen[what] then | 192 | if seen[what] then |
193 | return "recursion(" .. tostring(what) .. ")...\n" | 193 | return "recursion(" .. tostring(what) .. ")..." |
194 | end | 194 | end |
195 | seen[what] = true | 195 | seen[what] = true |
196 | depth = depth + 1 | 196 | depth = depth + 1 |
@@ -199,9 +199,9 @@ local function dump(what) | |||
199 | insert(lines, ('\t'):rep(depth) .. "[" .. tostring(k) .. "] = " .. _dump(v, depth)) | 199 | insert(lines, ('\t'):rep(depth) .. "[" .. tostring(k) .. "] = " .. _dump(v, depth)) |
200 | end | 200 | end |
201 | seen[what] = false | 201 | seen[what] = false |
202 | return "{\n" .. concat(lines) .. ('\t'):rep(depth - 1) .. "}\n" | 202 | return "{\n" .. concat(lines, "\n") .. "\n" .. ('\t'):rep(depth - 1) .. "}" |
203 | else | 203 | else |
204 | return tostring(what) .. "\n" | 204 | return tostring(what) |
205 | end | 205 | end |
206 | end | 206 | end |
207 | return _dump(what) | 207 | return _dump(what) |