Skip to content

Commit

Permalink
Support for mut is clause
Browse files Browse the repository at this point in the history
  • Loading branch information
Lycs-D authored and ttytm committed Mar 31, 2024
1 parent c8346f4 commit 9bdaeb9
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tree_sitter_v/bindings/node_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub enum NodeType {
match_expression_list
module_clause
multi_return_type
mut_is_clause
mutability_modifiers
mutable_expression
mutable_identifier
Expand Down Expand Up @@ -415,6 +416,7 @@ const node_type_name_to_enum = {
'match_expression_list': NodeType.match_expression_list
'module_clause': NodeType.module_clause
'multi_return_type': NodeType.multi_return_type
'mut_is_clause': NodeType.mut_is_clause
'mutability_modifiers': NodeType.mutability_modifiers
'mutable_expression': NodeType.mutable_expression
'mutable_identifier': NodeType.mutable_identifier
Expand Down
4 changes: 3 additions & 1 deletion tree_sitter_v/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,10 +1190,12 @@ module.exports = grammar({
for_statement: ($) =>
seq(
'for',
optional(choice($.range_clause, $.for_clause, $._expression)),
optional(choice($.range_clause, $.for_clause, $.mut_is_clause, $._expression)),
field('body', $.block),
),

mut_is_clause: ($) => prec.left(PREC.primary, seq('mut', $.is_expression)),

range_clause: ($) =>
prec.left(
PREC.primary,
Expand Down
2 changes: 1 addition & 1 deletion tree_sitter_v/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"node-gyp-build": "^4.8.0"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
"tree-sitter": "^0.21.1"
},
"peerDependenciesMeta": {
"tree_sitter": {
Expand Down
21 changes: 21 additions & 0 deletions tree_sitter_v/src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tree_sitter_v/src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tree_sitter_v/test/corpus/for_statement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,41 @@ for i in 0 .. 10 {
(int_literal))))
(block)))

================================================================================
Simple for is statement
================================================================================
for v is a {
}
--------------------------------------------------------------------------------

(source_file
(for_statement
(is_expression
(reference_expression
(identifier))
(plain_type
(type_reference_expression
(identifier))))
(block)))

================================================================================
Simple for mut is statement
================================================================================
for mut v is a {
}
--------------------------------------------------------------------------------

(source_file
(for_statement
(mut_is_clause
(is_expression
(reference_expression
(identifier))
(plain_type
(type_reference_expression
(identifier)))))
(block)))

================================================================================
Simple C for statement
================================================================================
Expand Down

0 comments on commit 9bdaeb9

Please sign in to comment.