-
Notifications
You must be signed in to change notification settings - Fork 16
Update julia grammar #520
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
Update julia grammar #520
Conversation
Update the Julia grammar to tree-sitter-julia#135. That PR introduced several breaking changes, including changes in the way function signatures and parameters were parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
), | ||
|
||
_statement: ($, previous) => choice( | ||
previous, | ||
$.semgrep_ellipsis, | ||
), | ||
|
||
typed_parameter: ($, previous) => choice( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing this? We can still have ellpisis in type parameters even with this removal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Julia doesn't have a distinction between expressions and patterns, so function signatures are parsed as function calls, and checked in the lowering phase (after macro expansion). Having these parameter rules added a lot of duplication and conflicts, so we removed them.
We can still have ellpisis in type parameters even with this removal?
Yes. Ellipsis would now be parsed as splat_expression
.
Hey, apologies for the delay here. I can take responsibility for this review going forward. The changes here look good, but do you plan to integrate these into Semgrep as well? We likely can't accept this PR otherwise. |
Yes, I'm currently working on the changes to semgrep itself. I opened semgrep/semgrep#10820, tho there's still some work to do there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I've released this as semgrep/semgrep-julia@f973ebd.
We will merge this once the associated Semgrep PR is merged.
The `_statement` rule doesn't need to be extended because statements are expressions and the `_expression` rule is already extended.
Hey @nmote, I added a fix for a bug in the extended grammar: It was including Could you please make a new release? |
Done! |
This PR upgrades support for Julia to a more recent version of tree-sitter-julia. - See tree-sitter/tree-sitter-julia#135 for the changes to the parser - See semgrep/ocaml-tree-sitter-semgrep#520 for the changes to semgrep-julia Some notes: - The changes to tree-sitter-julia in the linked PR were focused on producing parse trees more faithful to JuliaSyntax (the default Julia parser). However, JuliaSyntax delegates a lot of work to the lowering phase, like checking function signatures. This means that while tree-sitter produces a smaller parser, semgrep now needs to do more work to find a function's name and parameters. - Since parameters are now parsed as expressions, I left a lot of `todo` for expressions that don't constitute valid "patterns". I don't know if it might be a good idea to create an alias for `todo` to clearly indicate that we don't handle those cases because they're not valid in normal Julia (outside macros), and not because they should be handled in the future. - tree-sitter-julia now parses short functions as assignments (That's also how it's done in the reference parser). To handle this, I translate short functions into lambdas: `f(...) = ...` becomes `f = (...) -> ...`. - The special handling for `where_clause` was removed. A later version of tree-sitter-julia unified `where_clause` with `where_expression`. - One of the issues I really hoped would be fixed was #10649, but that's actually a limitation on semgrep's side! In general, I still feel there's a lot of weird hacks because semgrep's AST only considers C-like macros. --------- Co-authored-by: Nat Mote <[email protected]>
…emgrep/semgrep-proprietary#3802) This PR upgrades support for Julia to a more recent version of tree-sitter-julia. - See tree-sitter/tree-sitter-julia#135 for the changes to the parser - See semgrep/ocaml-tree-sitter-semgrep#520 for the changes to semgrep-julia Some notes: - The changes to tree-sitter-julia in the linked PR were focused on producing parse trees more faithful to JuliaSyntax (the default Julia parser). However, JuliaSyntax delegates a lot of work to the lowering phase, like checking function signatures. This means that while tree-sitter produces a smaller parser, semgrep now needs to do more work to find a function's name and parameters. - Since parameters are now parsed as expressions, I left a lot of `todo` for expressions that don't constitute valid "patterns". I don't know if it might be a good idea to create an alias for `todo` to clearly indicate that we don't handle those cases because they're not valid in normal Julia (outside macros), and not because they should be handled in the future. - tree-sitter-julia now parses short functions as assignments (That's also how it's done in the reference parser). To handle this, I translate short functions into lambdas: `f(...) = ...` becomes `f = (...) -> ...`. - The special handling for `where_clause` was removed. A later version of tree-sitter-julia unified `where_clause` with `where_expression`. - One of the issues I really hoped would be fixed was #10649, but that's actually a limitation on semgrep's side! In general, I still feel there's a lot of weird hacks because semgrep's AST only considers C-like macros. --------- Co-authored-by: Nat Mote <[email protected]> synced from OSS 06525d0 Co-authored-by: Sergio A. Vargas <[email protected]> synced from Pro 7029d9d64eb5cdd2835b9eb238b02a84fe7ec17b
…emgrep/semgrep-proprietary#3802) This PR upgrades support for Julia to a more recent version of tree-sitter-julia. - See tree-sitter/tree-sitter-julia#135 for the changes to the parser - See semgrep/ocaml-tree-sitter-semgrep#520 for the changes to semgrep-julia Some notes: - The changes to tree-sitter-julia in the linked PR were focused on producing parse trees more faithful to JuliaSyntax (the default Julia parser). However, JuliaSyntax delegates a lot of work to the lowering phase, like checking function signatures. This means that while tree-sitter produces a smaller parser, semgrep now needs to do more work to find a function's name and parameters. - Since parameters are now parsed as expressions, I left a lot of `todo` for expressions that don't constitute valid "patterns". I don't know if it might be a good idea to create an alias for `todo` to clearly indicate that we don't handle those cases because they're not valid in normal Julia (outside macros), and not because they should be handled in the future. - tree-sitter-julia now parses short functions as assignments (That's also how it's done in the reference parser). To handle this, I translate short functions into lambdas: `f(...) = ...` becomes `f = (...) -> ...`. - The special handling for `where_clause` was removed. A later version of tree-sitter-julia unified `where_clause` with `where_expression`. - One of the issues I really hoped would be fixed was #10649, but that's actually a limitation on semgrep's side! In general, I still feel there's a lot of weird hacks because semgrep's AST only considers C-like macros. --------- Co-authored-by: Nat Mote <[email protected]> synced from OSS 06525d0 Co-authored-by: Sergio A. Vargas <[email protected]> synced from Pro 7029d9d64eb5cdd2835b9eb238b02a84fe7ec17b
…emgrep/semgrep-proprietary#3802) This PR upgrades support for Julia to a more recent version of tree-sitter-julia. - See tree-sitter/tree-sitter-julia#135 for the changes to the parser - See semgrep/ocaml-tree-sitter-semgrep#520 for the changes to semgrep-julia Some notes: - The changes to tree-sitter-julia in the linked PR were focused on producing parse trees more faithful to JuliaSyntax (the default Julia parser). However, JuliaSyntax delegates a lot of work to the lowering phase, like checking function signatures. This means that while tree-sitter produces a smaller parser, semgrep now needs to do more work to find a function's name and parameters. - Since parameters are now parsed as expressions, I left a lot of `todo` for expressions that don't constitute valid "patterns". I don't know if it might be a good idea to create an alias for `todo` to clearly indicate that we don't handle those cases because they're not valid in normal Julia (outside macros), and not because they should be handled in the future. - tree-sitter-julia now parses short functions as assignments (That's also how it's done in the reference parser). To handle this, I translate short functions into lambdas: `f(...) = ...` becomes `f = (...) -> ...`. - The special handling for `where_clause` was removed. A later version of tree-sitter-julia unified `where_clause` with `where_expression`. - One of the issues I really hoped would be fixed was #10649, but that's actually a limitation on semgrep's side! In general, I still feel there's a lot of weird hacks because semgrep's AST only considers C-like macros. --------- Co-authored-by: Nat Mote <[email protected]> synced from OSS 06525d0 Co-authored-by: Sergio A. Vargas <[email protected]> synced from Pro 7029d9d64eb5cdd2835b9eb238b02a84fe7ec17b
Update the Julia grammar to tree-sitter/tree-sitter-julia#135. That PR introduced several breaking changes, including changes in the way function signatures and parameters were parsed.
(This should reduce the size of the
parser.c
in semgrep-julia by about 15MB).Checklist