From 514b9f97febe8920a78d6078b092fe84b859a963 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 7 Dec 2023 23:49:48 +0800 Subject: changed the if-assignment syntax to prevent some errors. --- spec/inputs/assign.yue | 2 +- spec/inputs/compile_doc.yue | 4 ++-- spec/inputs/cond.yue | 28 ++++++++++++++-------------- spec/inputs/destructure.yue | 8 ++++---- spec/inputs/existential.yue | 2 +- spec/inputs/macro_teal.yue | 2 +- spec/inputs/pipe.yue | 2 +- spec/inputs/plus.yue | 8 ++++---- spec/inputs/try_catch.yue | 4 ++-- spec/inputs/unicode/assign.yue | 2 +- spec/inputs/unicode/cond.yue | 28 ++++++++++++++-------------- spec/inputs/unicode/destructure.yue | 8 ++++---- spec/inputs/unicode/existential.yue | 2 +- spec/inputs/unicode/pipe.yue | 2 +- spec/inputs/unicode/plus.yue | 8 ++++---- spec/inputs/unicode/try_catch.yue | 4 ++-- 16 files changed, 57 insertions(+), 57 deletions(-) (limited to 'spec') diff --git a/spec/inputs/assign.yue b/spec/inputs/assign.yue index 8ae5cac..2c89a99 100644 --- a/spec/inputs/assign.yue +++ b/spec/inputs/assign.yue @@ -30,7 +30,7 @@ c, d = 1, 2 if true x = (do f! - 123) if f = getHandler! + 123) if f := getHandler! (using nil) <- _ diff --git a/spec/inputs/compile_doc.yue b/spec/inputs/compile_doc.yue index 4ce2b13..64d7d40 100644 --- a/spec/inputs/compile_doc.yue +++ b/spec/inputs/compile_doc.yue @@ -8,13 +8,13 @@ for [compiledFile, docFile] in *[ text = \read "*a" codes = [] for code in text\gmatch "```moonscript(.-)```" - if result, err = to_lua code, implicit_return_root: false, reserve_line_number: false + if result, err := to_lua code, implicit_return_root: false, reserve_line_number: false codes[] = result elseif not err\match "macro exporting module only accepts macro definition" print err os.exit 1 for code in text\gmatch "
(.-)
" - if result, err = to_lua code\gsub("<", "<")\gsub(">", ">"), implicit_return_root: false, reserve_line_number: false + if result, err := to_lua code\gsub("<", "<")\gsub(">", ">"), implicit_return_root: false, reserve_line_number: false codes[] = result else print err diff --git a/spec/inputs/cond.yue b/spec/inputs/cond.yue index 5bc6c9b..cce96df 100644 --- a/spec/inputs/cond.yue +++ b/spec/inputs/cond.yue @@ -52,18 +52,18 @@ elseif "just us" -- -if something = 10 +if something := 10 print something else print "else" -hello = if something = 10 +hello = if something := 10 print something else print "else" -hello = 5 + if something = 10 +hello = 5 + if something := 10 print something --- @@ -72,9 +72,9 @@ z = false _ = if false one -elseif x = true +elseif x := true two -elseif z = true +elseif z := true three else four @@ -82,17 +82,17 @@ else out = if false one -elseif x = true +elseif x := true two -elseif z = true +elseif z := true three else four kzy = -> - if something = true + if something := true 1 - elseif another = false + elseif another := false 2 --- @@ -152,7 +152,7 @@ dddd = {1,2,3} unless value do j = 100 - unless j = hi! + unless j := hi! error "not j!" ---------------- @@ -200,22 +200,22 @@ do elseif c d: e = tb -if :pi = math +if :pi := math print pi do local math - if :pi = math + if :pi := math print pi do - if _M = {} + if _M := {} :Thing = _M :a, :b = _M do global _M - if _M = {} + if _M := {} :Thing = _M :a, :b = _M diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index 73e4d33..5017ee1 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue @@ -94,18 +94,18 @@ do do thing = nil - if {a} = thing + if {a} := thing print a else print "nothing" thang = {1,2} - if {a,b} = thang + if {a,b} := thang print a,b - if {a,b} = thing + if {a,b} := thing print a,b - elseif {c,d} = thang + elseif {c,d} := thang print c,d else print "NO" diff --git a/spec/inputs/existential.yue b/spec/inputs/existential.yue index 27891dc..ec38897 100644 --- a/spec/inputs/existential.yue +++ b/spec/inputs/existential.yue @@ -16,7 +16,7 @@ with abc?!\func?! if \p? "abc" return 123 -if {:x} = a?.if?\then?(123)? @?\function 998 +if {:x} := a?.if?\then?(123)? @?\function 998 print x res = b.function\do!\while?("OK")\if("def",998)\f? diff --git a/spec/inputs/macro_teal.yue b/spec/inputs/macro_teal.yue index a443614..0cfd862 100644 --- a/spec/inputs/macro_teal.yue +++ b/spec/inputs/macro_teal.yue @@ -8,7 +8,7 @@ macro to_lua = (code)-> "require('yue').to_lua(#{code}, reserve_line_number:false, same_module:true)" macro trim = (name)-> - "if result = #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" + "if result := #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" export macro local = (decl, value = nil)-> import "yue" as {options:{:tl_enabled}} diff --git a/spec/inputs/pipe.yue b/spec/inputs/pipe.yue index 02f87a3..b5bae1d 100644 --- a/spec/inputs/pipe.yue +++ b/spec/inputs/pipe.yue @@ -11,7 +11,7 @@ b = 1 + 2 + (4 |> tostring |> print(1) or 123) -if x = 233 |> math.max 998 +if x := 233 |> math.max 998 print x with b |> create? "new" diff --git a/spec/inputs/plus.yue b/spec/inputs/plus.yue index e387090..9c500a4 100644 --- a/spec/inputs/plus.yue +++ b/spec/inputs/plus.yue @@ -8,13 +8,13 @@ c.repeat.if\then("xyz")\else res print @for,@@function 123 -if fcolor = message\match "<%w*>" then message = message\gsub "<%->", fcolor +if fcolor := message\match "<%w*>" then message = message\gsub "<%->", fcolor -message = message\gsub "<%->", fcolor if fcolor = message\match "<%w*>" +message = message\gsub "<%->", fcolor if fcolor := message\match "<%w*>" -valA = func! if func = getfunc! +valA = func! if func := getfunc! -local valA = func! if func = getfunc! +local valA = func! if func := getfunc! valB = do func = getfunc! diff --git a/spec/inputs/try_catch.yue b/spec/inputs/try_catch.yue index 96a87fc..ccb3f52 100644 --- a/spec/inputs/try_catch.yue +++ b/spec/inputs/try_catch.yue @@ -39,14 +39,14 @@ catch err print "OK" do - if success, result = try func "abc", 123 + if success, result := try func "abc", 123 print result success, result = try func "abc", 123 catch err print err - print result if success, result = try func "abc", 123 + print result if success, result := try func "abc", 123 catch err print err diff --git a/spec/inputs/unicode/assign.yue b/spec/inputs/unicode/assign.yue index 5392a92..6c03f86 100644 --- a/spec/inputs/unicode/assign.yue +++ b/spec/inputs/unicode/assign.yue @@ -30,7 +30,7 @@ else 变量x = (do 函数! - 123) if 函数 = 获取处理函数! + 123) if 函数 := 获取处理函数! (using nil) <- _无效变量 diff --git a/spec/inputs/unicode/cond.yue b/spec/inputs/unicode/cond.yue index fca6d60..dde5c99 100644 --- a/spec/inputs/unicode/cond.yue +++ b/spec/inputs/unicode/cond.yue @@ -52,18 +52,18 @@ elseif "只有我们" -- -if 某东西 = 10 +if 某东西 := 10 打印 某东西 else 打印 "其它" -你好 = if 某东西 = 10 +你好 = if 某东西 := 10 打印 某东西 else 打印 "其它" -你好 = 5 + if 某东西 = 10 +你好 = 5 + if 某东西 := 10 打印 某东西 --- @@ -72,9 +72,9 @@ z变量 = false _无效变量 = if false 一 -elseif 条件x = true +elseif 条件x := true 二 -elseif 条件z = true +elseif 条件z := true 三 else 四 @@ -82,17 +82,17 @@ else 输出 = if false 一 -elseif 条件x = true +elseif 条件x := true 二 -elseif 条件z = true +elseif 条件z := true 三 else 四 变量 = -> - if 某东西 = true + if 某东西 := true 1 - elseif 另一个 = false + elseif 另一个 := false 2 --- @@ -152,7 +152,7 @@ else do j变量 = 100 - unless j变量 = 嗨! + unless j变量 := 嗨! 错误 "不是 j变量!" ---------------- @@ -200,22 +200,22 @@ do elseif 条件c 字段d: 变量e = 变量tb -if :派 = 数学库 +if :派 := 数学库 打印 派 do local 数学库 - if :派 = 数学库 + if :派 := 数学库 打印 派 do - if _模块 = {} + if _模块 := {} :东西 = _模块 :a功能, :b功能 = _模块 do global _模块 - if _模块 = {} + if _模块 := {} :东西 = _模块 :a功能, :b功能 = _模块 diff --git a/spec/inputs/unicode/destructure.yue b/spec/inputs/unicode/destructure.yue index 5efdf82..3c3a369 100644 --- a/spec/inputs/unicode/destructure.yue +++ b/spec/inputs/unicode/destructure.yue @@ -92,18 +92,18 @@ do do 东西 = nil - if {元素a} = 东西 + if {元素a} := 东西 打印 元素a else 打印 "没东西" 东东 = {1,2} - if {元素a,元素b} = 东东 + if {元素a,元素b} := 东东 打印 元素a,元素b - if {元素a,元素b} = 东西 + if {元素a,元素b} := 东西 打印 元素a,元素b - elseif {元素c,元素d} = 东东 + elseif {元素c,元素d} := 东东 打印 元素c,元素d else 打印 "不" diff --git a/spec/inputs/unicode/existential.yue b/spec/inputs/unicode/existential.yue index 0e35a39..de65027 100644 --- a/spec/inputs/unicode/existential.yue +++ b/spec/inputs/unicode/existential.yue @@ -16,7 +16,7 @@ with 对象abc?!\函数?! if \函数p? "abc" return 123 -if {:x字段} = 对象a?.如果?\然后?(123)? @?\方法 998 +if {:x字段} := 对象a?.如果?\然后?(123)? @?\方法 998 打印 x字段 结果 = 对象b.方法\执行!\当?("没问题")\如果("默认",998)\函数? diff --git a/spec/inputs/unicode/pipe.yue b/spec/inputs/unicode/pipe.yue index 2cd41ee..085a2cf 100644 --- a/spec/inputs/unicode/pipe.yue +++ b/spec/inputs/unicode/pipe.yue @@ -11,7 +11,7 @@ 变量b = 1 + 2 + (4 |> tostring |> 打印(1) or 123) -if 变量x = 233 |> math.max 998 +if 变量x := 233 |> math.max 998 打印 变量x with 变量b |> 创建? "new" diff --git a/spec/inputs/unicode/plus.yue b/spec/inputs/unicode/plus.yue index b08974f..70b57bb 100644 --- a/spec/inputs/unicode/plus.yue +++ b/spec/inputs/unicode/plus.yue @@ -8,13 +8,13 @@ 打印 @循环, @@函数 123 -if 颜色 = 消息\匹配 "<%w*>" then 消息 = 消息\替换 "<%->", 颜色 +if 颜色 := 消息\匹配 "<%w*>" then 消息 = 消息\替换 "<%->", 颜色 -消息 = 消息\替换 "<%->", 颜色 if 颜色 = 消息\匹配 "<%w*>" +消息 = 消息\替换 "<%->", 颜色 if 颜色 := 消息\匹配 "<%w*>" -数值A = 方法! if 方法 = 获取方法! +数值A = 方法! if 方法 := 获取方法! -local 数值A = 方法! if 方法 = 获取方法! +local 数值A = 方法! if 方法 := 获取方法! 数值B = do 方法 = 获取方法! diff --git a/spec/inputs/unicode/try_catch.yue b/spec/inputs/unicode/try_catch.yue index 71e03ee..1156d8e 100644 --- a/spec/inputs/unicode/try_catch.yue +++ b/spec/inputs/unicode/try_catch.yue @@ -39,14 +39,14 @@ catch 错误 打印 "好的" do - if 成功, 结果 = try 函数 "abc", 123 + if 成功, 结果 := try 函数 "abc", 123 打印 结果 成功, 结果 = try 函数 "abc", 123 catch 错误 打印 错误 - 打印 结果 if 成功, 结果 = try 函数 "abc", 123 + 打印 结果 if 成功, 结果 := try 函数 "abc", 123 catch 错误 打印 错误 -- cgit v1.2.3-55-g6feb