diff options
Diffstat (limited to 'spec/inputs/macro-teal.yue')
-rw-r--r-- | spec/inputs/macro-teal.yue | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/spec/inputs/macro-teal.yue b/spec/inputs/macro-teal.yue index 3a9bb2b..951e882 100644 --- a/spec/inputs/macro-teal.yue +++ b/spec/inputs/macro-teal.yue | |||
@@ -4,8 +4,8 @@ $ -> | |||
4 | options.target_extension = "tl" | 4 | options.target_extension = "tl" |
5 | package.path ..= "?.lua;./spec/lib/?.lua" | 5 | package.path ..= "?.lua;./spec/lib/?.lua" |
6 | 6 | ||
7 | macro to_lua = (codes)-> | 7 | macro to_lua = (code)-> |
8 | "require('yue').to_lua(#{codes}, reserve_line_number:false, same_module:true)" | 8 | "require('yue').to_lua(#{code}, reserve_line_number:false, same_module:true)" |
9 | 9 | ||
10 | macro trim = (name)-> | 10 | macro trim = (name)-> |
11 | "if result = #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" | 11 | "if result = #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" |
@@ -16,12 +16,12 @@ export macro local = (decl, value = nil)-> | |||
16 | if not (name and type) | 16 | if not (name and type) |
17 | error "invalid local varaible declaration for \"#{decl}\"" | 17 | error "invalid local varaible declaration for \"#{decl}\"" |
18 | value = $to_lua(value)\gsub "^return ", "" | 18 | value = $to_lua(value)\gsub "^return ", "" |
19 | codes = if tl_enabled | 19 | code = if tl_enabled |
20 | "local #{name}:#{$trim type} = #{value}" | 20 | "local #{name}:#{$trim type} = #{value}" |
21 | else | 21 | else |
22 | "local #{name} = #{value}" | 22 | "local #{name} = #{value}" |
23 | { | 23 | { |
24 | :codes | 24 | :code |
25 | type: "text" | 25 | type: "text" |
26 | locals: {name} | 26 | locals: {name} |
27 | } | 27 | } |
@@ -37,28 +37,28 @@ export macro function = (decl, value)-> | |||
37 | _, node = tl.parse_program tokens,{},"macro-function" | 37 | _, node = tl.parse_program tokens,{},"macro-function" |
38 | args = table.concat [arg.tk for arg in *node[1].args],", " | 38 | args = table.concat [arg.tk for arg in *node[1].args],", " |
39 | value = "(#{args})#{value}" | 39 | value = "(#{args})#{value}" |
40 | codes = if tl_enabled | 40 | code = if tl_enabled |
41 | value = $to_lua(value)\match "function%([^\n]*%)(.*)end" | 41 | value = $to_lua(value)\match "function%([^\n]*%)(.*)end" |
42 | "local function #{name}#{type}\n#{value}\nend" | 42 | "local function #{name}#{type}\n#{value}\nend" |
43 | else | 43 | else |
44 | value = $to_lua(value)\gsub "^return ", "" | 44 | value = $to_lua(value)\gsub "^return ", "" |
45 | "local #{name} = #{value}" | 45 | "local #{name} = #{value}" |
46 | { | 46 | { |
47 | :codes | 47 | :code |
48 | type: "text" | 48 | type: "text" |
49 | locals: {name} | 49 | locals: {name} |
50 | } | 50 | } |
51 | 51 | ||
52 | export macro record = (name, decl)-> | 52 | export macro record = (name, decl)-> |
53 | import "yue" as {options:{:tl_enabled}} | 53 | import "yue" as {options:{:tl_enabled}} |
54 | codes = if tl_enabled | 54 | code = if tl_enabled |
55 | "local record #{name} | 55 | "local record #{name} |
56 | #{decl} | 56 | #{decl} |
57 | end" | 57 | end" |
58 | else | 58 | else |
59 | "local #{name} = {}" | 59 | "local #{name} = {}" |
60 | { | 60 | { |
61 | :codes | 61 | :code |
62 | type: "text" | 62 | type: "text" |
63 | locals: {name} | 63 | locals: {name} |
64 | } | 64 | } |
@@ -74,14 +74,14 @@ export macro method = (decl, value)-> | |||
74 | _, node = tl.parse_program tokens,{},"macro-function" | 74 | _, node = tl.parse_program tokens,{},"macro-function" |
75 | args = table.concat [arg.tk for arg in *node[1].args],", " | 75 | args = table.concat [arg.tk for arg in *node[1].args],", " |
76 | value = "(#{args})->#{value\match "[%-=]>(.*)"}" | 76 | value = "(#{args})->#{value\match "[%-=]>(.*)"}" |
77 | codes = if tl_enabled | 77 | code = if tl_enabled |
78 | value = $to_lua(value)\match "^return function%(.-%)\n(.*)end" | 78 | value = $to_lua(value)\match "^return function%(.-%)\n(.*)end" |
79 | "function #{tab}#{sym}#{func}#{type}\n#{value}\nend" | 79 | "function #{tab}#{sym}#{func}#{type}\n#{value}\nend" |
80 | else | 80 | else |
81 | value = $to_lua(value)\gsub "^return ", "" | 81 | value = $to_lua(value)\gsub "^return ", "" |
82 | "#{tab}.#{func} = #{value}" | 82 | "#{tab}.#{func} = #{value}" |
83 | { | 83 | { |
84 | :codes | 84 | :code |
85 | type: "text" | 85 | type: "text" |
86 | } | 86 | } |
87 | 87 | ||