-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support matching strings with templates #4
Comments
Once this is done, we should consider supporting using quasi quoted templates as Template Haskell patterns. For example: case "http://search.example/?query=hello" of
[uriTemplate|http://search.example/{?query}|] -> print query
_ -> pure () |
I think it could make sense to use URI templates for routing web applications, but doing so with a straightforward However I don't think it's necessary, especially for a first stab, to support matching a bunch of URI templates in a performant fashion. It's just something to think about. |
One interesting thing about this is that if you consider parsing to march along left to right, you could use earlier parses to disambiguate repeated variables. Not something I'd expect to ever come up in real life, but here's an example:
Naively the You don't even really need the left to right process to make that work. It's just that your end result has to be consistent for all the variables matched. |
One minor problem with pattern matching on URI template quasi quotes is that variable names may not be valid Haskell identifiers. For example:
Maybe none of that matters. I think TH can generate identifiers that the parser would reject, so it probably won't fail. And since the template is known at compile time, the user can simply choose variable names that work. |
I'm making progress on the gh-4-match branch. I've got extremely basic matching working right now. That means no operators, no modifiers, and only strings. Supporting everything else is going to be a challenge, that's for sure. Fortunately the existing test suite exercises all the interesting cases when expanding templates, which can be rejiggered to test parsing them too. Off the top of my head, I expect the most challenging things will be:
|
This has really nerd sniped me. I'm now making progress in the I think supporting prefix modifiers shouldn't be too bad. I have no plans to support matching lists, associative arrays, or explode modifiers. They're just too complicated. |
Motivated by #3. It should be possible to match a string, like
http://search.example/?query=hello
, against a template, likehttp://search.example/{?query}
, to produce values,like [("query", stringValue "hello")]
.This parsing is potentially ambiguous. If this functionality is provided, it could produce a list of possible matches. Or it could follow some rule, like expressions are as greedy as possible.
Since this is not something that's defined by the RFC, it would be worthwhile to come up with some test cases exercising this using a variety of operators and values.
The text was updated successfully, but these errors were encountered: