REBOL解析规则

问题描述:

这个伟大的工程(感谢苏南达的建议How can I parse [a/b] ? syntax error in Rebol?):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 
+0

好吧,让我们看看是否再次回答Sunanda。我不太明白为什么一个教程提出问题,但我准备犯错。 – 2009-09-22 04:56:02

+0

我很乐意在任何有REBOL问题的论坛上回答有关REBOL的问题(如果我知道答案的话)。到目前为止,REBOL社区对*的使用非常少 - 主要是RebolTutorial提出的问题,还有几个人(主要是我到目前为止)的回应。如果这给任何人造成问题,那么Reboltutorial可以切换到REBOL特定的论坛之一以获得他/她的Q&A支持。 – Sunanda 2009-09-22 13:57:59

的这里的问题是,组成是吃所有表达式在括号中。你很高兴它吃(以点亮的词“/”),但是你认真不希望它吃(附加输出类),因为这是为在解析方言。

有可能是一个聪明的做法,但这应该工作:删除通过执行点燃字解析规则之外工作撰写 ...

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]] 
+0

非常感谢,我需要在第二个例子中这样做的: 属性:复制[] 类:复制[] FS:要点亮的词“/” 输出:复制“” 定义规则:[ 一些[套课文! (追加输出连接属性“;”)] [ ] 复制属性结束(追加输出属性)] [ ] 解析[客户由名/姓/电子邮件定义] definition-rule 探针输出 – 2009-09-22 20:02:46

我重新发布代码注释,因为它是不可读,W我想要做的正是这样的帽子:

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