Parsing 如果块中的项目像单个元素块一样处理,那么如何解析项目序列?

Parsing 如果块中的项目像单个元素块一样处理,那么如何解析项目序列?,parsing,rebol,rebol3,Parsing,Rebol,Rebol3,我需要一个等价的情况,比如: [ {Foo} http://example.com/some/stuff.html separator ] …的处理方式就像您编写的: [ [{Foo}] [http://example.com/some/stuff.html] [separator] ] 增加一点复杂性的是,如果将项放在块中,那么它可能有参数: [ [{Foo} /some-refinement] [http://example

我需要一个等价的情况,比如:

[
    {Foo}
    http://example.com/some/stuff.html
    separator
]
…的处理方式就像您编写的:

[
    [{Foo}]
    [http://example.com/some/stuff.html]
    [separator]
]
增加一点复杂性的是,如果将项放在块中,那么它可能有参数:

[
    [{Foo} /some-refinement]
    [http://example.com/some/stuff.html {stuff caption} 3]
    [separator dashed-line]
]
我想要一个基于解析的引擎,它可以为
{Foo}
[{Foo}]
[{Foo}/一些改进]
运行相同的处理程序(让我们称之为字符串处理程序),并且仅使用正确数量的参数调用它

写这篇文章不需要解析很容易。。。单个元素被包装在临时块中(如果它不是块)。然后在案例陈述中测试第一项。但我想将其转换为基于解析的,其中一个分支使用,而另一个分支不使用,无需重复代码

它将需要支持嵌套,因此您可能需要处理以下内容:

[http://example.com/some/stuff.html [{Foo} /some-refinement] 3]

我希望以下内容可以作为您解决问题的基础

以下操作在R2和R3中执行完全相同的操作。这两个平台的PARSE's'操作非常不同,因此我设置了一个简单的保护
[.here.:block!:.here.]
,它修复了两个平台中不同的bug情况

我使用了hook函数,它允许将数据浏览和数据评估清晰地分开。如果仔细观察,您会注意到=enter block?=:规则是全局的,并且在运行“发射值”函数之前设置了切换其含义的代码。。。因此,在某些情况下,您可能实际上希望使用emit值来设置不同的规则

请注意,我并没有假设任何类型的已知结构,因为您的解释似乎是针对非结构化数据集的

还要注意,测试B被设置为字符串,因此我们可以直接在字符串输入数据上使用包装器:

rebol [
    author: "Maxim Olivier-Adlhoch"
    date: 2014-02-08
    license: "public domain"
]


A: [
    [{Foo}]
    [http://example.com/some/stuff.html]
    [separator]
]


B: {[
    {Foo}
    http://example.com/some/stuff.html
    separator
]}


C: [
    [{Foo} /some-refinement]
    [http://example.com/some/stuff.html {stuff caption} 3]
    [separator dashed-line]
]


D: [http://example.com/some/stuff.html [{Foo} /some-refinement] 3]


depth: ""
enter-block: func [][
    prin depth 
    print "[" 
    append depth "^-"
]

quit-block: func [][
    remove depth 
    prin depth 
    print "]"
]

emit-value: func [value][
    prin depth 
    probe value
]

=enter-block?=: none

=block=: [
    (
        =enter-block?=: [into =block=] ; we enter blocks by default
        enter-block
    )
    some [
        .here.: block! :.here. ; only enter blocks (R3/R2 compatible)
        (if 1 = length? .value.: first .here. [ =enter-block?=: [skip]  emit-value first .value. ])
        =enter-block?=
        | set .value. skip ( emit-value .value. )
    ]
    (quit-block)
]

STRING-HANDLER: func [data][
    if string? data [
        data: load data
    ]

    parse data =block=
]

STRING-HANDLER A
STRING-HANDLER B
STRING-HANDLER C
STRING-HANDLER D

ask "press enter to quit ..."

谢谢你的努力。事实上,我的结局有点不同。。。。。。但事实上,我一直在重新考虑一些问题。如果你想插嘴的话,这里有一些Trello卡片,上面写的是与此密切相关的(以及)