Skip to content

Commit

Permalink
chore: Update tree-sitter-rust (1/n)
Browse files Browse the repository at this point in the history
We are way behind on tree-sitter-rust. When I tried to do a big jump I
ran into a bunch of problems, so I'm going to do it bit by bit.

Test plan: Automated tests
  • Loading branch information
nmote committed Nov 7, 2023
1 parent 38d8ef5 commit c4e674d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lang/semgrep-grammars/src/semgrep-rust/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = grammar(standard_grammar, {
},

// Statement ellipsis: '...' not followed by ';'
_expression_statement: ($, previous) => {
expression_statement: ($, previous) => {
return choice(
previous,
prec.right(100, seq($.ellipsis, ';')), // expression ellipsis
Expand Down
44 changes: 25 additions & 19 deletions lang/semgrep-grammars/src/semgrep-rust/test/corpus/semgrep.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ impl $CLASS {
(type_identifier)))
(type_identifier)
(block
(if_expression
(identifier)
(block
(identifier))
(else_clause
(expression_statement
(if_expression
(identifier)
(block
(identifier)))))))))
(identifier))
(else_clause
(block
(identifier))))))))))

================================================================================
Typed Metavariables
Expand All @@ -44,12 +45,13 @@ x == ($Y : String);
--------------------------------------------------------------------------------

(source_file
(binary_expression
(identifier)
(parenthesized_expression
(semgrep_typed_metavar
(identifier)
(type_identifier)))))
(expression_statement
(binary_expression
(identifier)
(parenthesized_expression
(semgrep_typed_metavar
(identifier)
(type_identifier))))))

================================================================================
Ellipsis for expression
Expand All @@ -76,7 +78,8 @@ impl Foo {
(let_declaration
(identifier)
(integer_literal))
(ellipsis)
(expression_statement
(ellipsis))
(let_declaration
(identifier)
(integer_literal)))))))
Expand Down Expand Up @@ -106,7 +109,8 @@ impl Foo {
(let_declaration
(identifier)
(integer_literal))
(ellipsis)
(expression_statement
(ellipsis))
(let_declaration
(identifier)
(integer_literal)))))))
Expand Down Expand Up @@ -314,10 +318,11 @@ foo($...X);
--------------------------------------------------------------------------------

(source_file
(call_expression
(identifier)
(arguments
(identifier))))
(expression_statement
(call_expression
(identifier)
(arguments
(identifier)))))

================================================================================
Statement metavariable ellipsis
Expand All @@ -328,4 +333,5 @@ $...X;
--------------------------------------------------------------------------------

(source_file
(identifier))
(expression_statement
(identifier)))

0 comments on commit c4e674d

Please sign in to comment.