Choose one!
Selecting between ambiguous parses with NineML.
A while back, I refactored the way ambiguity is handled in the NineML family of Invisible XML tools. The new model supports an API that lets the user choose between different, ambiguous parses.
What was missing was any way to access that API short of writing your own Java class. Inspired by both an outstanding bug and a suggestion about how ambiguity might be represented in XML, I’ve coded up something I think is quite nice.
In CoffeeSacks, the Saxon extension functions for Invisible XML processing, you can provide a callback function in the options. This function will be called when ambiguity is detected and it can select an alternative. The full XML representation of the ambiguous parses provides about everything that is available to make the selection.
In CoffeePot, the command-line tool, you can choose to load an XSLT or XQuery function from a library, this works the same way as the CoffeeSacks callback, or you can just use XPath expressions.
You’re still better off writing an unambiguous grammar if you can, and neither of these methods allows the grammar author to specify a preference, but they do give you, the user, control.
(I believe there is a priority mechanism for the grammar author, but it appears to be wholly undocumented and perhaps under tested. I plan to work on that.)
I hope the documentation and examples in CoffeeSacks and CoffeePot are sufficient.