diff --git a/tree_sitter_v/bindings/node_types.v b/tree_sitter_v/bindings/node_types.v index db1861ff..3c6cbb24 100644 --- a/tree_sitter_v/bindings/node_types.v +++ b/tree_sitter_v/bindings/node_types.v @@ -108,6 +108,7 @@ pub enum NodeType { match_expression_list module_clause multi_return_type + mut_is_clause mutability_modifiers mutable_expression mutable_identifier @@ -419,6 +420,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 diff --git a/tree_sitter_v/grammar.js b/tree_sitter_v/grammar.js index 16a44dca..fd4dedf5 100644 --- a/tree_sitter_v/grammar.js +++ b/tree_sitter_v/grammar.js @@ -1209,10 +1209,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, diff --git a/tree_sitter_v/package.json b/tree_sitter_v/package.json index a2431a6a..921c1149 100644 --- a/tree_sitter_v/package.json +++ b/tree_sitter_v/package.json @@ -24,7 +24,7 @@ "node-gyp-build": "^4.8.0" }, "peerDependencies": { - "tree-sitter": "^0.21.0" + "tree-sitter": "^0.21.1" }, "peerDependenciesMeta": { "tree_sitter": { diff --git a/tree_sitter_v/src/grammar.json b/tree_sitter_v/src/grammar.json index 89b4e928..c1c12440 100644 --- a/tree_sitter_v/src/grammar.json +++ b/tree_sitter_v/src/grammar.json @@ -8017,6 +8017,10 @@ "type": "SYMBOL", "name": "for_clause" }, + { + "type": "SYMBOL", + "name": "mut_is_clause" + }, { "type": "SYMBOL", "name": "_expression" @@ -8038,6 +8042,23 @@ } ] }, + "mut_is_clause": { + "type": "PREC_LEFT", + "value": 7, + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "mut" + }, + { + "type": "SYMBOL", + "name": "is_expression" + } + ] + } + }, "range_clause": { "type": "PREC_LEFT", "value": 7, diff --git a/tree_sitter_v/src/node-types.json b/tree_sitter_v/src/node-types.json index f586e068..583f0027 100644 --- a/tree_sitter_v/src/node-types.json +++ b/tree_sitter_v/src/node-types.json @@ -1403,6 +1403,10 @@ "type": "for_clause", "named": true }, + { + "type": "mut_is_clause", + "named": true + }, { "type": "range_clause", "named": true @@ -2656,6 +2660,21 @@ ] } }, + { + "type": "mut_is_clause", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "is_expression", + "named": true + } + ] + } + }, { "type": "mutability_modifiers", "named": true, diff --git a/tree_sitter_v/test/corpus/for_statement.txt b/tree_sitter_v/test/corpus/for_statement.txt index c5ef8171..e18f1512 100644 --- a/tree_sitter_v/test/corpus/for_statement.txt +++ b/tree_sitter_v/test/corpus/for_statement.txt @@ -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 ================================================================================