Rebol/Red parse:如何在2个标记之间进行复制 [英] Rebol/Red parse: how to copy between 2 marks

查看:106
本文介绍了Rebol/Red parse:如何在2个标记之间进行复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在解析规则中解析2个标记.举一个人为的例子:

I want to be able to parse between 2 marks in parse rule. For a contrieved example:

src: {a b c d e f}

rule: [
    to "b" mark1: thru "e" mark2: 
    to mark1 copy text to mark2
]

这不起作用,文本包含"[",而不是我想要的内容:

This doesn't work, text contains "[" instead of what I'd like to get:

b c d e

推荐答案

您正在尝试使用PARSE实现复制的"DO期望". PARSE的COPY正在寻找模式,而不是将系列视为位置.

You're trying to implement a "DO desire" of copying using PARSE. PARSE's COPY is looking for patterns, not treating the series as positions.

您可以通过PAREN!在解析过程中转入DO,如果解析规则到达该点,它将运行.

You can escape into DO in mid-parse via a PAREN!, it will run if the parse rule reaches that point.

src: {a b c d e f}

rule: [
    to "b" mark1: thru "e" mark2: 
    (text: copy/part mark1 mark2)
    to end ;-- not strictly necessary, but makes PARSE return true
]

parse src rule

这将为您提供b c d e

请注意,使用COPY或TO不能同时使用这两种方法. TO <series!>的意思是寻找b",而不是跳到b的位置".因此,当您说to mark1时,您正在调用另一个匹配项.如果要将解析位置设置为标记1中记录的特定位置,请在解析规则中使用:mark1.

Note that you can't have it both ways, either with COPY or with TO. TO <series!> meant "look for b", not "jump to the position of b". So when you say to mark1 you're invoking another match. If you want to set the parse position to the specific position recorded in mark1, use :mark1 in the parse rule.

这篇关于Rebol/Red parse:如何在2个标记之间进行复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆