I’m missing some fairly simple syntax I gather. I’m trying to rewrite an element label to something else and keep everything else intact.
object htmlRule extends RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case Elem(prefix, "document", attribs, scope, child@_*) =>
Elem(prefix, "html", attribs, scope, child)
case other => other
}
}
Now, I ask for an explanation of two things:
1) What exactly does “child@_*” mean in plain English?
2) How can I capture the value of “child@_*” and just let it pass right through to the new element? Currently, I get the following error, which makes sense.
[error] found : Seq[scala.xml.Node]
[error] required: scala.xml.Node
[error] Elem(prefix, "html", attribs, scope, child)
I’m not wedded to this either, so if there’s a better way to simply change the element name of a specific node, let’s here it…
Thanks,
–tim
The notation:
Allows you to match “within” a value (the patternConstraint part) while capturing the overall value subjected to that constraint (as bindVar).
In your particular case,
child @ _*, the_means “don’t care”, the*means a sequence of values andchild @means bind child to the entire sequence.A frequent use of this capability is a nested pattern (usually mentioning case classes):
Here, the target of the match is tested to see if it is an instance of
Exprand if it is,opis bound to theExpr‘s operator,lhsandrhsare bound to its left- and right-hand sides, resp. andexpris bound to the Expr instance itself.