Joel-

Thanks for the parsing routine. There are still a few things about it 
that I need to look at a few more times for me to understand it 
perfectly, but I was able to make a re-usable function out of your 
routine. (I also changed some of the 'words because I like my scripts 
to read like "plain English.") The function follows...

REBOL []

parse-paragraphs: func [
    "Parse a document into a block of paragraphs."
    document [string!] "the document to be parsed"
][

    paragraph-block: copy []
    current-paragraph:  copy ""
    stopper:  charset {.?!:}
    non-stopper:  complement stopper
    fragment: copy ""

    sent: [
        copy fragment [any non-stopper stopper]
        (append current-paragraph fragment)
        [{^/} (append paragraph-block current-paragraph current-
paragraph: copy "")
        |{"^/} (append paragraph-block append current-paragraph {"} 
current-paragraph: copy "")
        | none
        ]
    ]

    paragraph: [
        (paragraph-block: copy []  current-paragraph: copy "")
        any sent end
        (if 0 < length? current-paragraph [append paragraph-block 
current-paragraph])
    ]

        parse/all document paragraph

        paragraph-block
]


> To make up for my omission (and my lack of time/energy last night),
> the following is a scheme for using  parse  to attack the paragraphing
> problem you posted.  I know it doesn't handle every possible case, but I
> think it can be generalized in a fairly obvious way.
> 
> Enjoy!
> 
> -jn-

Reply via email to