1
我试图限定sweet.js宏允许更容易地定义其它重复宏,但我已经发现一个语法错误这里:sweet.js宏可以定义其他宏吗?
SyntaxError: [patterns] Ellipses level does not match in the template
11: { $($b...)... }
这是生成此语法错误宏:
macro repeatingMacro{
rule{
$a {
$b...
} {
$c...
}
} => {
//the output of this macro should be another macro with repeating patterns
macro $a {
rule{
{ $($b...)... }
} => {
{ $($c...)... }
}
}
}
}
如果该宏被正确定义,那么这将允许创建其他宏,像这样的:
repeatingMacro cond {
$a... { $b... }
}
{
if($a...){
$b...
}
}
var x = 1;
var y = 2;
cond {
(x > y) {
alert(x);
}
(x < y) {
alert(y)
}
}
This code can be edited online here.
换句话说,是有可能定义一个宏,它会自动改变这个宏:
macro cond {
rule {
$x... { $y... }
} => {
if($x...){
$y...
}
}
}
...这个宏?
macro cond {
rule {
{ $($x... { $y... })... }
} => {
$(if($x...){
$y...
})...
}
}
要回答标题问题:是的。有关示例,请参阅https://gist.github.com/natefaubion/f4be4c8531ef45de87b4。 – Havvy 2014-10-25 19:40:59