tags:

views:

93

answers:

3

I want to parse orders-series below:

  orders-series: {Wordpress Profiles
  Blogger is a User
  Admin is a Blogger
  Author is a Blogger
  Subscriber is a User

  Blogger Role
  Blogger Manage Posts


  Admin Roles
  Admin Manage Site
  Manage Site Include Manage Users
  Manage Site Include Manage Themes
  Manage Site Include Manage Plugins
  }

  orders-block: copy []
  newline2: rejoin [newline newline]
  rule: [
    [some [copy orders to newline2 (append orders-block orders) thru newline2]]
    | copy orders to end (append orders-block orders)
  ]
  parse orders-series rule
  write clipboard:// mold orders-block

I got this in clipboard

[{Wordpress Profiles
Blogger is a User
Admin is a Blogger
Author is a Blogger
Subscriber is a User} "Blogger Role^/Blogger Manage Posts"]

whereas I would like to get this

  [{
  Wordpress Profiles
  Blogger is a User
  Admin is a Blogger
  Author is a Blogger
  Subscriber is a User
  }
  {
  Blogger Role
  Blogger Manage Posts
  }    
  {
  Admin Roles
  Admin Manage Site
  Manage Site Include Manage Users
  Manage Site Include Manage Themes
  Manage Site Include Manage Plugins
  }]

How should I modify my parse rule ?

Thanks.

+1  A: 

Just remove the | in front of: | copy...

+2  A: 

I think this works too:

orders: []

parse orders-series [
    any [
     newline
     | copy txt [to "^/^/" | to end] (append orders trim txt) "^/"
    ]
]
Henrik Mikael Kristensen
+2  A: 

I use a slightly different approach:

REBOL []

orders-series: {Wordpress Profiles
  Blogger is a User
  Admin is a Blogger
  Author is a Blogger
  Subscriber is a User

  Blogger Role
  Blogger Manage Posts


  Admin Roles
  Admin Manage Site
  Manage Site Include Manage Users
  Manage Site Include Manage Themes
  Manage Site Include Manage Plugins
}

char-cr-lf: charset [
  #"^(00)" - #"^(09)" #"^(0B)" - #"^(0C)" #"^(0E)" - #"^(FF)"
]

an-order: [
  [
    some [
      some [char-cr-lf] newline
    ] 
  ] 
]

rule: [
  (orders-block: copy [])
  [
    any [copy order an-order (append orders-block order) [ any newline | end]]
  ]
]

parse orders-series rule

I suspect that both Doc's and Henrik's solution would be tripped up by the additional blank line between Blogger Manage Posts and Admin Roles.

Peter W A Wood
Thanks for this answer, will try.
Rebol Tutorial