Search code examples
parsingrebol

Rebol PARSE rule to match to first occurrence of at least 2 #[none]s


See similar question for string case.

In R3-Alpha, I tried to adapt the @sqlab response to block case:

parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] ??]

I expect ??: [#[none] #[none] b], but get

** Script error: PARSE - invalid rule or usage of rule: none!

It's the result right and my expectation wrong? Or it's a bug?


Solution

  • I can just show a solution for Red and Rebol2. As the words in the rule are reduced automatic, you have to shield them.

    Red

    >> parse [x x x x _ a _ _ b] [to [ '_ '_] y: ]
    == false
    >> 
    >> y
    == [_ _ b]
    

    Rebol2

    >> parse [x x x x _ a _ _ b] [some [r: [ '_ '_  ] (y: r) | skip]   ]
    == true
    >> y
    == [_ _ b]
    

    After the editing of the question by HostileFork the solution for Red looks like that

    >> parse [x x x x #[none] a #[none] #[none] b] [to [none! none!] y:] 
    == false
    >> y
    == [none none b]
    >> 
    

    example according the question in the comment of giuliolunati

    >> parse  [x x x x 0 a 1 2 b]  [to [integer! integer!] y:]
    == false
    >> y
    == [1 2 b]