-
Notifications
You must be signed in to change notification settings - Fork 6
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
Question: Is it possible to match a subsequence multiple times? #8
Comments
Hi @barrywhart This is currently not possible. This is a great feature though, I have started working on it in #9 |
That's great news, thanks!! |
Fix issue #8: Add support for Some(*patterns) that matches subsequences
This is now possible. I have added a test case for your specific example: https://github.com/scravy/awesome-pattern-matching/blob/main/tests/test_issues.py#L104 Here's the description of the new feature:
|
@barrywhart If you like you can check out the repository and check it with a local build. I do let this sink in a bit as I did quite a bit of refactoring to accommodate this use case – I'll release 0.23.0 eventually Maybe you can help me understand something: I am interested in how you plan on extracting things once you matched them? For me apm was always a great tool to not just match but also extract data. The test case added has a simple extraction and I don't know the structure of your AST, so I just used strings and a simple predicate on them. Note that if you plan on using this library it might make sense to extract some common patterns as described in the short paragraph about extensibility in the README: https://github.com/scravy/awesome-pattern-matching#extensible – basically a |
Thanks, @scravy! I hope to try it this week. Yes, we will make extensive use of the Lint rules detect issues in SQL code and optionally fix them. So the typical usage of
Here are a few examples of rules that I rewrote using
|
About this, yes, we'll think about it. This raises an interesting design question, because we'll need to do similar things in 3 contexts:
So we'll need to consider the pros, cons, and effort involved in streamlining each of these use cases. Depending on the choices we make, the three may be more or less similar. I hope that makes sense. 😛 |
Thank you for sharing. It's great to see how apm is being used. I just released 0.24.1 which has the changes for Some included. |
Hi! I'm evaluating
awesome-pattern-matching
for use in the SQLFluff SQL linter package. When we write rules to lint SQL code, we often need to search the parse tree for patterns, and your package seems like a potentially great fit.I've gotten some basic patterns working, but I'm struggling with this one, and I wonder if it's supported.
A SQL
CASE
statement can have multipleWHEN
clauses, e.g.:I'd like a pattern that matches any number of
WHEN
segments in a sequence of parse nodes. TheWHEN
segments are mingled with other segments.This works:
And this works:
But I don't know how to create a pattern for the general case. For example, this attempt does not work:
Do you know of a way to do this?
The text was updated successfully, but these errors were encountered: