Rebol 解析:处理空格和复制 var
我读了第15章: http://www.rebol.com/docs/core23/ rebolcore-15.html#section-8”
spacer: charset reduce [tab newline #" "]
spaces: [some spacer]
rule: ["a" spaces "b" spaces "c"]
parse/all "a b c" rule
没问题,但如果我将规则更改为仅
rule: ["a" spaces copy varb to spaces "c"]
parse/all "a b c" rule
Rebol 控制台输出错误:
** Script Error: Invalid argument: some spacer
** Where: halt-view
** Near: parse/all "a b c" rule
>>
为什么?
谢谢。
I read chapter 15:
http://www.rebol.com/docs/core23/rebolcore-15.html#section-8"
spacer: charset reduce [tab newline #" "]
spaces: [some spacer]
rule: ["a" spaces "b" spaces "c"]
parse/all "a b c" rule
is OK but if I change rule to just
rule: ["a" spaces copy varb to spaces "c"]
parse/all "a b c" rule
Rebol Console outputs error:
** Script Error: Invalid argument: some spacer
** Where: halt-view
** Near: parse/all "a b c" rule
>>
Why ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 REBOL 2 中,PARSE 的 TO 操作的参数不能是复杂的规则 - 它必须是文字值或字符集。 代码
[to space]
相当于[to [some spacer]]
,但这是行不通的。 在您的示例中,您可以将[to space]
转换为[to spacer space]
并且它应该可以正常工作。有一些技巧可以解决这个问题,主要涉及将
[to [some spacer]]
重构为[any non-spacer]
,其中 non-spacer 是间隔字符集。预计这一问题将在 REBOL 3 中得到修复,但该修复尚未完成,并且由于 Unicode,补充字符集效果不佳。 现在继续使用 REBOL 2。
In REBOL 2 the argument of the TO operation of PARSE can't be a complex rule - it must be a literal value or character set. The code
[to spaces]
is equivalent to[to [some spacer]]
and that just won't work. In your example you can convert[to spaces]
to[to spacer spaces]
and it should work just fine.There are tricks to get around this, that mostly involve refactoring the
[to [some spacer]]
to be[any non-spacer]
where non-spacer is the complement of the spacer character set.It is intended that this will be fixed in REBOL 3, but that fix hasn't been done yet, and complementing a character set doesn't work as well because of Unicode. Stick with REBOL 2 for now.