- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
XML matching oddity
Fri, 2009-12-04, 03:40
I was working on XHTML conversion routine and ended with a behavior I'd like explained.
On the site I collect data from, sometime people do <B><IMG src="x.gif"/></B>.
I need the image but not the bold around it, among other thing I do some processing:
val node = <B>Alpha</B>
node match {
case <BR></BR> => println("break")
case bi @ <B><IMG/></B> => println("Bold image") //THIS IS THE BAD GUY
case <B>{text @ _*}</B> => println("Bold blob "+text)
case <B>{text}</B> => print("Bold coin "+text) //Need because of BAD GUY
}
Now after I added the line (named BAD GUY) I need an extra <B>{text}</B> or I get a match error. Can some one explain why this happens?
Thomas
On the site I collect data from, sometime people do <B><IMG src="x.gif"/></B>.
I need the image but not the bold around it, among other thing I do some processing:
val node = <B>Alpha</B>
node match {
case <BR></BR> => println("break")
case bi @ <B><IMG/></B> => println("Bold image") //THIS IS THE BAD GUY
case <B>{text @ _*}</B> => println("Bold blob "+text)
case <B>{text}</B> => print("Bold coin "+text) //Need because of BAD GUY
}
Now after I added the line (named BAD GUY) I need an extra <B>{text}</B> or I get a match error. Can some one explain why this happens?
Thomas
Sat, 2009-12-05, 19:07
#2
Re: XML matching oddity
If you get an exception when you compile something, it is a bug.
On Sat, Dec 5, 2009 at 3:05 AM, Cay Horstmann <cay.horstmann@gmail.com> wrote:
--
Daniel C. Sobral
I travel to the future all the time.
On Sat, Dec 5, 2009 at 3:05 AM, Cay Horstmann <cay.horstmann@gmail.com> wrote:
I am pretty sure this is a bug. When I try this in the REPL
node match {
case <BR></BR> => "break"
case bi @ <B><IMG/></B> => "Bold image " + bi
case <B>{text @ _*}</B> => "Bold other " + text.toString()
case _ => "something else"
}
I kill it with a stack trace
Exception in thread "main" scala.tools.nsc.symtab.Types$TypeError:
too many arguments for method body%2: ()java.lang.String
at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:318)
at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:268)
at scala.tools.nsc.typechecker.Infer$Inferencer.errorTree(Infer.scala:272)
,,,
But the following works fine:
node match {
case <BR></BR> => "break"
case bi @ <B><IMG/></B> => "Bold image " + bi
case <B>{text @ _*}</B> => "Bold other "
case _ => "something else"
}
The only difference is that I am not using the text variable.
Cheers,
Cay
On Thu, Dec 3, 2009 at 6:40 PM, Thomas Sant Ana <mailleux@gmail.com> wrote:
> I was working on XHTML conversion routine and ended with a behavior I'd
> like explained.
>
> On the site I collect data from, sometime people do <B><IMG
> src="x.gif"/></B>.
>
> I need the image but not the bold around it, among other thing I do some
> processing:
>
>
> val node = <B>Alpha</B>
>
>
> node match {
> case <BR></BR> => println("break")
>
> case bi @ <B><IMG/></B> => println("Bold image") //THIS IS THE BAD
> GUY
> case <B>{text @ _*}</B> => println("Bold blob "+text)
> case <B>{text}</B> => print("Bold coin "+text) //Need because of BAD
> GUY
>
> }
>
> Now after I added the line (named BAD GUY) I need an extra <B>{text}</B> or
> I get a match error. Can some one explain why this happens?
>
> Thomas
>
--
Daniel C. Sobral
I travel to the future all the time.
=> "break" case bi @ => "Bold image " + bi case {text @ _*} => "Bold other " + text.toString() case _ => "something else" } I kill it with a stack trace Exception in thread "main" scala.tools.nsc.symtab.Types$TypeError: too many arguments for method body%2: ()java.lang.String at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:318) at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:268) at scala.tools.nsc.typechecker.Infer$Inferencer.errorTree(Infer.scala:272) ,,, But the following works fine: node match { case
=> "break" case bi @ => "Bold image " + bi case {text @ _*} => "Bold other " case _ => "something else" } The only difference is that I am not using the text variable. Cheers, Cay On Thu, Dec 3, 2009 at 6:40 PM, Thomas Sant Ana wrote: > I was working on XHTML conversion routine and ended with a behavior I'd > like explained. > > On the site I collect data from, sometime people do src="http://www.scala-lang.org/x.gif"/>. > > I need the image but not the bold around it, among other thing I do some > processing: > > > val node = Alpha > > > node match { > case
=> println("break") > > case bi @ => println("Bold image") //THIS IS THE BAD > GUY > case {text @ _*} => println("Bold blob "+text) > case {text} => print("Bold coin "+text) //Need because of BAD > GUY > > } > > Now after I added the line (named BAD GUY) I need an extra {text} or > I get a match error. Can some one explain why this happens? > > Thomas >