Rebol Parsing Rule:如何更正规则以分隔段落

发布于 2024-08-05 00:40:22 字数 1210 浏览 1 评论 0原文

我想解析下面的订单系列:

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

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

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的痛♀有谁懂 2024-08-12 00:40:22

我使用稍微不同的方法:

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 管理帖子和管理员角色之间的额外空行而出错。

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.

葬﹪忆之殇 2024-08-12 00:40:22

我认为这也有效:

orders: []

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

I think this works too:

orders: []

parse orders-series [
    any [
        newline
        | copy txt [to "^/^/" | to end] (append orders trim txt) "^/"
    ]
]
韬韬不绝 2024-08-12 00:40:22

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文