diff options
Diffstat (limited to 'spec/inputs')
| -rw-r--r-- | spec/inputs/destructure.yue | 2 | ||||
| -rw-r--r-- | spec/inputs/macro_export.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/switch.yue | 54 | ||||
| -rw-r--r-- | spec/inputs/unicode/destructure.yue | 2 | ||||
| -rw-r--r-- | spec/inputs/unicode/macro_export.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/unicode/with.yue | 24 | ||||
| -rw-r--r-- | spec/inputs/with.yue | 24 |
7 files changed, 83 insertions, 31 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index 674dfe4..9f01a20 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue | |||
| @@ -94,7 +94,7 @@ do | |||
| 94 | -- | 94 | -- |
| 95 | 95 | ||
| 96 | do | 96 | do |
| 97 | with {a,b} = thing | 97 | with {a,b} := thing |
| 98 | print a, b | 98 | print a, b |
| 99 | 99 | ||
| 100 | 100 | ||
diff --git a/spec/inputs/macro_export.yue b/spec/inputs/macro_export.yue index cc7d459..75fd813 100644 --- a/spec/inputs/macro_export.yue +++ b/spec/inputs/macro_export.yue | |||
| @@ -38,8 +38,8 @@ export macro copy = (src, dst, ...)-> | |||
| 38 | " | 38 | " |
| 39 | do | 39 | do |
| 40 | local _src_, _dst_ | 40 | local _src_, _dst_ |
| 41 | with _dst_ = #{dst} | 41 | with _dst_ := #{dst} |
| 42 | with _src_ = #{src} | 42 | with _src_ := #{src} |
| 43 | #{table.concat for field in *{...} do " | 43 | #{table.concat for field in *{...} do " |
| 44 | _dst_.#{field} = _src_.#{field} | 44 | _dst_.#{field} = _src_.#{field} |
| 45 | "}" | 45 | "}" |
diff --git a/spec/inputs/switch.yue b/spec/inputs/switch.yue index 7ff3118..5097db3 100644 --- a/spec/inputs/switch.yue +++ b/spec/inputs/switch.yue | |||
| @@ -220,4 +220,56 @@ do | |||
| 220 | ] | 220 | ] |
| 221 | print "matched", sixth | 221 | print "matched", sixth |
| 222 | 222 | ||
| 223 | nil \ No newline at end of file | 223 | do |
| 224 | switch v := "hello" | ||
| 225 | when "hello" | ||
| 226 | print "matched hello" | ||
| 227 | else | ||
| 228 | print "not matched" | ||
| 229 | -- output: matched hello | ||
| 230 | |||
| 231 | do | ||
| 232 | f = -> "ok" | ||
| 233 | switch val := f! | ||
| 234 | when "ok" | ||
| 235 | print "it's ok" | ||
| 236 | -- output: it's ok | ||
| 237 | |||
| 238 | |||
| 239 | do | ||
| 240 | g = -> 42 | ||
| 241 | switch result := g! | ||
| 242 | when 1, 2 | ||
| 243 | print "small" | ||
| 244 | when 42 | ||
| 245 | print "life universe everything" | ||
| 246 | else | ||
| 247 | print "other #{result}" | ||
| 248 | -- output: life universe everything | ||
| 249 | |||
| 250 | do | ||
| 251 | check = -> | ||
| 252 | if true | ||
| 253 | "yes" | ||
| 254 | else | ||
| 255 | "no" | ||
| 256 | |||
| 257 | switch x := check! | ||
| 258 | when "yes" | ||
| 259 | print "affirmative" | ||
| 260 | else | ||
| 261 | print "negative" | ||
| 262 | -- output: affirmative | ||
| 263 | |||
| 264 | do | ||
| 265 | t = (): tb -> | ||
| 266 | tb = {a: 1} | ||
| 267 | tb.a = 2 | ||
| 268 | |||
| 269 | switch data := t! | ||
| 270 | when {a: 2} | ||
| 271 | print "matched" | ||
| 272 | else | ||
| 273 | print "not matched" | ||
| 274 | |||
| 275 | nil | ||
diff --git a/spec/inputs/unicode/destructure.yue b/spec/inputs/unicode/destructure.yue index 3c3a369..a5ffd5d 100644 --- a/spec/inputs/unicode/destructure.yue +++ b/spec/inputs/unicode/destructure.yue | |||
| @@ -84,7 +84,7 @@ do | |||
| 84 | -- | 84 | -- |
| 85 | 85 | ||
| 86 | do | 86 | do |
| 87 | with {元素a,元素b} = 东西 | 87 | with {元素a,元素b} := 东西 |
| 88 | 打印 元素a, 元素b | 88 | 打印 元素a, 元素b |
| 89 | 89 | ||
| 90 | 90 | ||
diff --git a/spec/inputs/unicode/macro_export.yue b/spec/inputs/unicode/macro_export.yue index 3c9a942..56571cd 100644 --- a/spec/inputs/unicode/macro_export.yue +++ b/spec/inputs/unicode/macro_export.yue | |||
| @@ -37,8 +37,8 @@ export macro 复制 = (源, 目标, ...)-> | |||
| 37 | " | 37 | " |
| 38 | do | 38 | do |
| 39 | local _源_, _目标_ | 39 | local _源_, _目标_ |
| 40 | with _目标_ = #{目标} | 40 | with _目标_ := #{目标} |
| 41 | with _源_ = #{源} | 41 | with _源_ := #{源} |
| 42 | #{table.concat for 字段 in *{...} do " | 42 | #{table.concat for 字段 in *{...} do " |
| 43 | _目标_.#{字段} = _源_.#{字段} | 43 | _目标_.#{字段} = _源_.#{字段} |
| 44 | "}" | 44 | "}" |
diff --git a/spec/inputs/unicode/with.yue b/spec/inputs/unicode/with.yue index ecbfdab..3c15add 100644 --- a/spec/inputs/unicode/with.yue +++ b/spec/inputs/unicode/with.yue | |||
| @@ -45,19 +45,19 @@ do | |||
| 45 | with 变量a | 45 | with 变量a |
| 46 | 打印 .世界 | 46 | 打印 .世界 |
| 47 | 47 | ||
| 48 | 模块 = with _模块 = {} | 48 | 模块 = with _模块 := {} |
| 49 | .事物 = "你好" | 49 | .事物 = "你好" |
| 50 | 50 | ||
| 51 | with 变量a, 变量b = 东西, 布 | 51 | with 变量a, 变量b := 东西, 布 |
| 52 | 打印 .世界 | 52 | 打印 .世界 |
| 53 | 53 | ||
| 54 | 变量x = with 变量a, 变量b = 1, 2 | 54 | 变量x = with 变量a, 变量b := 1, 2 |
| 55 | 打印 变量a + 变量b | 55 | 打印 变量a + 变量b |
| 56 | 56 | ||
| 57 | 打印 with 变量a, 变量b = 1, 2 | 57 | 打印 with 变量a, 变量b := 1, 2 |
| 58 | 打印 变量a + 变量b | 58 | 打印 变量a + 变量b |
| 59 | 59 | ||
| 60 | p = with 你好!.字段x, 世界!.字段y = 1, 2 | 60 | p = with 你好!.字段x, 世界!.字段y := 1, 2 |
| 61 | 打印 变量a + 变量b | 61 | 打印 变量a + 变量b |
| 62 | 62 | ||
| 63 | -- | 63 | -- |
| @@ -68,16 +68,16 @@ do | |||
| 68 | 变量x\大写! | 68 | 变量x\大写! |
| 69 | 69 | ||
| 70 | do | 70 | do |
| 71 | with 变量k = "乔" | 71 | with 变量k := "乔" |
| 72 | 打印 \大写! | 72 | 打印 \大写! |
| 73 | 73 | ||
| 74 | do | 74 | do |
| 75 | with 变量a,变量b,变量c = "", "", "" | 75 | with 变量a,变量b,变量c := "", "", "" |
| 76 | 打印 \大写! | 76 | 打印 \大写! |
| 77 | 77 | ||
| 78 | do | 78 | do |
| 79 | 变量a = "床铺" | 79 | 变量a = "床铺" |
| 80 | with 变量a,变量b,变量c = "", "", "" | 80 | with 变量a,变量b,变量c := "", "", "" |
| 81 | 打印 \大写! | 81 | 打印 \大写! |
| 82 | 82 | ||
| 83 | do | 83 | do |
| @@ -85,7 +85,7 @@ do | |||
| 85 | 打印 \大写! | 85 | 打印 \大写! |
| 86 | 86 | ||
| 87 | do | 87 | do |
| 88 | with 变量k.变量j = "乔" | 88 | with 变量k.变量j := "乔" |
| 89 | 打印 \大写! | 89 | 打印 \大写! |
| 90 | 90 | ||
| 91 | do | 91 | do |
| @@ -96,7 +96,7 @@ do | |||
| 96 | 96 | ||
| 97 | do | 97 | do |
| 98 | with 变量a | 98 | with 变量a |
| 99 | with .b = 2 | 99 | with .b := 2 |
| 100 | 打印 .c | 100 | 打印 .c |
| 101 | 101 | ||
| 102 | do | 102 | do |
| @@ -131,12 +131,12 @@ do | |||
| 131 | 131 | ||
| 132 | do | 132 | do |
| 133 | global 掩码 | 133 | global 掩码 |
| 134 | with? 掩码 = 实心矩形 宽: w, 高: h, 颜色: 0x66000000 | 134 | with? 掩码 := 实心矩形 宽: w, 高: h, 颜色: 0x66000000 |
| 135 | .触摸启用 = true | 135 | .触摸启用 = true |
| 136 | .吞噬触摸 = true | 136 | .吞噬触摸 = true |
| 137 | 137 | ||
| 138 | do | 138 | do |
| 139 | with? 掩码 = 实心矩形 宽: w, 高: h, 颜色: 0x66000000 | 139 | with? 掩码 := 实心矩形 宽: w, 高: h, 颜色: 0x66000000 |
| 140 | .触摸启用 = true | 140 | .触摸启用 = true |
| 141 | .吞噬触摸 = true | 141 | .吞噬触摸 = true |
| 142 | 142 | ||
diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue index dcd4053..c1cf3e3 100644 --- a/spec/inputs/with.yue +++ b/spec/inputs/with.yue | |||
| @@ -48,21 +48,21 @@ do | |||
| 48 | with a -- only one value allowed | 48 | with a -- only one value allowed |
| 49 | print .world | 49 | print .world |
| 50 | 50 | ||
| 51 | mod = with _M = {} | 51 | mod = with _M := {} |
| 52 | .Thing = "hi" | 52 | .Thing = "hi" |
| 53 | 53 | ||
| 54 | -- operate on a only | 54 | -- operate on a only |
| 55 | with a, b = something, pooh | 55 | with a, b := something, pooh |
| 56 | print .world | 56 | print .world |
| 57 | 57 | ||
| 58 | x = with a, b = 1, 2 | 58 | x = with a, b := 1, 2 |
| 59 | print a + b | 59 | print a + b |
| 60 | 60 | ||
| 61 | print with a, b = 1, 2 | 61 | print with a, b := 1, 2 |
| 62 | print a + b | 62 | print a + b |
| 63 | 63 | ||
| 64 | -- assignment lhs must be evaluated in the order they appear | 64 | -- assignment lhs must be evaluated in the order they appear |
| 65 | p = with hello!.x, world!.y = 1, 2 | 65 | p = with hello!.x, world!.y := 1, 2 |
| 66 | print a + b | 66 | print a + b |
| 67 | 67 | ||
| 68 | -- | 68 | -- |
| @@ -73,16 +73,16 @@ do | |||
| 73 | x\upper! | 73 | x\upper! |
| 74 | 74 | ||
| 75 | do | 75 | do |
| 76 | with k = "jo" | 76 | with k := "jo" |
| 77 | print \upper! | 77 | print \upper! |
| 78 | 78 | ||
| 79 | do | 79 | do |
| 80 | with a,b,c = "", "", "" | 80 | with a,b,c := "", "", "" |
| 81 | print \upper! | 81 | print \upper! |
| 82 | 82 | ||
| 83 | do | 83 | do |
| 84 | a = "bunk" | 84 | a = "bunk" |
| 85 | with a,b,c = "", "", "" | 85 | with a,b,c := "", "", "" |
| 86 | print \upper! | 86 | print \upper! |
| 87 | 87 | ||
| 88 | do | 88 | do |
| @@ -90,7 +90,7 @@ do | |||
| 90 | print \upper! | 90 | print \upper! |
| 91 | 91 | ||
| 92 | do | 92 | do |
| 93 | with k.j = "jo" | 93 | with k.j := "jo" |
| 94 | print \upper! | 94 | print \upper! |
| 95 | 95 | ||
| 96 | do | 96 | do |
| @@ -103,7 +103,7 @@ do | |||
| 103 | do | 103 | do |
| 104 | with a | 104 | with a |
| 105 | -- nested `with`s with assignments should change the scope correctly | 105 | -- nested `with`s with assignments should change the scope correctly |
| 106 | with .b = 2 | 106 | with .b := 2 |
| 107 | print .c | 107 | print .c |
| 108 | 108 | ||
| 109 | do | 109 | do |
| @@ -138,12 +138,12 @@ do | |||
| 138 | 138 | ||
| 139 | do | 139 | do |
| 140 | global mask | 140 | global mask |
| 141 | with? mask = SolidRect width: w, height: h, color: 0x66000000 | 141 | with? mask := SolidRect width: w, height: h, color: 0x66000000 |
| 142 | .touchEnabled = true | 142 | .touchEnabled = true |
| 143 | .swallowTouches = true | 143 | .swallowTouches = true |
| 144 | 144 | ||
| 145 | do | 145 | do |
| 146 | with? mask = SolidRect width: w, height: h, color: 0x66000000 | 146 | with? mask := SolidRect width: w, height: h, color: 0x66000000 |
| 147 | .touchEnabled = true | 147 | .touchEnabled = true |
| 148 | .swallowTouches = true | 148 | .swallowTouches = true |
| 149 | 149 | ||
