parsing..
[1/8] from: eric::ehrichweiss::com at: 8-Jan-2005 16:04
I'm an old school Amiga programmer(which probably means I'm among many
old friends) and was especially fond of Arexx. Well that thought brought
me to this post...
The parse command seems to need improvement unless I'm not understanding
it and I think that a great place to start might be by looking at what
Arexx does. For example. I have several projects that require a single
input line to be parsed into several variables. If I'm understanding
Rebol's parse command, it can only do one variable at a time, Arexx did
them until you were satisfied...so instead of multiple or recursive
parse commands you could do "parse input "abc" variable1 "def" variable2
ghi
variable3 "jkl" " It's as simple as that for the most part. You
can vary how the delimiters work with wildcard functions like "abc#?def"
which means that there are some characters between 'c' and 'd' that are
unknown in length. It's been a while since I used Arexx so forgive me if
my syntax is off a bit.
Anyway, if this is possible with a single line, please show me an
example since the one on the language dictionary seems very limited. And
if it isn't possible currently, what would be necessary to make it possible?
Eric
[2/8] from: krobillard:san:rr at: 8-Jan-2005 15:08
Eric,
Take a look at chapter 15 of the Users Guide
(http://rebol.com/docs/core23/rebolcore.html).
Use 'some' to continually read the input.
Rebol parse is more verbose than regexps (and by the looks of it, Rexx parse)
but it's not too bad. Here's an example:
----------------------------
input-line: "ghi 22 abc hello"
v1: v2: v2: none
blk: parse input-line none ; convert to block form first
parse blk [some[
"abc" set v1 string!
| "def" set v2 string!
| "ghi" set v3 string!
]]
print [v1 v2 v3] ; hello none 22
----------------------------
If your input format is fixed then you won't need 'some' and this might work
for you:
----------------------------
input-line: "abc hello def true ghi 22"
blk: parse input-line none
parse blk [ "abc" set v1 string! "def" set v2 string! "ghi" set v3 string! ]
print [v1 v2 v3]
----------------------------
-Karl
On Saturday 08 January 2005 13:04, Eric Haddix wrote:
[3/8] from: tomc:darkwing:uoregon at: 8-Jan-2005 15:25
>> set [a b c d] parse "1 2 3 4" none
== ["1" "2" "3" "4"]
>> a
== "1"
>> b
== "2"
>> c
== "3"
>> d
== "4"
?
On Sat, 8 Jan 2005, Eric Haddix wrote:
[4/8] from: greggirwin::mindspring::com at: 8-Jan-2005 17:03
Hi Eric,
EH> The parse command seems to need improvement unless I'm not understanding
EH> it...
EH> Anyway, if this is possible with a single line, please show me an
EH> example since the one on the language dictionary seems very limited. And
EH> if it isn't possible currently, what would be necessary to make it possible?
REBOL's PARSE command is quite different from REXX's template based
approach; just different goals. REXX's approach falls somewhere
between the two modes PARSE has in REBOL (simple splitting and true
grammar definition).
It shouldn't be too hard to write something that emulates the REXX
approach, but I don't know of any that already exist. If REXX
compatibility isn't critical (and I can't imagine that it is), taking
the spirit of a template based parsing function, and making a very
REBOLish version could be very cool.
-- Gregg
[5/8] from: volker:nitsch:gmai:l at: 9-Jan-2005 3:32
On Sat, 08 Jan 2005 16:04:17 -0500, Eric Haddix <[eric--ehrichweiss--com]> wrote:
> I'm an old school Amiga programmer(which probably means I'm among many
> old friends) and was especially fond of Arexx. Well that thought brought
<<quoted lines omitted: 7>>
> parse commands you could do "parse input "abc" variable1 "def" variable2
> "ghi" variable3 "jkl" " It's as simple as that for the most part.
parse input[
"abc" copy variable1 to "def"
"def" copy variable2 to "ghi"
"ghi"
]
> You
> can vary how the delimiters work with wildcard functions like "abc#?def"
[ .. "abc" thru "def" .. ]
> which means that there are some characters between 'c' and 'd' that are
> unknown in length. It's been a while since I used Arexx so forgive me if
> my syntax is off a bit.
>
> Anyway, if this is possible with a single line, please show me an
> example since the one on the language dictionary seems very limited. And
> if it isn't possible currently, what would be necessary to make it possible?
>
Generally there are three "versions" of parse:
The complete simple with delemiting chars
parse/all inp "^/"
The more complex with 'to 'thru 'copy, this is similar to arexx
abilities (IIRC).
copy var to "token"
goes to token and stops before it. copies the stuff.
Thus you have to skip the "token", or it is included in the next copy.
thus i write [ to "token" "token" ]. This case is rarelly needed
because there is 'thru
copy var to "delemiter" thru "begin" copy var2 to "del2"
like
thru {<a href="} copy url to {"}
thru ">" copy label to "<"
The ultracomplex is similar to EBNF and can parse
programming-languages if you really do the work.
> Eric
> --
> To unsubscribe from the list, just send an email to rebol-request
> at rebol.com with unsubscribe as the subject.
>
--
-Volker
Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem.
David
Wheeler
[6/8] from: rotenca::telvia::it at: 9-Jan-2005 12:49
Eric Haddix wrote:
>Anyway, if this is possible with a single line, please show me an
>example since the one on the language dictionary seems very limited.
>
This is not limited at all:
http://www.rebol.com/docs/core23/rebolcore-15.html
Rebol parse is a lot more powerful than ARexx parse.
--
Ciao
Romano Paolo Tenca
[7/8] from: eric::ehrichweiss::com at: 10-Jan-2005 21:28
WOW!! Thanx for all the responses. I must have slept through that
chapter and thought I was reading it because I never could get what I
*thought* should work to actually work... Ah well, at least now I know.
Back to lurking until I reach another crisis.
[8/8] from: gabriele::colellachiara::com at: 11-Jan-2005 11:30
Hi Gregg,
On Sunday, January 9, 2005, 1:03:29 AM, you wrote:
GI> It shouldn't be too hard to write something that emulates the REXX
GI> approach, but I don't know of any that already exist. If REXX
It's not the same, but somewhat similar:
http://www.colellachiara.com/soft/Libs/pattern-matching.r
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted