Rebol解析规则:如何更正规则以分隔段落

时间:2009-09-12 15:12:11

标签: 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
  }

  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

我在剪贴板中得到了这个

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

虽然我想得到这个

  [{
  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
  }]

我应该如何修改我的解析规则?

感谢。

3 个答案:

答案 0 :(得分:2)

我认为这也有效:

orders: []

parse orders-series [
    any [
        newline
        | copy txt [to "^/^/" | to end] (append orders trim txt) "^/"
    ]
]

答案 1 :(得分:2)

我使用稍微不同的方法:

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

我怀疑Doc和Henrik的解决方案会因Blogger管理帖子和管理员角色之间的额外空白而被绊倒。

答案 2 :(得分:1)

只需删除|在前面:|复制...