2009-09-22 98 views
0

這個偉大的工程(感謝蘇南達的建議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社區對Stackoverflow的使用非常少 - 主要是RebolTutorial提出的問題,還有幾個人(主要是我到目前爲止)的迴應。如果這給任何人造成問題,那麼Reboltutorial可以切換到REBOL特定的論壇之一以獲得他/她的Q&A支持。 – Sunanda 2009-09-22 13:57:59

回答

1

的這裏的問題是,組成是吃所有表達式在括號中。你很高興它吃(以點亮的詞「/」),但是你認真不希望它吃(附加輸出類),因爲這是爲在解析方言。

有可能是一個聰明的做法,但這應該工作:刪除通過執行點燃字解析規則之外工作撰寫 ...

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

0

我重新發布代碼註釋,因爲它是不可讀,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