0

这很好用(感谢 Sunanda 的建议How can I parse [a / b] ? syntax error in Rebol?):

attribute: copy []
class: copy []
definition-rule: compose/deep [some [set class word! 'is 'defined 'by 
[some [copy attribute to (to-lit-word "/") thru (to-lit-word "/") ]]
copy attribute to end]]
parse [Customer is defined by First Name / Last Name / Email] definition-rule

但我现在需要添加一些附加指令(附加输出类),它不再起作用:

attribute: copy []
class: copy []
definition-rule: compose/deep [some [set class word! (append output class) 'is 'defined 'by 
[some [copy attribute to (to-lit-word "/") thru (to-lit-word "/") ]]
copy attribute to end]]
parse [Customer is defined by First Name / Last Name / Email] definition-rule
4

2 回答 2

1

这里的问题是撰写正在吃掉括号中的所有表达式。你很高兴它吃掉(to-lit-word "/")但你真的不希望它吃掉(append output class)因为那是为解析方言设计的。

可能有一个更聪明的方法,但这应该可行:通过在解析规则之外进行lit-word工作来删除compose ...

attribute: copy []
class: copy []
output: copy ""
fs: to-lit-word "/"   ;; define a forward slash lit-word

definition-rule:  [
    some [set class word! (append output class) 'is 'defined 'by [
        some [copy attribute to fs thru fs]
    ]
    copy attribute to end]
    ]

parse [Customer is defined by First Name / Last Name / Email] definition-rule
== true

我不完全确定你想用这段代码做什么,但你想在最后提取一组属性,然后考虑这个更改:

attribute: copy []
attributes: copy []
class: copy []
output: copy ""
fs: to-lit-word "/"   ;; define a forward slash lit-word

definition-rule:  [
    some [set class word! (append output class) 'is 'defined 'by [
        some [copy attribute to fs thru fs (append/only attributes attribute)]
    ]
    copy attribute to end (append/only attributes attribute)]
    ]

parse [Customer is defined by First Name / Last Name / Email] definition-rule

print ["==" class mold attributes]

== Customer [[First Name] [Last Name] [Email]]
于 2009-09-22T14:12:54.937 回答
0

I repost code in comment as it isn't readable, what I wanted to do exactly was this:

attribute: copy []
class: copy []
fs: to-lit-word "/" 
output: copy ""


definition-rule:  [
    some [set class word! (append output join class "|") 'is 'defined 'by [
        some [copy attribute to fs thru fs (append output join attribute ";")]
    ]
    copy attribute to end (append output attribute)]
]

parse [Customer is defined by First Name / Last Name / Email] definition-rule
probe output
于 2009-09-22T20:04:02.743 回答