parse again
[1/6] from: gchiu::compkarori::co::nz at: 28-Dec-2000 12:48
I find parse baffling ...
I have a diary I want to parse like this
test: { 9.00 am Get up 9.30 am have breakfast 10.00 am
read email }
I want to copy all the entries for each time period,
including the time, to a list.
I tried:
digit: charset "0123456789"
parse test [ to 1 2 digit (print 1) ]
doesn't even get me past the 9 ...
--
Graham Chiu
[2/6] from: al:bri:xtra at: 28-Dec-2000 13:48
> I have a diary I want to parse like this:
>
> test: { 9.00 am Get up 9.30 am have breakfast 10.00 am read email }
An alternative is to use block! parse:
>> test: [ 9:00 "Get up" 9:30 "Have breakfast" 10:00 "read email"]
== [9:00 "Get up" 9:30 "Have breakfast" 10:00 "read email"]
>> parse test [any [time! string!]]
== true
Of course, that requires that the data be in Rebol compatible format.
> I want to copy all the entries for each time period, including the time,
to a list.
> I tried:
>
> digit: charset "0123456789"
>
> parse test [ to 1 2 digit (print 1) ]
'to is a little limited. It only seems to work with string! or end.
What you need is something like:
Test: { 9.00 am Get up 9.30 am have breakfast 10.00 am read email}
Diary: make block! 0
Digit: charset "0123456789"
LoAlpha: charset "abcdefghijklmnopqrstuvwxyz"
HiAlpha: charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Alpha: union LoAlpha HiAlpha
Time: [1 2 Digit "." 2 Digit ["am" | "pm"]]
parse test [
any [
copy TimeEntry Time copy Entry some [Alpha | " "] (
repend Diary [TimeEntry trim Entry]
)
| skip
]
end
]
>> Diary
== ["9.00 am" "Get up" "9.30 am" "have breakfast" "10.00 am" "read email"]
I hope that helps!
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[3/6] from: tim:johnsons-web at: 27-Dec-2000 17:19
Hi Graham:
Like I said, am on hiatus, but do you have "rebol the official
guide"?
If so, Elan has a "tutorial" starting on page 330.
If you don't, post a response and I will submit something.
:) Take care
Tim
Graham Chiu wrote:
[4/6] from: gchiu:compkarori at: 29-Dec-2000 16:33
On Thu, 28 Dec 2000 13:48:39 +1300
"Andrew Martin" <[Al--Bri--xtra--co--nz]> wrote:
> >> Diary
> == ["9.00 am" "Get up" "9.30 am" "have breakfast" "10.00
> am" "read email"]
>
> I hope that helps!
Thanks Andrew. Now to get it working on my real data ...
--
Graham Chiu
[5/6] from: gchiu:compkarori at: 29-Dec-2000 16:34
On Wed, 27 Dec 2000 17:19:57 -0900
Tim Johnson <[tim--johnsons-web--com]> wrote:
> If so, Elan has a "tutorial" starting on page 330.
> If you don't, post a response and I will submit
> something.
Hi Tim,
I have Elan's book - but that chapter didn't help me much
with this problem which Andrew is suggesting is a bug or
limitation with 'to
--
Graham Chiu
[6/6] from: rebol:techscribe at: 29-Dec-2000 0:59
Hi Graham,
Parsing is very simple. It takes a minimal effort. And you always know
exactly what you are doing. If you are writing parse rules and any of
these statements do not make sense, then you have uncovered a conceptual
bug.
For block parsing you should consult with Chapter 22 (REBOL Dialecting).
A simple solution to your problem using block parsing would be:
test: [9:00 am Get up 9:30 am Eat breakfast 10:00 am Read email]
sp: does [prin " "]
rule: [set t time! (prin t sp) set ampm word! (prin ampm sp) some [ set
activity word! (prin activity sp) ] (prin newline)]
>> parse test [some rule]
9:00 am Get up
9:30 am Eat breakfast
10:00 am read email
Doing it with a string is not much more difficult:
digits: charset "0123456789"
test: {9:00 am Get up 9:30 am Eat breakfast 10:00 am read email}
rule: [ (print "") begin: 1 2 digits ":" 2 digits end: (prin copy/part
begin end) | here: skip (prin here/1) ]
>> parse/all test [some rule]
9:00 am Get up
9:30 am Eat breakfast
10:00 am read email
Hope that helps,
Elan
Graham Chiu wrote: