我在任何和解析上重读了章http://www.rebol.com/docs/core23/rebolcore-15.html但是无法实现解析这种层次结构:它有可能吗?
<Multipage>
<tab id=1>
<box id=1>
</box>
</tab>
<tab id=2>
<box id=2>
Hello
</box>
</tab>
<tab>
</tab>
<tab>
</tab>
</Multipage>
答案 0 :(得分:2)
答案 1 :(得分:1)
是的,可能而且不是很难:
data: {...}
ws-chars: charset " ^/^M^-"
ws: [any ws-chars]
rule: [
ws <Multipage> any [
ws "<tab" opt [ws "id=" copy id to ">" (print ["tab id:" id])] ">" any [
ws "<box" opt [ws "id=" copy value to ">" (print ["box id:" id])] ">"
opt [copy text to "<" (if text [?? text])]
</box>
]
ws </tab>
]
ws </Multipage> ws
]
parse/all data rule
运行此代码,您将获得输出:
tab id: "1"
box id: "1"
text: "^/ "
tab id: "2"
box id: "2"
text: "^/ Hello^/ "