Skip to content

Commit 25dfe48

Browse files
committed
fix: array expressions with attributes after the first item
1 parent 48e0533 commit 25dfe48

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

grammar.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ const primitive_types = numeric_types.concat(['bool', 'str', 'char']);
6464
module.exports = grammar({
6565
name: 'rust',
6666

67-
extras: $ => [/\s/, $.line_comment, $.block_comment],
67+
extras: $ => [
68+
/\s/,
69+
$.line_comment,
70+
$.block_comment,
71+
],
6872

6973
externals: $ => [
7074
$._string_content,
@@ -102,6 +106,7 @@ module.exports = grammar({
102106
[$.parameters, $._pattern],
103107
[$.parameters, $.tuple_struct_pattern],
104108
[$.type_parameters, $.for_lifetimes],
109+
[$.array_expression],
105110
],
106111

107112
word: $ => $.identifier,
@@ -1065,7 +1070,7 @@ module.exports = grammar({
10651070
field('length', $._expression),
10661071
),
10671072
seq(
1068-
sepBy(',', $._expression),
1073+
sepBy(',', seq(repeat($.attribute_item), $._expression)),
10691074
optional(','),
10701075
),
10711076
),

test/corpus/expressions.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ Array expressions
358358
[1, 2, 3];
359359
["a", "b", "c"];
360360
[0; 128];
361+
[
362+
#[cfg(foo)]
363+
"foo",
364+
#[cfg(bar)]
365+
"bar",
366+
];
361367

362368
--------------------------------------------------------------------------------
363369

@@ -377,7 +383,19 @@ Array expressions
377383
(expression_statement
378384
(array_expression
379385
(integer_literal)
380-
length: (integer_literal))))
386+
length: (integer_literal)))
387+
(expression_statement
388+
(array_expression
389+
(attribute_item
390+
(attribute
391+
(identifier)
392+
arguments: (token_tree (identifier))))
393+
(string_literal)
394+
(attribute_item
395+
(attribute
396+
(identifier)
397+
arguments: (token_tree (identifier))))
398+
(string_literal))))
381399

382400
================================================================================
383401
Tuple expressions

0 commit comments

Comments
 (0)