diff options
author | Li Jin <dragon-fly@qq.com> | 2023-06-25 17:46:32 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-06-25 17:46:32 +0800 |
commit | cd618f934b0e4a30bd6cd4e98f8c1005bf3d6193 (patch) | |
tree | 5bc8bc55f80fe74a3b73101b55eabc60ae1d75c3 /spec | |
parent | 5d246757285a437401347dd6a1a1f8d3cf61e08c (diff) | |
download | yuescript-cd618f934b0e4a30bd6cd4e98f8c1005bf3d6193.tar.gz yuescript-cd618f934b0e4a30bd6cd4e98f8c1005bf3d6193.tar.bz2 yuescript-cd618f934b0e4a30bd6cd4e98f8c1005bf3d6193.zip |
fix more ambiguous Lua codes generation cases.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/ambiguous.yue | 21 | ||||
-rw-r--r-- | spec/outputs/ambiguous.lua | 15 | ||||
-rw-r--r-- | spec/outputs/attrib.lua | 8 | ||||
-rw-r--r-- | spec/outputs/macro.lua | 8 | ||||
-rw-r--r-- | spec/outputs/teal-lang.lua | 10 | ||||
-rw-r--r-- | spec/outputs/teal-lang.tl | 8 | ||||
-rw-r--r-- | spec/outputs/using.lua | 2 |
7 files changed, 54 insertions, 18 deletions
diff --git a/spec/inputs/ambiguous.yue b/spec/inputs/ambiguous.yue index 3ae0bfc..37857fe 100644 --- a/spec/inputs/ambiguous.yue +++ b/spec/inputs/ambiguous.yue | |||
@@ -23,6 +23,27 @@ for i = 1, 10 | |||
23 | goto abc | 23 | goto abc |
24 | (print) 5 | 24 | (print) 5 |
25 | 25 | ||
26 | macro lua = (code)-> { | ||
27 | :code | ||
28 | type: "lua" | ||
29 | } | ||
30 | |||
31 | do | ||
32 | print() | ||
33 | 1 |> b |> (a) | ||
34 | print() | ||
35 | <- (fn) | ||
36 | |||
37 | do | ||
38 | print() | ||
39 | () <- async_fn() | ||
40 | print() | ||
41 | $lua[==[ | ||
42 | --[[a comment to insert]] | ||
43 | (haha)() | ||
44 | ]==] | ||
45 | nil | ||
46 | |||
26 | macro v = -> 'print 123' | 47 | macro v = -> 'print 123' |
27 | do | 48 | do |
28 | global * | 49 | global * |
diff --git a/spec/outputs/ambiguous.lua b/spec/outputs/ambiguous.lua index f96cee5..3da6f14 100644 --- a/spec/outputs/ambiguous.lua +++ b/spec/outputs/ambiguous.lua | |||
@@ -25,6 +25,21 @@ for i = 1, 10 do | |||
25 | (print)(5) | 25 | (print)(5) |
26 | end | 26 | end |
27 | do | 27 | do |
28 | print(); | ||
29 | (a)(b(1)) | ||
30 | print(); | ||
31 | (fn)(function() end) | ||
32 | end | ||
33 | do | ||
34 | print() | ||
35 | async_fn(function() | ||
36 | print(); | ||
37 | --[[a comment to insert]] | ||
38 | (haha)() | ||
39 | return nil | ||
40 | end) | ||
41 | end | ||
42 | do | ||
28 | print(123) | 43 | print(123) |
29 | end | 44 | end |
30 | do | 45 | do |
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua index fbac28e..aaff747 100644 --- a/spec/outputs/attrib.lua +++ b/spec/outputs/attrib.lua | |||
@@ -64,12 +64,12 @@ do | |||
64 | local _with_0 = io.open("file.txt") | 64 | local _with_0 = io.open("file.txt") |
65 | _with_0:write("Hello") | 65 | _with_0:write("Hello") |
66 | return _with_0 | 66 | return _with_0 |
67 | end)(); | 67 | end)() |
68 | local _ <close> = setmetatable({ }, { | 68 | local _ <close> = setmetatable({ }, { |
69 | __close = function(self) | 69 | __close = function(self) |
70 | return print("second") | 70 | return print("second") |
71 | end | 71 | end |
72 | }); | 72 | }) |
73 | local _ <close> = setmetatable({ }, { | 73 | local _ <close> = setmetatable({ }, { |
74 | __close = function() | 74 | __close = function() |
75 | return print("first") | 75 | return print("first") |
@@ -86,11 +86,11 @@ do | |||
86 | _defers[#_defers + 1] = function() | 86 | _defers[#_defers + 1] = function() |
87 | return print(3) | 87 | return print(3) |
88 | end | 88 | end |
89 | local _ <close> = _defers; | 89 | local _ <close> = _defers |
90 | _defers[#_defers + 1] = function() | 90 | _defers[#_defers + 1] = function() |
91 | return print(2) | 91 | return print(2) |
92 | end | 92 | end |
93 | local _ <close> = _defers; | 93 | local _ <close> = _defers |
94 | _defers[#_defers + 1] = function() | 94 | _defers[#_defers + 1] = function() |
95 | return print(1) | 95 | return print(1) |
96 | end | 96 | end |
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index fbc1d48..f18baed 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | assert(item == nil); | 1 | assert(item == nil) |
2 | local v = (item == nil) | 2 | local v = (item == nil) |
3 | if f1() then | 3 | if f1() then |
4 | print("OK") | 4 | print("OK") |
@@ -170,11 +170,11 @@ do | |||
170 | end)() | 170 | end)() |
171 | print(a) | 171 | print(a) |
172 | end | 172 | end |
173 | local x = 0; | 173 | local x = 0 |
174 | local function f(a) | 174 | local function f(a) |
175 | return a + 1 | 175 | return a + 1 |
176 | end | 176 | end |
177 | x = x + f(3); | 177 | x = x + f(3) |
178 | function tb:func() | 178 | function tb:func() |
179 | print(123) | 179 | print(123) |
180 | end | 180 | end |
@@ -277,7 +277,7 @@ print((setmetatable({ | |||
277 | return 998 | 277 | return 998 |
278 | end | 278 | end |
279 | })) | 279 | })) |
280 | print("current line: " .. tostring(268)); | 280 | print("current line: " .. tostring(268)) |
281 | -- TODO | 281 | -- TODO |
282 | do | 282 | do |
283 | print(1) | 283 | print(1) |
diff --git a/spec/outputs/teal-lang.lua b/spec/outputs/teal-lang.lua index 0e627f4..28ba6f8 100644 --- a/spec/outputs/teal-lang.lua +++ b/spec/outputs/teal-lang.lua | |||
@@ -1,13 +1,13 @@ | |||
1 | local a = { | 1 | local a = { |
2 | value = 123 | 2 | value = 123 |
3 | }; | 3 | } |
4 | local b = a.value; | 4 | local b = a.value |
5 | local add = function(a, b) | 5 | local add = function(a, b) |
6 | return a + b | 6 | return a + b |
7 | end | 7 | end |
8 | local s = add(a.value, b) | 8 | local s = add(a.value, b) |
9 | print(s); | 9 | print(s) |
10 | local Point = {}; | 10 | local Point = {} |
11 | Point.new = function(x, y) | 11 | Point.new = function(x, y) |
12 | local point = setmetatable({ }, { | 12 | local point = setmetatable({ }, { |
13 | __index = Point | 13 | __index = Point |
@@ -21,7 +21,7 @@ Point.move = function(self, dx, dy) | |||
21 | self.y = self.y + dy | 21 | self.y = self.y + dy |
22 | end | 22 | end |
23 | local p = Point.new(100, 100) | 23 | local p = Point.new(100, 100) |
24 | p:move(50, 50); | 24 | p:move(50, 50) |
25 | local filter = function(tab, handler) | 25 | local filter = function(tab, handler) |
26 | local _accum_0 = { } | 26 | local _accum_0 = { } |
27 | local _len_0 = 1 | 27 | local _len_0 = 1 |
diff --git a/spec/outputs/teal-lang.tl b/spec/outputs/teal-lang.tl index 8f0bf36..0dc25a1 100644 --- a/spec/outputs/teal-lang.tl +++ b/spec/outputs/teal-lang.tl | |||
@@ -1,14 +1,14 @@ | |||
1 | local a:{string:number} = { | 1 | local a:{string:number} = { |
2 | value = 123 | 2 | value = 123 |
3 | }; | 3 | } |
4 | local b:number = a.value; | 4 | local b:number = a.value |
5 | local function add(a:number, b:number):number | 5 | local function add(a:number, b:number):number |
6 | 6 | ||
7 | return a + b | 7 | return a + b |
8 | 8 | ||
9 | end | 9 | end |
10 | local s = add(a.value, b) | 10 | local s = add(a.value, b) |
11 | print(s); | 11 | print(s) |
12 | local record Point | 12 | local record Point |
13 | x: number | 13 | x: number |
14 | y: number | 14 | y: number |
@@ -28,7 +28,7 @@ function Point:move(dx:number, dy:number) | |||
28 | 28 | ||
29 | end | 29 | end |
30 | local p:Point = Point.new(100, 100) | 30 | local p:Point = Point.new(100, 100) |
31 | p:move(50, 50); | 31 | p:move(50, 50) |
32 | local function filter(tab:{string}, handler:function(item:string):boolean):{string} | 32 | local function filter(tab:{string}, handler:function(item:string):boolean):{string} |
33 | 33 | ||
34 | local _accum_0 = { } | 34 | local _accum_0 = { } |
diff --git a/spec/outputs/using.lua b/spec/outputs/using.lua index ff23a30..8ecc21e 100644 --- a/spec/outputs/using.lua +++ b/spec/outputs/using.lua | |||
@@ -22,7 +22,7 @@ _ = function() | |||
22 | local hello = hello or 2 | 22 | local hello = hello or 2 |
23 | end | 23 | end |
24 | do | 24 | do |
25 | local a = { }; | 25 | local a = { } |
26 | _(function() | 26 | _(function() |
27 | local x, y = a[1], a[2] | 27 | local x, y = a[1], a[2] |
28 | end) | 28 | end) |