diff options
author | Li Jin <dragon-fly@qq.com> | 2020-03-12 10:27:53 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-03-12 10:27:53 +0800 |
commit | b2cdbc975526b710d23c41af18978afbac516240 (patch) | |
tree | 40092d049e9e424476a548f1b3de08575fd1ac99 /spec | |
parent | bd5550aa0aff81eafd077cd44e6fa3e88015f6e7 (diff) | |
download | yuescript-b2cdbc975526b710d23c41af18978afbac516240.tar.gz yuescript-b2cdbc975526b710d23c41af18978afbac516240.tar.bz2 yuescript-b2cdbc975526b710d23c41af18978afbac516240.zip |
fix macro type mismatch issue.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/macro.moon | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/spec/inputs/macro.moon b/spec/inputs/macro.moon index db03a10..07ac7b3 100644 --- a/spec/inputs/macro.moon +++ b/spec/inputs/macro.moon | |||
@@ -43,7 +43,7 @@ macro block foreach = (items,action)-> | |||
43 | #{action}" | 43 | #{action}" |
44 | 44 | ||
45 | macro expr pipe = (...)-> | 45 | macro expr pipe = (...)-> |
46 | switch select "#",... | 46 | switch select "#", ... |
47 | when 0 then return "" | 47 | when 0 then return "" |
48 | when 1 then return ... | 48 | when 1 then return ... |
49 | ops = {...} | 49 | ops = {...} |
@@ -53,7 +53,7 @@ macro expr pipe = (...)-> | |||
53 | last = "_#{i}" | 53 | last = "_#{i}" |
54 | stmt | 54 | stmt |
55 | res = "do | 55 | res = "do |
56 | #{table.concat stmts,"\n"} | 56 | #{table.concat stmts, "\n"} |
57 | #{last}" | 57 | #{last}" |
58 | $showMacro "pipe", res | 58 | $showMacro "pipe", res |
59 | 59 | ||
@@ -68,3 +68,39 @@ val = $pipe( | |||
68 | $reduce(0, _1 + _2) | 68 | $reduce(0, _1 + _2) |
69 | ) | 69 | ) |
70 | 70 | ||
71 | macro expr plus = (a, b)-> "#{a} + #{b}" | ||
72 | |||
73 | $plus(1,2)\call 123 | ||
74 | |||
75 | macro expr curry = (...)-> | ||
76 | args = {...} | ||
77 | len = #args | ||
78 | body = args[len] | ||
79 | def = table.concat ["(#{args[i]})->" for i = 1, len - 1] | ||
80 | "#{def}\n#{body\gsub "^do\n",""}" | ||
81 | |||
82 | f = $curry x,y,z,do | ||
83 | print x,y,z | ||
84 | |||
85 | macro expr get_inner = (var)-> "do | ||
86 | a = 1 | ||
87 | a + 1" | ||
88 | |||
89 | macro expr get_inner_hygienic = (var)-> "(-> | ||
90 | local a = 1 | ||
91 | a + 1)!" | ||
92 | |||
93 | do | ||
94 | a = 8 | ||
95 | a = $get_inner! | ||
96 | a += $get_inner! | ||
97 | print a | ||
98 | |||
99 | do | ||
100 | a = 8 | ||
101 | a = $get_inner_hygienic! | ||
102 | a += $get_inner_hygienic! | ||
103 | print a | ||
104 | |||
105 | nil | ||
106 | |||