0

This works great (thanks to Sunanda's suggestion 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

but I now need to add some append instructions (append output class) and it doesn't work any more:

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
Community
  • 1
  • 1
Rebol Tutorial
  • 2,738
  • 2
  • 25
  • 36
  • Well, let's see if Sunanda answers again. I don't quite understand why a tutorial is asking questions, but I'm prepared to be wrong. – Noon Silk Sep 22 '09 at 04:56
  • I am happy to answer questions on REBOL (if I know the answer) on any forum where REBOL questions are asked. The REBOL community's utilisation of Stackoverflow so far is quite small -- mainly RebolTutorial asking questions, and several people (mainly me so far) responding. If that creates problems for anyone, then Reboltutorial could switch to one of the REBOL-specific forums for his/her Q&A support. – Sunanda Sep 22 '09 at 13:57

2 Answers2

1

The problem here is that the compose is eating all the expressions in parentheses. You are happy for it to eat the (to-lit-word "/") but you seriously do not want it to eat the (append output class) because that is intended for the parse dialect.

There is probably a cleverer approach, but this should work: remove the compose by doing the lit-word work outside of the parse rule...

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

I am not entirely sure what you are trying to do with this code, but it you want to extract the set of attributes at the end, then consider this change:

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]]
Sunanda
  • 1,555
  • 7
  • 9
  • Thanks a lot, I needed the second example for doing 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 – Rebol Tutorial Sep 22 '09 at 20:02
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
Rebol Tutorial
  • 2,738
  • 2
  • 25
  • 36