[REBOL] Re: Parse versus Regular Expressions
From: ingo:h-o-h at: 7-Apr-2003 15:03
Hi Joel,
Joel Neely wrote:
<...>
> GIVEN:
>
> A file of lines, each of which is 80 characters, and contains:
<...>
> Thanks in advance to anyone who offers PARSE solutions!
<...>
This is one possible solution,
Kind regards,
Ingo
[REBOL [
Title: {Rebol solution to:
Re: Parse versus Regular Expressions (Joel Nealy)}
Author: "Ingo Hohmann"
]
data: {00001 This is a sentence. 20030301
00002 So 20030302
00003 is 20030302
00004 this. 20030302
00004 Error in this line. 20030302
00005* this will disappear 20030303
00006* but this won't because of sequence order 20030101
00007 The last 20030304
00008 sentence. 20030304
00009*And this will show. 20030301}
char: complement charset ""
non-point: complement charset "."
old-pre: old-post: "" ; I need no copy here
sentence: ""
parse/all data [
any [
copy pre 5 char
copy line [48 non-point | thru "."]
copy trailing any " "
copy post 8 char
opt skip ; In case there's no newline in the last line
(
either all [pre > old-pre post >= old-post][
if not #"*" = first line [
insert tail sentence line
if #"." = last sentence [
print trim/lines sentence
clear sentence
]
]
][
print rejoin ["ERROR: " pre line
either none? trailing [""][trailing] post
]
]
old-pre: pre
old-post: post
)
]
]
]