Closed scabug closed 9 years ago
Imported From: https://issues.scala-lang.org/browse/SI-2156?orig=1 Reporter: @acruise
@acruise said: Note that I'm specifically talking about matching patterns with idiomatic XML-like syntax, e.g.:
xml match {
case <Elem/> => ...
case <Elem attr="123">{ kids: _* }</Elem> => ...
}
Of course, you can always match against scala.xml.Elem constructors but that gets ugly fast.
Jrgen Purtz (juergen purtz) said: It seems that we speak about two different problems in this ticket:
No. 1: Pattern matching is not able to accept element names plus attributes. Test case:
val xml = <a anyAttr="0815">some text</a>
xml match {
// Next statement will not compile. Remove attribute and it will
// compile (2.7.7). Is the result correct (matching regardless of attribute)?
case <a anyAttr="0815">{content}</a> => println(" match: " + content)
case other => println("no match: " + other)
}
This is first a problem of the compiler and second a possible problem of undefined behaviour.
No.2: Namespace problems because of recognition only prefixes and not URI's (as discussed by Stefan Zeiger and others in the link to nabble.com).
Willis Blackburn (willisblackburn) said: Has anything happened with this ticket? I am also frustrated by Scala's poor support for XML namespaces. Scala makes it easy to implement namespace-aware code the wrong way (by assigning meaning to the prefix) and hard to implement it the right way (by assigning meaning to the namespace URI). Ideally we should refactor the API so that it uses namespaces almost exclusively. For example, instead of passing a prefix to Elem, the code should pass a namespace URI, plus the namespace binding, which is already part of the API. The prefix should only come into play when a node is converted to or from a string.
I know that people are going to say that changing this will break code, but I think that we need to think about the future. Scala is a young language. There isn't that much code out there, and not all of it uses the XML library. Scala's XML support is unique and is a major feature of the language. It's better to take some lumps now and get it sorted out.
Willis Blackburn (willisblackburn) said: By the way I'm happy to work on it. I'd need some guidance from someone who was more familiar with the compiler but could take care of the code changes myself. Email me at wboyce@panix.com.
Willis Blackburn (willisblackburn) said: That's wboyce at panix dot com.
@paulp said: Replying to [comment:3 willisblackburn]:
Has anything happened with this ticket?
By observation I am the only one who has addressed XML bugs in recent times, and I'm definitely not working on this one. It's fine to say we should break the API and rewrite things to be better -- I totally agree -- it's a ton of work (not just technical, also you have to convince other people) and I'm not personally interested in XML so I won't be doing that work.
Nothing would make me happier than to see someone else do that work, but don't imagine it's a matter of dashing off something which seems more sensible. You will have to effectively champion your code. And don't think you can get into breaking changes without taking on at least a few of the zillions of other issues people raise from time to time (see recent scala-xml traffic for some examples.)
@SethTisue said: It isn't immediately obvious to me whether this ticket requires changes to the pattern matcher, or changes to the scala-xml library.
If the former, it's almost certainly a wontfix, as the longer term plan is to deprecate XML literals and replace them with a string-interpolator-based syntax.
If the latter, please open a new ticket at https://github.com/scala/scala-xml/issues (and include a link to this ticket).
Scala supports pattern matching against XML nodes in only a very rudimentary way. The lack of any support for namespaces may be the most glaring omission.
http://www.nabble.com/Namespace-support-in-XML-patterns-td17562546.html was a few years ago but had some fairly concrete suggestions, I'll write up a pre-pre-SIP "hopefully soon" to try to move things along.