Simple parse question
[1/9] from: tim:johnsons-web at: 13-Apr-2003 15:49
Hello Rebols:
I'd like to parse a string with embedded quotes:
>> parse {Don't "Mess Up"} none
; returns:
== ["Don't" "Mess Up"]
; what I'm really looking for is
== ["Don't" {"Mess} {Up"}]
Any ideas?
Pointers to docs on this appreciated too.
Thanks :-)
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com
[2/9] from: tomc:darkwing:uoregon at: 13-Apr-2003 20:31
Hi Tim,
>> words: [some [any { } copy w [to { }](append result w )] copy w to end
(append result w )]
== [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"}]
I do not know of any doc
On Sun, 13 Apr 2003, Tim Johnson wrote:
[3/9] from: mat::plothatching::com at: 14-Apr-2003 9:30
Hello Tim,
>>> parse {Don't "Mess Up"} none
TJ> ; returns:
TJ> == ["Don't" "Mess Up"]
TJ> ; what I'm really looking for is
TJ> == ["Don't" {"Mess} {Up"}]
TJ> Any ideas?
TJ> Pointers to docs on this appreciated too.
Interesting problem. I'd probably do a replace on the quote to
something else, parse it and then replace it back. Hack but I can't
think of another way of doing it.
Regards,
Mat Bettinson - +44-(0)20-83401514.
[4/9] from: lmecir:mbox:vol:cz at: 14-Apr-2003 12:24
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
[5/9] from: tomc:darkwing:uoregon at: 14-Apr-2003 9:47
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:
[6/9] from: lmecir:mbox:vol:cz at: 14-Apr-2003 20:03
Hi,
Tom wrote:
> 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
<<quoted lines omitted: 6>>
> the string is duplicated, and there is a long run of 'none.
> (this is /core 2.5.5 on solaris)
I wonder whether this deserves a feedback or not, but it doesn't look allright to me,
that is why I asked.
Regards
-Ladislav
[7/9] 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
<<quoted lines omitted: 58>>
> [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
[8/9] from: lmecir:mbox:vol:cz at: 14-Apr-2003 21:53
Hi Tim,
> Hi Guys;
> I played with Ladislav's code and Tom's code and came
<<quoted lines omitted: 14>>
> ]
> ; > ; If any sees anything wrong with this, let me know.
what if:
str:
^/a^/b^/"
? Parse/all may be needed sometimes.
Regards
-L
[9/9] from: lmecir:mbox:vol:cz at: 14-Apr-2003 23:49
Hi Tom, myself and all,
...
> but that get into a loop same as it would without the 'break.
> more confusing is the result
<<quoted lines omitted: 4>>
> (this is /core 2.5.5 on solaris)
> I wonder whether this deserves a feedback or not, but it > doesn't look
allright to me, that is why I asked.
Romano explained, that the BREAK keyword influences just the behaviour of a
block rule containing BREAK, in this case not the block with ANY, but the
block with the alternative. That is why it works this way.
Regards
-Ladislav
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted