我有一个宏,我在括号之间接受任何代码。然后我将它传递给另一个具有该代码规则的宏。我在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)
答案 0 :(得分:2)
我认为你错过了test
规则中的外在问题。
test(true is true)
扩展为
testimpl { (true is true) }
与testimpl
中的规则不符。
将test
规则更改为rule { ($code ...) }
应该有效。