-
Notifications
You must be signed in to change notification settings - Fork 10
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
Simplifying grammar for ocaml-tree-sitter introduces conflict #286
Comments
What's the priority for this? I haven't looked at the problem but I hope there's a workaround by writing the original grammar differently. |
Medium prio. Would be nice to start integrating swift. |
I was hoping to put Nat on swift, but he would be blocked by this issue. |
Could I work around this in the Swift grammar by just declaring the conflict for |
Maybe, but maybe it would hide a bug/limitation in ocaml-tree-sitter-semgrep that we need to fix anyway. |
I haven't had a chance to figure this out yet and our whole team at r2c is away next week. We're getting fewer and fewer bugs with ocaml-tree-sitter but they're getting increasingly tricky. It's going to be tough for us to fix this until the week of March 7. |
Here's what I got: Unhiding the rule
ocaml-tree-sitter makes this transformation for all the hidden rules and it's always been fine but apparently this particular rule The official documentation states:
|
@alex-pinkus Forcing the rule to be inlined eliminates the conflict:
(A) Since it's important in the original grammar that module.exports = grammar({
name: "swift",
inline: $ => [
$._locally_permitted_modifiers
],
... (B) Otherwise, I think we can solve this by patching the grammar in ocaml-tree-sitter-semgrep, which is something we do to add semgrep syntax anyway. I don't think we should modify the ocaml-tree-sitter code generator to force all unhidden rules to be inlined because that may not be correct or efficient in general. Please let us know if you prefer solution A or B. |
See semgrep/ocaml-tree-sitter-semgrep#286 When generating a simplified grammar, the `ocaml-tree-sitter` code generator forces all hidden nodes to be visible. It appears that hidden nodes automatically get marked as `inline`, and that without that auto-inlining, the `_locally_permitted_modifiers` rule causes a conflict. Rather than making the semgrep folks work around their conflict, we just check the `inline` declaration into the grammar itself so that it sticks around in the simplified grammar.
I'm more than happy to put that in the original grammar -- to your point, since compilation fails without it, I'm (unintentionally) relying on that inlining behavior for correctness, so I might as well declare it. |
See semgrep/ocaml-tree-sitter-semgrep#286 When generating a simplified grammar, the `ocaml-tree-sitter` code generator forces all hidden nodes to be visible. It appears that hidden nodes automatically get marked as `inline`, and that without that auto-inlining, the `_locally_permitted_modifiers` rule causes a conflict. Rather than making the semgrep folks work around their conflict, we just check the `inline` declaration into the grammar itself so that it sticks around in the simplified grammar.
great, thank you! |
If you try ./add-simple-language https://github.com/alex-pinkus/tree-sitter-swift
and then
./test-lang swift,
then the original grammar is fine, as well as the test, but when we try to use ocaml-tree-sitter-semgrep on it, we get a conflict:
The important part is problably:
swift: Simplifying 'grammar.json' for ocaml-tree-sitter.
which introduces some conflicts.
This is for semgrep/semgrep#2232
The text was updated successfully, but these errors were encountered: