0

これはうまく機能します(Sunandaの提案のおかげで[a / b]を解析するにはどうすればよいですか?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 "/")を食べて満足していますが、 (出力クラスを追加)を食べたくないのは、構文解析方言を対象としているためです。

おそらくもっと賢いアプローチがありますが、これはうまくいくはずです:解析ルールの外で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

判読できないので、コメントでコードを再投稿します。私が正確にやりたかったのは、次のとおりです。

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 に答える