我有一个宏,其中包含括号之间的任何代码。然后,我将其传递给另一个具有该代码规则的宏。我在test中做了其他事情,它的命名也不同,但我认为在这里使用一个最小的测试用例是有用的。
macro testimpl {
rule {
{ $lhs:expr is $rhs:expr }
} => {
}
}
macro test {
rule { $code ... } => { testimpl { $code ... } }
}
testimpl { true is true } // Works
test(true is true) // Throws the next error下面是我得到的错误消息:
{ name: 'macro',
message: 'Macro `testimpl` could not be matched with `{} ...`',
stx:
{ token:
{ type: 3,
value: 'testimpl',
lineNumber: 13,
lineStart: 98,
range: [Object],
sm_lineNumber: 9,
sm_lineStart: 98,
sm_range: [Object],
leadingComments: [Object] },
context: { mark: 649, context: [Object], instNum: 131515 },
deferredContext: null } }
/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:100
throw new SyntaxError(syn.printSyntaxError(source$2, err))
^
SyntaxError: [macro] Macro `testimpl` could not be matched with `{} ...`
9: rule { $code ... } => { testimpl { $code ... } }
^
at expand$2 (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:100:27)
at parse (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:136:29)
at Object.compile (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:144:19)
at Object.exports.run (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sjs.js:85:27)
at Object.<anonymous> (/home/havvy/sweetjs/playground/node_modules/sweet.js/bin/sjs:7:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)发布于 2014-10-25 21:26:29
我想你错过了test规则中的外部父母。
test(true is true)扩展到
testimpl { (true is true) }这与testimpl中的规则不匹配。
将test规则更改为rule { ($code ...) }应该有效。
https://stackoverflow.com/questions/26567096
复制相似问题