Here's an idea for extending the parse dialect:

>> words: make block! 10
== []
>> string-rule: ["str" skip "ng" [alpha | none]]
== ["str" skip "ng" [alpha | none]]
>> parse/all "An example string, a strong man, a strange day." extended [
[    any [
[        to-block string-rule copy word string-rule
[        (append words word)
[        ]
[    to end
[    ]
== true
>> words
== ["string" "strong" "strange"]

(to-block is like to, but accepts a rule to search for.) 'extended
is defined in the following way:

extended-words: make object! [
    to-block: func [
        rule [block!]
        /local mark
    ] [
        compose/deep [
            mark: some [(rule) to end | skip mark:]
            :mark skip :mark
        ]
    ]
]

extended: func [
    rule [block!]
    /local result temp
] [
    result: make block! length? rule
    bind rule in extended-words 'self
    while [not tail? rule] [
        either find first extended-words rule/1 [
            temp: do/next rule
            insert tail result temp/1
            rule: temp/2
        ] [
            either block? rule/1 [
                insert/only tail result extended rule/1
            ] [
                insert/only tail result rule/1
            ]
            rule: next rule
        ]
    ]
    result
]

Adding a new word means just adding it to 'extended-words.

Any comments?

Regards,
    Gabriele.
-- 
o--------------------) .-^-. (----------------------------------o
| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila |
| GIESSE on IRC     \ \-\_/-/ /  http://www.amyresource.it/AGI/ |
o--------------------) `-v-' (----------------------------------o

Reply via email to