compareMatches ( ( ( )
Compare a pair of (rule,result) tuples in "most-specific first" order
Designed primarily for use as a list.sort() "compare function", this
function returns 1, 0, or -1, according to the order that the
(rule,result) pairs should be ordered in. Zero indicates that the
rules are overlapping or equivalent, and therefore have no discernible
ordering. Note that this may cause problems when sorting rules which
are disjoint (non-overlapping), if the sorting algorithm assumes equality
is transitive! For its use in this module, however, it is always sorting
a list of rules that have all matched the same value, which means that
none of the rules are disjoint (since they must at least overlap in the
area of the matched value). Therefore, either all rules are overlapping
(and thus equal) or one or more rules are "more specific" than any of
the overlapping rules. This suffices for sorting matches, since we
want all the unambiguous matches first, followed by the ambiguous ones.
(There may also be some "less specific" rules that encompass the
ambiguous ones, but since we fail at the first ambiguity, this is
unimportant.
|