Stuck on Parse - Need Help
[1/6] from: carlos:lorenz:gmai:l at: 5-Aug-2008 13:49
Hi list,
I would appreciate some help on this parse matter.
I have the following string:
corpo: {
Evento: Boxe - Preliminares
Início: 09/08/2008 02:30
Fim: 09/08/2008 05:45
Sinopse: Acompanhe ao vivo as preliminares do boxe, categoria médio (até
75kg), direto do Ginásio dos Trabalhadores.
Evento: Handebol Masculino
Início: 09/08/2008 22:00
Fim: 09/08/2008 23:00
Sinopse: Acompanhe ao vivo a estréia de Croácia x Espanha no torneio
masculino, em jogo válido pelo Grupo A, direto do Ginásio do Centro
Olímpico.
Evento: Vôlei de Praia - Masc.
Início: 09/08/2008 23:00
Fim: 10/08/2008 00:00
Sinopse: Xu e Wu, da China, Gosch e Horst, da Áustria, disputam, nas areias
da Arena de Vôlei de Praia, o jogo válido pela 1Ş rodada do Grupo A.
}
And I need to have some data out of the string written on a file like this:
------
Boxe - Preliminares
09/08/2008 02:30
09/08/2008 05:45
------
Handebol Masculino
09/08/2008 22:00
09/08/2008 23:00
------
Vôlei de Praia - Masc.
09/08/2008 23:00
10/08/2008 00:00
Here is the code I am trying to run with no success:
REBOL[]
corpo: {
Evento: Boxe - Preliminares
Início: 09/08/2008 02:30
Fim: 09/08/2008 05:45
Sinopse: Acompanhe ao vivo as preliminares do boxe, categoria médio (até
75kg), direto do Ginásio dos Trabalhadores.
Evento: Handebol Masculino
Início: 09/08/2008 22:00
Fim: 09/08/2008 23:00
Sinopse: Acompanhe ao vivo a estréia de Croácia x Espanha no torneio
masculino, em jogo válido pelo Grupo A, direto do Ginásio do Centro
Olímpico.
Evento: Vôlei de Praia - Masc.
Início: 09/08/2008 23:00
Fim: 10/08/2008 00:00
Sinopse: Xu e Wu, da China, Gosch e Horst, da Áustria, disputam, nas areias
da Arena de Vôlei de Praia, o jogo válido pela 1Ş rodada do Grupo A.
}
out-file: to-file "arq.txt"
parse corpo [
any
[
thru "Evento:" copy evt to newline (write/append
out-file rejoin ["------" newline evt newline]) |
thru "Início:" copy ini to newline (write/append
out-file rejoin [ini newline]) |
thru "Fim:" copy fim to newline (write/append
out-file rejoin [fim newline]) |
]
to end
]
Thanks for any help
--
Carlos Lorenz
[2/6] from: brock:kalef:innovapost at: 5-Aug-2008 13:05
Carlos,
It seemed to work fine for me when you remove the '|' symbol from the any[] portion
of your parse rule.
Brock
[3/6] from: Tom::Conlin::gmail::com at: 5-Aug-2008 10:39
Carlos Lorenz wrote:
> Hi list,
> I would appreciate some help on this parse matter.
<<quoted lines omitted: 64>>
> ]
> Thanks for any help
rebol[]
corpo: {
Evento: Boxe - Preliminares
In=EDcio: 09/08/2008 02:30
Fim: 09/08/2008 05:45
Sinopse: Acompanhe ao vivo as preliminares do boxe, categoria m=E9dio
(at=E975kg), direto do Gin=E1sio dos Trabalhadores.
Evento: Handebol Masculino
In=EDcio: 09/08/2008 22:00
Fim: 09/08/2008 23:00
Sinopse: Acompanhe ao vivo a estr=E9ia de Cro=E1cia x Espanha no torneio
masculino, em jogo v=E1lido pelo Grupo A, direto do Gin=E1sio do Centro
Ol=EDmpico.
Evento: V=F4lei de Praia - Masc.
In=EDcio: 09/08/2008 23:00
Fim: 10/08/2008 00:00
Sinopse: Xu e Wu, da China, Gosch e Horst, da =C1ustria, disputam, nas areias
da Arena de V=F4lei de Praia, o jogo v=E1lido pela 1=AA rodada do Grupo A.
}
out-file: to-file "arq.txt"
write out-file ""
parse/all corpo [
any[
thru "Evento:" copy evt thru newline
(write/append out-file rejoin ["------" newline evt])
thru "In=EDcio:" copy ini thru newline
(write/append out-file ini)
thru "Fim:" copy fim thru newline
(write/append out-file fim)
]
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
------
Boxe - Preliminares
09/08/2008 02:30
09/08/2008 05:45
------
Handebol Masculino
09/08/2008 22:00
09/08/2008 23:00
------
V=F4lei de Praia - Masc.
09/08/2008 23:00
10/08/2008 00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
use parse/all with blocks of rules more often than not
your order is fixed so alteration is not needed
to end is only needed to get parse to return true bailing out early
good morning and I think I will go have my cup of tea.
[4/6] from: jonwhispa::googlemail::com at: 5-Aug-2008 20:10
Hi,
The first "thru" would match and the parsing would end and go back to "any"
then matching the first "thru" again and again.
You just needed to remove the "thru"`s and add a "skip" at the end to pass
over any extra text
out-file: to-file "arq.txt"
parse corpo [
any [
"Evento:" copy evt to newline (write/append out-file rejoin
["------" newline evt newline]) |
"Início:" copy ini to newline (write/append out-file rejoin [ini
newline]) |
"Fim:" copy fim to newline (write/append out-file rejoin [fim
newline]) |
skip
]
]
Slightly different version than the others, with a single write.
out-text: ""
output: [ copy temp thru newline (append out-text trim temp) ]
parse/all corpo [ any [ "Evento:" (append out-text "--------^/") output |
Início:
output | "Fim:" output | skip ] ]
;write to-file "arq.txt" out-text
print out-text
--------
Boxe - Preliminares
09/08/2008 02:30
09/08/2008 05:45
--------
Handebol Masculino
09/08/2008 22:00
09/08/2008 23:00
--------
Vôlei de Praia - Masc.
09/08/2008 23:00
10/08/2008 00:00
Jon
2008/8/5 Carlos Lorenz <carlos.lorenz-gmail.com>
[5/6] from: carlos:lorenz:gmai:l at: 6-Aug-2008 16:09
Thanks Curley!
2008/8/5 Curley Simon <jonwhispa-googlemail.com>
> Hi,
> The first "thru" would match and the parsing would end and go back to "any"
<<quoted lines omitted: 146>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Carlos Lorenz
www.revistaeletronica.com.br
Unidade Lorenz Ltda
(11) 4034 1971
[6/6] from: carlos::lorenz::gmail::com at: 6-Aug-2008 16:10
Thanks Tom!
2008/8/5 Tom <Tom.Conlin-gmail.com>
> Carlos Lorenz wrote:
> > Hi list,
<<quoted lines omitted: 159>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Carlos Lorenz
www.revistaeletronica.com.br
Unidade Lorenz Ltda
(11) 4034 1971
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted