更改/部分无法按预期进行解析

发布于 2024-08-29 02:37:51 字数 891 浏览 6 评论 0原文

根据 http://www.rebol.com/docs/core23/rebolcore- 15.html

您可以使用change/part来解析和替换,但这不适用于我只是尝试

<mytag > ... </mytag>

用“MyString”替换块

content:  {<mytag id="a" 111111111111111>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="b" 22222222222222222>
</mytag>

<mytag id="c" 3333333333333>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="d" 444444444444444>
</mytag>
}


mytag: [  to {<mytag} start: (
)
  thru {<mytag}
  to {id="} thru {id="} copy ID to {"} thru {"}
  to {</mytag>} 

  thru {</mytag>} 
  ending:

  (change/part start "mystring" ending)
  mark:
  (  write clipboard:// mark
  input)  
]

rule: [any mytag to end]

parse content rule

According to http://www.rebol.com/docs/core23/rebolcore-15.html

You can use change/part to parse and replace but that doesn't work well with this where I just try to replace the block

<mytag > ... </mytag>

by "MyString"

content:  {<mytag id="a" 111111111111111>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="b" 22222222222222222>
</mytag>

<mytag id="c" 3333333333333>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="d" 444444444444444>
</mytag>
}


mytag: [  to {<mytag} start: (
)
  thru {<mytag}
  to {id="} thru {id="} copy ID to {"} thru {"}
  to {</mytag>} 

  thru {</mytag>} 
  ending:

  (change/part start "mystring" ending)
  mark:
  (  write clipboard:// mark
  input)  
]

rule: [any mytag to end]

parse content rule

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

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

发布评论

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

评论(2

深者入戏 2024-09-05 02:37:51

Ladislav 的建议是在不更改输入流的情况下解决这个问题,这可能会产生性能问题并且更难以调试。只需单独构建您的输出即可。例如

result: copy ""

mytag: [
  [
    copy text to {<mytag} (if text [append result text])
    thru {<mytag}
    to {id="} thru {id="} copy ID to {"} thru {"}
    thru {</mytag>} 
    (append result reform ["__" ID "__"])
  ]
  | 
  skip
]

rule: [any mytag to end]

parse content rule

result

Ladislav's suggestion is to solve it without changing the input stream, which can have performance issues and is harder to debug. Just build up your output separately. e.g.

result: copy ""

mytag: [
  [
    copy text to {<mytag} (if text [append result text])
    thru {<mytag}
    to {id="} thru {id="} copy ID to {"} thru {"}
    thru {</mytag>} 
    (append result reform ["__" ID "__"])
  ]
  | 
  skip
]

rule: [any mytag to end]

parse content rule

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