Skip to content
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

[feature] support quantity/order rule #676

Open
HerringtonDarkholme opened this issue Oct 19, 2023 · 2 comments
Open

[feature] support quantity/order rule #676

HerringtonDarkholme opened this issue Oct 19, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Oct 19, 2023

❓Problem Now

It is hard to find nodes without children or nodes appearing in specific positions.
For example, user may want to match the first/last argument of an argument list, or to find a node with more than three children (e.g. too many arguments or too many statements).

Though it is possible to use precedes/follows and recursive matches to emulate node position rules, the procedure is definitely excruciating. (I can testify this as the author).

⭐ Suggestion

Support one additional rule:

rule:
  nthChild: 3       
  nthChild: 2n+1
  nthChild:
    position: 3 # or An+B
    ofRule:    # rule object
      pattern: pattern-rule 

💻 Use Cases

  1. Find the first/last argument
  2. Find functions with too many statements
  3. Find functions with too many arguments
  4. Find an argument at specific position of an argument list

Related issue #675

@HerringtonDarkholme HerringtonDarkholme added the enhancement New feature or request label Oct 19, 2023
@alexzhang1030
Copy link
Contributor

alexzhang1030 commented Nov 27, 2023

I want to try to implement this feature, but I'm unsure if it will be part of the composite rule or maybe create a new type like the quantity rule. 👀

@HerringtonDarkholme
Copy link
Member Author

HerringtonDarkholme commented Nov 28, 2023

Hi @alexzhang1030, thanks for your interest in ast-grep.

I am not 100% sure of the quantity rule's behavior at the moment. If you wanna grab this issue. Would you like to first write a RFC in this issue? We can discuss the behavior of the rule.

Once the behavior is well-defined, we can discuss about how to implement it.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants