1

I was creating my macros and there is a bug than pops up (from my point of view) randomly:

ASSERT: enforest assumes there are tokens to work with

I'm not sure about what does this mean but I did my best to encapsulate the problem and I end with this code:

macro foo {
  rule { $bar:expr ? } => { $bar }
  rule { $bar:expr } => { $bar }
}

If I invoke foo macro between parentheses and add the ? at the end this error is thrown:

(foo test ?)
// produces ASSERT: enforest assumes there are tokens to work with

But if I remove the parentheses or the ? it just works

foo test ?
// produces: test
(foo test)
// produces: test

You can see it failing here:

http://sweetjs.org/browser/editor.html#macro%20foo%20%7B%0A%20%20rule%20%7B%20$bar:expr%20?%20%7D%20=%3E%20%7B%20$bar%20%7D%0A%20%20rule%20%7B%20$bar:expr%20%7D%20=%3E%20%7B%20$bar%20%7D%0A%7D%0A%0A(foo%20test%20?)%0A

So please, this is driving me crazy I'm facing this error again and again. It should be related to the :expr operator, but I can't replace it with ... because it's so greedy and it selects everything to the last ? it found.

I can see the line than throws this error is here. But I don't know the context.

Any help?

4

1 回答 1

0

感谢@natefaubion,我有一个答案,这是一个错误,因为它被解释?为三元运算符并且由于找不到表达式的其余部分而失败。

同样对于我的具体情况,自定义模式类(而不是:expr)将是一个更好的解决方案。这个想法是在这里提出的:https ://github.com/mozilla/sweet.js/issues/203 。

现在一个肮脏的解决方法是使用case手动解析模式:http: //bit.ly/1aPmwyX

正如@natefaubion 所说

这不是一个很好的答案!它可以工作(有点),但是 1)三元运算符的加密方式存在一个错误 2)您真正想要的是可扩展的模式类。

于 2014-01-23T22:43:28.133 回答