diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-05-23 15:07:45 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-05-23 15:07:45 +0800 |
| commit | 4ba4c90e711c6204aa40e38347c5a5a076d9370e (patch) | |
| tree | c929f1f5dc7002a65311db82abf4228aaa979925 | |
| parent | cf0a0f37bf07eb8e9435febe96e3adfe45004f91 (diff) | |
| download | yuescript-0.28.3.tar.gz yuescript-0.28.3.tar.bz2 yuescript-0.28.3.zip | |
Added `-` for implicit object.v0.28.3
Diffstat (limited to '')
| -rwxr-xr-x | doc/docs/doc/README.md | 63 | ||||
| -rwxr-xr-x | doc/docs/zh/doc/README.md | 64 | ||||
| -rw-r--r-- | spec/inputs/tables.yue | 18 | ||||
| -rw-r--r-- | spec/inputs/with.yue | 4 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 16 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 16 | ||||
| -rw-r--r-- | spec/outputs/tables.lua | 22 | ||||
| -rw-r--r-- | spec/outputs/with.lua | 30 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 4 |
9 files changed, 187 insertions, 50 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 0853391..58b37c0 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
| @@ -16,17 +16,17 @@ Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ]. | |||
| 16 | ### An Overview of YueScript | 16 | ### An Overview of YueScript |
| 17 | ```moonscript | 17 | ```moonscript |
| 18 | -- import syntax | 18 | -- import syntax |
| 19 | import "yue" as :p, :to_lua | 19 | import p, to_lua from "yue" |
| 20 | 20 | ||
| 21 | -- object literals | 21 | -- object literals |
| 22 | inventory = | 22 | inventory = |
| 23 | equipment: | 23 | equipment: |
| 24 | * "sword" | 24 | - "sword" |
| 25 | * "shield" | 25 | - "shield" |
| 26 | items: | 26 | items: |
| 27 | * name: "potion" | 27 | - name: "potion" |
| 28 | count: 10 | 28 | count: 10 |
| 29 | * name: "bread" | 29 | - name: "bread" |
| 30 | count: 3 | 30 | count: 3 |
| 31 | 31 | ||
| 32 | -- list comprehension | 32 | -- list comprehension |
| @@ -61,17 +61,17 @@ export 🌛 = "月之脚本" | |||
| 61 | <YueDisplay> | 61 | <YueDisplay> |
| 62 | <pre> | 62 | <pre> |
| 63 | -- import syntax | 63 | -- import syntax |
| 64 | import "yue" as :p, :to_lua | 64 | import p, to_lua from "yue" |
| 65 | 65 | ||
| 66 | -- object literals | 66 | -- object literals |
| 67 | inventory = | 67 | inventory = |
| 68 | equipment: | 68 | equipment: |
| 69 | * "sword" | 69 | - "sword" |
| 70 | * "shield" | 70 | - "shield" |
| 71 | items: | 71 | items: |
| 72 | * name: "potion" | 72 | - name: "potion" |
| 73 | count: 10 | 73 | count: 10 |
| 74 | * name: "bread" | 74 | - name: "bread" |
| 75 | count: 3 | 75 | count: 3 |
| 76 | 76 | ||
| 77 | -- list comprehension | 77 | -- list comprehension |
| @@ -752,34 +752,45 @@ a ??= false | |||
| 752 | 752 | ||
| 753 | ### Implicit Object | 753 | ### Implicit Object |
| 754 | 754 | ||
| 755 | You can write a list of implicit structures that starts with the symbol **\*** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent. | 755 | You can write a list of implicit structures that starts with the symbol **\*** or **-** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent. |
| 756 | |||
| 756 | ```moonscript | 757 | ```moonscript |
| 758 | -- assignment with implicit object | ||
| 757 | list = | 759 | list = |
| 758 | * 1 | 760 | * 1 |
| 759 | * 2 | 761 | * 2 |
| 760 | * 3 | 762 | * 3 |
| 761 | 763 | ||
| 764 | -- function call with implicit object | ||
| 762 | func | 765 | func |
| 763 | * 1 | 766 | * 1 |
| 764 | * 2 | 767 | * 2 |
| 765 | * 3 | 768 | * 3 |
| 766 | 769 | ||
| 770 | -- return with implicit object | ||
| 771 | f = -> | ||
| 772 | return | ||
| 773 | * 1 | ||
| 774 | * 2 | ||
| 775 | * 3 | ||
| 776 | |||
| 777 | -- table with implicit object | ||
| 767 | tb = | 778 | tb = |
| 768 | name: "abc" | 779 | name: "abc" |
| 769 | 780 | ||
| 770 | values: | 781 | values: |
| 771 | * "a" | 782 | - "a" |
| 772 | * "b" | 783 | - "b" |
| 773 | * "c" | 784 | - "c" |
| 774 | 785 | ||
| 775 | objects: | 786 | objects: |
| 776 | * name: "a" | 787 | - name: "a" |
| 777 | value: 1 | 788 | value: 1 |
| 778 | func: => @value + 1 | 789 | func: => @value + 1 |
| 779 | tb: | 790 | tb: |
| 780 | fieldA: 1 | 791 | fieldA: 1 |
| 781 | 792 | ||
| 782 | * name: "b" | 793 | - name: "b" |
| 783 | value: 2 | 794 | value: 2 |
| 784 | func: => @value + 2 | 795 | func: => @value + 2 |
| 785 | tb: { } | 796 | tb: { } |
| @@ -787,32 +798,42 @@ tb = | |||
| 787 | ``` | 798 | ``` |
| 788 | <YueDisplay> | 799 | <YueDisplay> |
| 789 | <pre> | 800 | <pre> |
| 801 | -- assignment with implicit object | ||
| 790 | list = | 802 | list = |
| 791 | * 1 | 803 | * 1 |
| 792 | * 2 | 804 | * 2 |
| 793 | * 3 | 805 | * 3 |
| 794 | 806 | ||
| 807 | -- function call with implicit object | ||
| 795 | func | 808 | func |
| 796 | * 1 | 809 | * 1 |
| 797 | * 2 | 810 | * 2 |
| 798 | * 3 | 811 | * 3 |
| 799 | 812 | ||
| 813 | -- return with implicit object | ||
| 814 | f = -> | ||
| 815 | return | ||
| 816 | * 1 | ||
| 817 | * 2 | ||
| 818 | * 3 | ||
| 819 | |||
| 820 | -- table with implicit object | ||
| 800 | tb = | 821 | tb = |
| 801 | name: "abc" | 822 | name: "abc" |
| 802 | 823 | ||
| 803 | values: | 824 | values: |
| 804 | * "a" | 825 | - "a" |
| 805 | * "b" | 826 | - "b" |
| 806 | * "c" | 827 | - "c" |
| 807 | 828 | ||
| 808 | objects: | 829 | objects: |
| 809 | * name: "a" | 830 | - name: "a" |
| 810 | value: 1 | 831 | value: 1 |
| 811 | func: => @value + 1 | 832 | func: => @value + 1 |
| 812 | tb: | 833 | tb: |
| 813 | fieldA: 1 | 834 | fieldA: 1 |
| 814 | 835 | ||
| 815 | * name: "b" | 836 | - name: "b" |
| 816 | value: 2 | 837 | value: 2 |
| 817 | func: => @value + 2 | 838 | func: => @value + 2 |
| 818 | tb: { } | 839 | tb: { } |
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 2968f6e..1dd59a7 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
| @@ -16,17 +16,17 @@ Yue(月)是中文中“月亮”的名称。 | |||
| 16 | ### 月之脚本概览 | 16 | ### 月之脚本概览 |
| 17 | ```moonscript | 17 | ```moonscript |
| 18 | -- 导入语法 | 18 | -- 导入语法 |
| 19 | import "yue" as :p, :to_lua | 19 | import p, to_lua from "yue" |
| 20 | 20 | ||
| 21 | -- 隐式对象 | 21 | -- 隐式对象 |
| 22 | inventory = | 22 | inventory = |
| 23 | equipment: | 23 | equipment: |
| 24 | * "sword" | 24 | - "sword" |
| 25 | * "shield" | 25 | - "shield" |
| 26 | items: | 26 | items: |
| 27 | * name: "potion" | 27 | - name: "potion" |
| 28 | count: 10 | 28 | count: 10 |
| 29 | * name: "bread" | 29 | - name: "bread" |
| 30 | count: 3 | 30 | count: 3 |
| 31 | 31 | ||
| 32 | -- 列表推导 | 32 | -- 列表推导 |
| @@ -61,17 +61,17 @@ export 🌛 = "月之脚本" | |||
| 61 | <YueDisplay> | 61 | <YueDisplay> |
| 62 | <pre> | 62 | <pre> |
| 63 | -- 导入语法 | 63 | -- 导入语法 |
| 64 | import "yue" as :p, :to_lua | 64 | import p, to_lua from "yue" |
| 65 | 65 | ||
| 66 | -- 隐式对象 | 66 | -- 隐式对象 |
| 67 | inventory = | 67 | inventory = |
| 68 | equipment: | 68 | equipment: |
| 69 | * "sword" | 69 | - "sword" |
| 70 | * "shield" | 70 | - "shield" |
| 71 | items: | 71 | items: |
| 72 | * name: "potion" | 72 | - name: "potion" |
| 73 | count: 10 | 73 | count: 10 |
| 74 | * name: "bread" | 74 | - name: "bread" |
| 75 | count: 3 | 75 | count: 3 |
| 76 | 76 | ||
| 77 | -- 列表推导 | 77 | -- 列表推导 |
| @@ -751,67 +751,87 @@ a ??= false | |||
| 751 | 751 | ||
| 752 | ### 隐式对象 | 752 | ### 隐式对象 |
| 753 | 753 | ||
| 754 | 你可以在表格块内使用符号 **\*** 开始编写一系列隐式结构。如果你正在创建隐式对象,对象的字段必须具有相同的缩进。 | 754 | 你可以在表格块内使用符号 **\*** 或是 **-** 开始编写一系列隐式结构。如果你正在创建隐式对象,对象的字段必须具有相同的缩进。 |
| 755 | |||
| 755 | ```moonscript | 756 | ```moonscript |
| 757 | -- 赋值时使用隐式对象 | ||
| 756 | list = | 758 | list = |
| 757 | * 1 | 759 | * 1 |
| 758 | * 2 | 760 | * 2 |
| 759 | * 3 | 761 | * 3 |
| 760 | 762 | ||
| 763 | -- 函数调用时使用隐式对象 | ||
| 761 | func | 764 | func |
| 762 | * 1 | 765 | * 1 |
| 763 | * 2 | 766 | * 2 |
| 764 | * 3 | 767 | * 3 |
| 765 | 768 | ||
| 769 | -- 返回时使用隐式对象 | ||
| 770 | f = -> | ||
| 771 | return | ||
| 772 | * 1 | ||
| 773 | * 2 | ||
| 774 | * 3 | ||
| 775 | |||
| 776 | -- 表格时使用隐式对象 | ||
| 766 | tb = | 777 | tb = |
| 767 | name: "abc" | 778 | name: "abc" |
| 768 | 779 | ||
| 769 | values: | 780 | values: |
| 770 | * "a" | 781 | - "a" |
| 771 | * "b" | 782 | - "b" |
| 772 | * "c" | 783 | - "c" |
| 773 | 784 | ||
| 774 | objects: | 785 | objects: |
| 775 | * name: "a" | 786 | - name: "a" |
| 776 | value: 1 | 787 | value: 1 |
| 777 | func: => @value + 1 | 788 | func: => @value + 1 |
| 778 | tb: | 789 | tb: |
| 779 | fieldA: 1 | 790 | fieldA: 1 |
| 780 | 791 | ||
| 781 | * name: "b" | 792 | - name: "b" |
| 782 | value: 2 | 793 | value: 2 |
| 783 | func: => @value + 2 | 794 | func: => @value + 2 |
| 784 | tb: { } | 795 | tb: { } |
| 785 | |||
| 786 | ``` | 796 | ``` |
| 787 | <YueDisplay> | 797 | <YueDisplay> |
| 788 | <pre> | 798 | <pre> |
| 799 | -- 赋值时使用隐式对象 | ||
| 789 | list = | 800 | list = |
| 790 | * 1 | 801 | * 1 |
| 791 | * 2 | 802 | * 2 |
| 792 | * 3 | 803 | * 3 |
| 793 | 804 | ||
| 805 | -- 函数调用时使用隐式对象 | ||
| 794 | func | 806 | func |
| 795 | * 1 | 807 | * 1 |
| 796 | * 2 | 808 | * 2 |
| 797 | * 3 | 809 | * 3 |
| 798 | 810 | ||
| 811 | -- 返回时使用隐式对象 | ||
| 812 | f = -> | ||
| 813 | return | ||
| 814 | * 1 | ||
| 815 | * 2 | ||
| 816 | * 3 | ||
| 817 | |||
| 818 | -- 表格时使用隐式对象 | ||
| 799 | tb = | 819 | tb = |
| 800 | name: "abc" | 820 | name: "abc" |
| 801 | 821 | ||
| 802 | values: | 822 | values: |
| 803 | * "a" | 823 | - "a" |
| 804 | * "b" | 824 | - "b" |
| 805 | * "c" | 825 | - "c" |
| 806 | 826 | ||
| 807 | objects: | 827 | objects: |
| 808 | * name: "a" | 828 | - name: "a" |
| 809 | value: 1 | 829 | value: 1 |
| 810 | func: => @value + 1 | 830 | func: => @value + 1 |
| 811 | tb: | 831 | tb: |
| 812 | fieldA: 1 | 832 | fieldA: 1 |
| 813 | 833 | ||
| 814 | * name: "b" | 834 | - name: "b" |
| 815 | value: 2 | 835 | value: 2 |
| 816 | func: => @value + 2 | 836 | func: => @value + 2 |
| 817 | tb: { } | 837 | tb: { } |
diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue index 0de8a8c..702e04a 100644 --- a/spec/inputs/tables.yue +++ b/spec/inputs/tables.yue | |||
| @@ -245,6 +245,24 @@ menus = | |||
| 245 | click: -> | 245 | click: -> |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | _ = | ||
| 249 | boolean: | ||
| 250 | - true | ||
| 251 | - false | ||
| 252 | float: | ||
| 253 | - 3.14 | ||
| 254 | - -6.8523015e+5 | ||
| 255 | int: | ||
| 256 | - 123 | ||
| 257 | - -0b1010_0111_0100_1010_1110 | ||
| 258 | null: | ||
| 259 | nodeName: 'node' | ||
| 260 | parent: nil | ||
| 261 | string: | ||
| 262 | - 'Hello world' | ||
| 263 | - "newline | ||
| 264 | newline2" | ||
| 265 | |||
| 248 | tb = {...other} | 266 | tb = {...other} |
| 249 | 267 | ||
| 250 | tbMix = { | 268 | tbMix = { |
diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue index 3fee48e..dcd4053 100644 --- a/spec/inputs/with.yue +++ b/spec/inputs/with.yue | |||
| @@ -161,4 +161,8 @@ do | |||
| 161 | if .v | 161 | if .v |
| 162 | break .a | 162 | break .a |
| 163 | 163 | ||
| 164 | a = while true | ||
| 165 | break with? tb | ||
| 166 | break 1 | ||
| 167 | |||
| 164 | nil | 168 | nil |
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 3ee20bb..c7a2d50 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -339,6 +339,14 @@ func({ | |||
| 339 | 2, | 339 | 2, |
| 340 | 3 | 340 | 3 |
| 341 | }) | 341 | }) |
| 342 | local f | ||
| 343 | f = function() | ||
| 344 | return { | ||
| 345 | 1, | ||
| 346 | 2, | ||
| 347 | 3 | ||
| 348 | } | ||
| 349 | end | ||
| 342 | local tb = { | 350 | local tb = { |
| 343 | name = "abc", | 351 | name = "abc", |
| 344 | values = { | 352 | values = { |
| @@ -2548,6 +2556,14 @@ func({ | |||
| 2548 | 2, | 2556 | 2, |
| 2549 | 3 | 2557 | 3 |
| 2550 | }) | 2558 | }) |
| 2559 | local f | ||
| 2560 | f = function() | ||
| 2561 | return { | ||
| 2562 | 1, | ||
| 2563 | 2, | ||
| 2564 | 3 | ||
| 2565 | } | ||
| 2566 | end | ||
| 2551 | local tb = { | 2567 | local tb = { |
| 2552 | name = "abc", | 2568 | name = "abc", |
| 2553 | values = { | 2569 | values = { |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 52204b7..fcde41f 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -339,6 +339,14 @@ func({ | |||
| 339 | 2, | 339 | 2, |
| 340 | 3 | 340 | 3 |
| 341 | }) | 341 | }) |
| 342 | local f | ||
| 343 | f = function() | ||
| 344 | return { | ||
| 345 | 1, | ||
| 346 | 2, | ||
| 347 | 3 | ||
| 348 | } | ||
| 349 | end | ||
| 342 | local tb = { | 350 | local tb = { |
| 343 | name = "abc", | 351 | name = "abc", |
| 344 | values = { | 352 | values = { |
| @@ -2542,6 +2550,14 @@ func({ | |||
| 2542 | 2, | 2550 | 2, |
| 2543 | 3 | 2551 | 3 |
| 2544 | }) | 2552 | }) |
| 2553 | local f | ||
| 2554 | f = function() | ||
| 2555 | return { | ||
| 2556 | 1, | ||
| 2557 | 2, | ||
| 2558 | 3 | ||
| 2559 | } | ||
| 2560 | end | ||
| 2545 | local tb = { | 2561 | local tb = { |
| 2546 | name = "abc", | 2562 | name = "abc", |
| 2547 | values = { | 2563 | values = { |
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua index f358811..3f851de 100644 --- a/spec/outputs/tables.lua +++ b/spec/outputs/tables.lua | |||
| @@ -366,6 +366,28 @@ local menus = { | |||
| 366 | } | 366 | } |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | _ = { | ||
| 370 | boolean = { | ||
| 371 | true, | ||
| 372 | false | ||
| 373 | }, | ||
| 374 | float = { | ||
| 375 | 3.14, | ||
| 376 | -6.8523015e+5 | ||
| 377 | }, | ||
| 378 | int = { | ||
| 379 | 123, | ||
| 380 | -685230 | ||
| 381 | }, | ||
| 382 | null = { | ||
| 383 | nodeName = 'node', | ||
| 384 | parent = nil | ||
| 385 | }, | ||
| 386 | string = { | ||
| 387 | 'Hello world', | ||
| 388 | "newline\nnewline2" | ||
| 389 | } | ||
| 390 | } | ||
| 369 | local tb | 391 | local tb |
| 370 | do | 392 | do |
| 371 | local _tab_0 = { } | 393 | local _tab_0 = { } |
diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 20c5d44..867d1b5 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua | |||
| @@ -203,15 +203,35 @@ do | |||
| 203 | return _with_0 | 203 | return _with_0 |
| 204 | end)()) | 204 | end)()) |
| 205 | local a | 205 | local a |
| 206 | local _with_0 = tb | 206 | do |
| 207 | local _with_0 = tb | ||
| 208 | do | ||
| 209 | local _accum_0 | ||
| 210 | while true do | ||
| 211 | if _with_0.v then | ||
| 212 | _accum_0 = _with_0.a | ||
| 213 | break | ||
| 214 | end | ||
| 215 | end | ||
| 216 | _with_0 = _accum_0 | ||
| 217 | end | ||
| 218 | a = _with_0 | ||
| 219 | end | ||
| 207 | local _accum_0 | 220 | local _accum_0 |
| 208 | while true do | 221 | while true do |
| 209 | if _with_0.v then | 222 | local _with_0 = tb |
| 210 | _accum_0 = _with_0.a | 223 | local _accum_1 |
| 224 | while true do | ||
| 225 | if _with_0 ~= nil then | ||
| 226 | _accum_1 = 1 | ||
| 227 | break | ||
| 228 | end | ||
| 211 | break | 229 | break |
| 212 | end | 230 | end |
| 231 | _with_0 = _accum_1 | ||
| 232 | _accum_0 = _with_0 | ||
| 233 | break | ||
| 213 | end | 234 | end |
| 214 | _with_0 = _accum_0 | 235 | a = _accum_0 |
| 215 | a = _with_0 | ||
| 216 | end | 236 | end |
| 217 | return nil | 237 | return nil |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index cd1fd48..078509c 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -740,7 +740,7 @@ YueParser::YueParser() { | |||
| 740 | 740 | ||
| 741 | table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); | 741 | table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); |
| 742 | TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); | 742 | TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); |
| 743 | TableBlockIndent = '*' >> Seperator >> disable_arg_table_block_rule( | 743 | TableBlockIndent = ('*' | '-' >> space_one) >> Seperator >> disable_arg_table_block_rule( |
| 744 | space >> key_value_list >> -(space >> ',') >> | 744 | space >> key_value_list >> -(space >> ',') >> |
| 745 | -(+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent))); | 745 | -(+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent))); |
| 746 | 746 | ||
| @@ -843,7 +843,7 @@ YueParser::YueParser() { | |||
| 843 | key_value_line = check_indent_match >> space >> ( | 843 | key_value_line = check_indent_match >> space >> ( |
| 844 | key_value_list >> -(space >> ',') | | 844 | key_value_list >> -(space >> ',') | |
| 845 | TableBlockIndent | | 845 | TableBlockIndent | |
| 846 | '*' >> space >> (SpreadExp | Exp | TableBlock) | 846 | ('*' | '-' >> space_one) >> space >> (SpreadExp | Exp | TableBlock) |
| 847 | ); | 847 | ); |
| 848 | 848 | ||
| 849 | fn_arg_def_list = FnArgDef >> *(space >> ',' >> space >> FnArgDef); | 849 | fn_arg_def_list = FnArgDef >> *(space >> ',' >> space >> FnArgDef); |
