NancyFx/Nancy — pull request #988 by grumpydev (2013-02-15 18:32:11+00:00)
Title: New route resolution engine

Switched from the old approach to a route Trie, which is faster, and much more readable.

Also removed the Indiana Jones and the Tuple of Doom that the old route resolver was returning and replaced it with a class.

Routing should (hopefully) be unaffected, but to be clear the new system works on route length and scoring as follows:

* Longest routes take precedence - if a route has 5 matched segments it will win over one with 4, regardless of what kind of nodes they were. In the case of node that have 'default' values, if the default value is used then the node isn't counted towards the length.
* Node scoring - if more than one result has the same length then each node in each route is totted up to a score, and the highest score wins. The scores for each node type are currently:
* Literal node - 10000
* Capture node - 1000
* Regex node - 1000
* Greedy capture node - 0

The full set of node types are:

* Literal node - just text
* Capture node - {foo}
* Optional capture node - {foo?}
* Optional capture node with default - {foo?defaultValue}
* RegEx node - (?\d{2,4})
* Greedy capture node - {foo*}

Note that now captures are *not* greedy by default, you need to specify the greedy capture if that's the behaviour you want (this fixes #785)