Closed
Conversation
ecd494f to
d257cab
Compare
14 tasks
Member
|
Thanks for the work here, @pcattori. We are aligned on goals and I'm excited about this work. I'd rather not merge anything to
OR
It's totally up to you. |
Contributor
Author
|
Ok cool let's do the feature branch for this then and not land into |
d257cab to
8fa7520
Compare
- track param names instead of param indices - cache in `#variants` - `get` for `.variants` instead of `.variants()`
Contributor
Author
|
superseded by #10935 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
During the development of
route-pattern, the design for the Route Pattern DSL changed many times. This wasn't unexpected, but it did mean that the matching APIs (ArrayMatcher,TrieMatcher, etc.) and parsing algorithms always had to "catch up" to the newest DSL changes. Over time, this led to some bolted-on bits and some gaps in the matching/parsing.Additionally, the current
ArrayMatcherandTrieMatcheraren't guaranteed to return the same "best" match.ArrayMatcherjust bails as soon as it finds its first match andTrieMatcherdoes some ad-hoc scoring.The goal moving forward is to spec out the parsing/matching (via unit tests + docs) and implement a simple, consistent ranking metric for
ArrayMatcher,TrieMatcher, or any other matcher.Here's my plan:
PartPattern.{parse,variants,toString}(this PR)RoutePattern.{parse,join}TrieMatcher.{add,matchAll}(w/o ranking)TrieMatcher.{match, matchAll}ArrayMatcher.{add,match,matchAll}PartPatternAs a first step towards this goal, this PR implements a new design for the parts of a Route Pattern that are allowed to use the pattern DSL. Today, that includes the protocol, hostname, and pathname, but in the future its likely that the protocol will be simplified to just accept the known network schemes (
http,https,http(s),ws,wss,ws(s),ftp, ...).Knowing that we want to eventually use
PartPatterns withinRoutePatterns to power aTrieMatcher, this new implementation aims for a simpler flat AST:This AST representation has a couple benefits over the previous implementation:
Traversal is simpler and faster since its just a for-loop where you can decide to skip any optionals as you go. Specifically, variants (for construction trie branches) are trivial to implement.
Feature detection is simpler and faster. For example, does this part pattern have any params? Check
ast.paramNames.length > 0? Any optionals? Checkast.optionals.size > 0. Etc.Joining patterns is more efficient. Previously,
RoutePattern.joinreparsed the entire pathname on every invocation whereas with this AST, we can simple concatenate the twopathnames(adding a/text node between them as necessary) and quickly apply an offset to the second pattern'sparamNamesandoptionals.To be clear, the goal isn't necessary to be faster at parsing part patterns — that can come later with optimizations if needed — but to have a purpose-built structure for our DSL.