更新时间:2023-12-05 11:15:34
以下是使用探针进行调试的解决方案
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
您的规则存在的问题是,永远不会或很少会减去div计数.解析指针会直接指向下一个打开的 div ,因为 to 始终是第一个满足的条件.
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 ]
带有结束规则的示例
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
]
]