Rebol / Red Parse html rules returns true but nothing is inserted

十年热恋 提交于 2019-12-02 08:25:30

Here a solution with probe to debug

rules: [
     thru <div class="main">
     (div-count: 1)
      some [
        "<div" (probe ++ div-count) skip
      |
        "</div>" mark:  ( probe -- div-count   if div-count = 0 [insert mark "closing main div"]) skip 
      |  skip
     ]
  ]
parse/all content rules 

The problems with your rules are, that the div-count is never or seldom subtracted. The parse pointer goes straight to the next opening div as to is always the first fulfilled condition.

You can break out or better return from parse if you add a to end after a successful condition. If you are unsure use brackets for grouping [ sucessful sub-rules ... to end ]

An example with an end-rule

end-rule: [] ; or none
rules: [
    thru <div class="main">
    (div-count: 1)
    some [
        ["<div" (++ div-count) skip]
    |
        ["</div>"mark:  (-- div-count   if div-count = 0 [insert mark "closing main div"  end-rule: [to end]]) end-rule ]
    |  skip
]

]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!