Skip to content

Commit e923872

Browse files
authored
[D] Fix auto attribute in if and while conditions (#4568)
* [D] Fix auto keyword in if() and while() conditions This commit adds `auto` keyword to `first-value`. * [D] Remove auto from basic-type This commit removes redundant pattern as `auto` is part of `attributes` variable and therefore already included via `attribute_lookahead` context.
1 parent da5a420 commit e923872

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

D/D.sublime-syntax

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,6 @@ contexts:
888888
- match: '\('
889889
scope: punctuation.section.parens.begin.d
890890
set: [basic-type2, basic-type2-after-parens, typeof-value]
891-
- match: '\bauto\b'
892-
scope: keyword.other.d
893-
pop: true
894891
- match: '\bmixin\b'
895892
scope: keyword.control.d
896893
set:
@@ -2347,14 +2344,20 @@ contexts:
23472344
condition:
23482345
- match: '\('
23492346
scope: punctuation.section.parens.begin.d
2350-
set: [condition-after, first-value]
2347+
set: [condition-after, first-value, condition-attribute]
23512348
- include: not-whitespace-illegal-pop
23522349
condition-after:
23532350
- meta_scope: meta.parens.d
23542351
- match: '\)'
23552352
scope: punctuation.section.parens.end.d
23562353
pop: true
23572354
- include: not-whitespace-illegal-pop
2355+
condition-attribute:
2356+
- match: '\bauto\b'
2357+
scope: storage.modifier.d
2358+
pop: true
2359+
- match: '(?=\S)'
2360+
pop: true
23582361

23592362
identifier:
23602363
- match: '\b{{name}}\b'

D/tests/syntax_test_d.d

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,7 @@ extern(1)
22512251
// ^ meta.number.integer.decimal.d
22522252
if (int a = 2) {}
22532253
//^^ keyword.control.conditional.d
2254+
// ^^^^^^^^^^^ meta.parens.d
22542255
// ^ punctuation.section.parens.begin.d
22552256
// ^^^ storage.type.d
22562257
// ^ variable.other.d
@@ -2260,7 +2261,18 @@ extern(1)
22602261
// ^^ meta.block.d
22612262
// ^ punctuation.section.block.begin.d
22622263
// ^ punctuation.section.block.end.d
2263-
2264+
if (auto a = 2) {}
2265+
//^^ keyword.control.conditional.d
2266+
// ^^^^^^^^^^^^ meta.parens.d
2267+
// ^ punctuation.section.parens.begin.d
2268+
// ^^^^ storage.modifier.d
2269+
// ^ variable.other.d
2270+
// ^ keyword.operator.assignment.d
2271+
// ^ meta.number.integer.decimal.d constant.numeric.value.d
2272+
// ^ punctuation.section.parens.end.d
2273+
// ^^ meta.block.d
2274+
// ^ punctuation.section.block.begin.d
2275+
// ^ punctuation.section.block.end.d
22642276
if (a in b) {}
22652277
//^^ keyword.control.conditional.d
22662278
// ^ punctuation.section.parens.begin.d
@@ -2330,6 +2342,17 @@ extern(1)
23302342
// ^ punctuation.section.parens.end.d
23312343
// ^ meta.path.d variable.other.d
23322344
// ^ punctuation.terminator.d
2345+
while (auto a = 2) a;
2346+
//^^^^^ keyword.control.loop.d
2347+
// ^^^^^^^^^^^^ meta.parens.d
2348+
// ^ punctuation.section.parens.begin.d
2349+
// ^^^^ storage.modifier.d
2350+
// ^ variable.other.d
2351+
// ^ keyword.operator.assignment.d
2352+
// ^ meta.number.integer.decimal.d constant.numeric.value.d
2353+
// ^ punctuation.section.parens.end.d
2354+
// ^ meta.path.d variable.other.d
2355+
// ^ punctuation.terminator.d
23332356
for (1; 2; 3) {
23342357
//^^^ keyword.control.loop.d
23352358
// ^ punctuation.section.parens.begin.d

0 commit comments

Comments
 (0)