Parse
[1/5] from: mccarter:uniserve at: 7-Mar-2001 14:44
I've been busting my head for a while now against parse.
I've been able to get simple rules to work famously and am able
to get a lot of good results,,, but .
Could someone please tell me where I'm going wrong here.
If I run the following script the first parse is happy
the second is not.. I have not been able to figure out what
the proper way to do this is and I have spent too long at this.
Thanks
Bill.
Using REBOL v 2.3.0.3.1
REBOL [
Title: "Test"
Author: "Gyrus"
Date: 3/02/2001
Version: 0.1
File: %test.r
]
str: {
28/11/00 27.13 28.00 26.81 27.81 +0.93 2668900
27/11/00 26.31 27.63 26.25 26.88 +0.75 4346600
24/11/00 26.56 27.13 25.88 26.13 unch 810500
22/11/00 26.25 26.44 25.88 26.13 -0.12 1757300
}
digits: charset "0123456789"
area-code: ["(" 3 digits ")"]
phone-num: [3 digits "-" 4 digits]
print parse str [ [area-code | none] phone-num]
print parse str [ copy text to [area-code | none] phone-num]
wait 10
[2/5] from: brett::codeconscious::com at: 8-Mar-2001 11:28
Hi Bill,
I'm sorry, I can't work out what you are trying to achive here.
The rules area-code and phone-num cannot be satisfied by the data you have
presented in str - or is that the point?
Can you provide a bit more information on what exactly you are trying to do.
However taking a stab at something that might help...
The data you have in str appears like it might be PABX records - if the
records are identical in structure it might be easier to tream them a line
at a time.
For example you could read them in with
block-of-lines: read/lines %pabx-data.dat
Then you get a block of lines.
Equivalently using your existing data
block-of-lines: parse/all str "^/"
Playing with each line individually
>> parse second block-of-lines none
== ["28/11/00" "27.13" "28.00" "26.81" "27.81" "+0.93" "2668900"]
Maybe you know that phone-number will always be the 7th field in the record,
so...
>> pick (parse second block-of-lines none) 7
== "2668900"
Cheers,
Brett.
[3/5] from: ryanc:iesco-dms at: 7-Mar-2001 17:15
If you are wandering why...
>> parse str [ copy text to "485-7993"]
works fine, yet...
>> parse str [ copy text to [area-code | none] phone-num]
** Script Error: Invalid argument: area-code | none.
** Where: parse str [copy text to [area-code | none] phone-num]
bombs, this is because the words 'to, 'thru, and 'skip dont seem to work
with blocks. 'Any and 'some will operate with blocks. Myself still
being quite awkward at 'parse, I am still perplexed as to how solve your
particular problem.
--Ryan
bill wrote:
> I've been busting my head for a while now against parse.
> I've been able to get simple rules to work famously and am able
<<quoted lines omitted: 29>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge. Knowledge is
limited. Imagination encircles the world.
-Einstein
[4/5] from: sterling:rebol at: 7-Mar-2001 17:16
The problem you are having with the second case is that the TO keyword
of parse cannot currently be used with a block of optional items to
parse to the first one that it reaches. This is an enhancement that
is planned for parse already.
Sterling
[5/5] from: mccarter:uniserve at: 7-Mar-2001 17:54
Thank You all
The docs are so sketchy on parse .
I was hoping for more functionality than is presently
available. I will use the pick and skip route for my string I guess.
Thanks again.
Bill.
[sterling--rebol--com] wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted
Librarian comment