Search code examples
rebolred-lang

rebol / red parse with [to end] rule


I'm trying to understand parse from the ground up so don't tell me to use split in this case.

sentence: "This is a sentence"

parse sentence [
    any [
        [any space] copy text [to space | to end] skip
        (print text)
    ]
 ]

Why do I not get the last word in the sentence, and only:

This
is
a

Did the [to end] not work?


Solution

  • to end did work, but then you have skip there and you're already at the end, so skip fails. See this:

    >> parse sentence [any [[any space] copy text [to space | to end ] (print text) skip]]
    This
    is
    a
    sentence