如何在解析块中绑定变量

时间:2012-03-19 17:56:18

标签: rebol

我只想迭代一个文件列表,并在解析其内容后打印文件名:

files: [%test1.txt %test2.txt]
rule: [to "test" thru "test" copy x to "." (print x print file)]
foreach file files [
    content: read file
    parse [any rule]
]

执行时我有 **脚本错误:文件没有值

如何将文件var名称绑定到规则块程序的上下文?

2 个答案:

答案 0 :(得分:4)

也可以这样做(按字面意思放入RULE并让FOREACH在正确的时间绑定它):

files: [%test1.txt %test2.txt]
rule: [to "test" thru "test" copy x to "." (print x print file)]
foreach file files compose/only/deep [
    content: read file
    parse content [any (rule)]
]

答案 1 :(得分:3)

只需每次迭代绑定规则:

files: [%test1.txt %test2.txt]
rule: [to "test" thru "test" copy x to "." (print x print file)]
foreach file files [
    bind rule 'file
    content: read file
    parse content [any rule]
]