[REBOL] Re: Simple parse question
From: tim:johnsons-web at: 14-Apr-2003 10:32
Hi Guys;
I played with Ladislav's code and Tom's code and came
up with the following:
; ==============================================================
; 'def is a hack of Andrew's 'sub function which automatically
; handles local words
make-words: def[str[string!]][
either empty? (intersect str rejoin[#"^-" #"^/" #"^M" #"^(page)" " " ])[str][
words: [
some [
any { } copy w [to { }](append result w )
] copy w to end
(append result w )
]
result: copy [] parse str words
result
]
]
; ==============================================================
; If any sees anything wrong with this, let me know.
; :-) "Help me before I hurt myself"
>> make-words {"test" "this"}
== [{"test"} {"this"}]
>> make-words {"test}
== {"test}
I sure appreciate the help!!
-tim-
> Good morning Ladisav,
>
> it is true, I was only answering the specific question
>
> the rule I would expect to use (and did try last night) is
>
> words: [some [any { } copy w [[to { }] | [to end break]](append result w
> )]]
>
> but that get into a loop same as it would without the 'break.
>
> more confusing is the result
>
> >> result copy [] parse {Don't "Mess Up"} words
> >> result
> == ["Don't" {"Mess} {Up"} "Don't" {"Mess} {Up"} none none none ... ...
>
> the string is duplicated, and there is a long run of 'none.
>
> (this is /core 2.5.5 on solaris)
>
> On Mon, 14 Apr 2003, Ladislav Mecir wrote:
>
> > Hi Tom,
> >
> > you wrote:
> >
> > > >> words: [some [any { } copy w [to { }](append result w )] copy w to end
> > > (append result w )]
> >
> > > >> result: copy [] parse {Don't "Mess up"} words
> > > == true
> > > >> result
> > > == ["Don't" {"Mess} {up"}]
> >
> > this looks OK, but there is a bug:
> >
> > result: copy [] parse "a" words ; == false
> >
> > to accept even one-word texts I suggest:
> >
> > ws: charset [#"^-" #"^/" #"^M" #"^(page)" " "]
> > nonws: complement ws
> > fail: [end skip]
> >
> > words: [
> > (result: copy [] br: none) any [
> > br any ws [
> > end (br: fail) |
> > copy w any nonws (insert tail result w)
> > ]
> > ]
> > ]
> >
> > A more complicated question:
> >
> > how would you rewrite the rule using the new parse dialect keyword BREAK?
> >
> > Regards
> > -Ladislav
> >
> >
> > --
> > To unsubscribe from this list, please send an email to
> > [rebol-request--rebol--com] with "unsubscribe" in the
> > subject, without the quotes.
> >
> >
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com