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

Reduce duplicate grammar fragments #132

Closed
nmote opened this issue Mar 15, 2022 · 1 comment · Fixed by #183
Closed

Reduce duplicate grammar fragments #132

nmote opened this issue Mar 15, 2022 · 1 comment · Fixed by #183
Labels
unnecessary-complexity The grammar and/or AST is more complex than it needs to be to support a given feature

Comments

@nmote
Copy link
Contributor

nmote commented Mar 15, 2022

I'm working on adding Swift support to Semgrep (semgrep/semgrep#2232) using this grammar. Thanks for all the hard work you've put into it so far!

One issue I'm running into is that the CST that ocaml-tree-sitter-semgrep generates from the grammar includes anonymous nodes for shared grammar fragments. This isn't a problem initially, but it can lead to maintainability issues as inconsequential changes will perturb the generated names.

For example, this choice call, which is duplicated a few lines below, leads to this generated CST node. In total there are 17 such cases.

The solution is simple: just pull out shared grammar fragments into top-level rules with names. I'm happy to do the work here and put up pull requests, assuming you are amenable to these changes.

@alex-pinkus
Copy link
Owner

Sure, I’m totally amenable to that.

There are a few places where there are similar-but-not-exactly-the-same choices represented inline because of subtle differences between what’s legal in local scope vs class scope vs global scope. You’ll want to watch out for those since they impact correctness (where private isn’t legal as a modifier it becomes legal as an identifier, although that’s a bad example because it is a named rule). I think that CI would catch any regressions there, but I just mention it as something to watch out for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unnecessary-complexity The grammar and/or AST is more complex than it needs to be to support a given feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants