我有一个宏,我可以在括号之间插入任何代码。然后,我将其传递给对该代码具有规则的另一个宏。我在其中做了其他事情,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)
我认为您缺少的规则test
。
test(true is true)
扩展到
testimpl { (true is true) }
这与您在中的规则不符testimpl
。
将test
规则更改为rule { ($code ...) }
应该可以。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句