Skip to content

Commit a8f33f9

Browse files
committed
Fixes Erroneous syntax highlighting of if construct with tags #204
Labels were only captured at the start and end of a statement. Now we are also capturing them in between for if conditionals. The edits in the end in "named-control-constructs" are meant to correctly handle whitespaces which before they were placed as part of the group returned to the invalid.error.xxx A unittest has been added testing the conditionals with/out labels.
1 parent 5bfbbe6 commit a8f33f9

File tree

4 files changed

+280
-3
lines changed

4 files changed

+280
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2525
- Fixes the general preprocessor syntax highlighting and adds testing
2626
- Fixes using function/subroutine as parameter in functions/subroutines
2727
([#207](https://github.com/krvajal/vscode-fortran-support/issues/207))
28+
- Fixes labelled conditionals erroneous highlighting
29+
([#204](https://github.com/krvajal/vscode-fortran-support/issues/204))
2830

2931
### Added
3032

syntaxes/fortran_free-form.tmLanguage.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"FPP",
1818
".pf",
1919
".PF"
20-
2120
],
2221
"firstLineMatch": "(?i)-[*]- mode: fortran free -[*]-",
2322
"injections": {
@@ -1353,7 +1352,7 @@
13531352
"comment": "Introduced in the Fortran 1990 standard.",
13541353
"contentName": "meta.named-construct.fortran.modern",
13551354
"begin": "(?ix)([a-z]\\w*)\\s*(:)(?=\\s*(?:associate|block(?!\\s*data)|critical|do|forall|if|select\\s*case|select\\s*type|select\\s*rank|where)\\b)",
1356-
"end": "(?i)\\s*(?!\\b(?:associate|block(?!\\s*data)|critical|do|forall|if|select\\s*case|select\\s*type|select\\s*rank|where)\\b)\\b(?:\\b(\\1)\\b)?(?:\\s*([^\\s;!][^;!\\n]*?))?(?=\\s*[;!\\n])",
1355+
"end": "(?i)(?!\\s*\\b(?:associate|block(?!\\s*data)|critical|do|forall|if|select\\s*case|select\\s*type|select\\s*rank|where)\\b)(?:\\b(\\1)\\b)?(?:\\s*([^\\s;!][^;!\\n]*?))?(?=\\s*[;!\\n])",
13571356
"endCaptures": {
13581357
"2": {
13591358
"name": "invalid.error.named-control-constructs.fortran.modern"
@@ -1611,10 +1610,14 @@
16111610
"include": "#parentheses"
16121611
},
16131612
{
1614-
"match": "(?i)\\b(then)\\b",
1613+
"comment": "capture the label if present",
1614+
"match": "(?i)\\b(then)\\b(\\s*[a-z]\\w*)?",
16151615
"captures": {
16161616
"1": {
16171617
"name": "keyword.control.then.fortran"
1618+
},
1619+
"2": {
1620+
"name": "meta.label.elseif"
16181621
}
16191622
}
16201623
},
@@ -1638,6 +1641,15 @@
16381641
"begin": "(?!(\\s*(;|!|\\n)))",
16391642
"end": "(?=[;!\\n])",
16401643
"patterns": [
1644+
{
1645+
"comment": "capture the label if present",
1646+
"match": "\\s*([a-z]\\w*)?\\s*",
1647+
"captures": {
1648+
"1": {
1649+
"name": "meta.label.else"
1650+
}
1651+
}
1652+
},
16411653
{
16421654
"include": "#invalid-word"
16431655
}

test/resources/conditionals.f90

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
! if
2+
if (1 > 2) then
3+
end if
4+
5+
! if-else
6+
if (1 > 2) then
7+
else
8+
end if
9+
10+
! if-else-if-else
11+
if (1 > 2) then
12+
else if (2 < 1) then
13+
else
14+
end if
15+
16+
! labelled if
17+
label1: if (1 > 2) then
18+
end if label1
19+
20+
! labelled if-else
21+
label2: if (1 > 2) then
22+
else label2
23+
end if label2
24+
25+
! labelled if-else-if-else
26+
label3: if (1 > 2) then
27+
else if (2 < 1) then label3
28+
else label3
29+
end if label3
30+
31+
! labelled if with whitespace after end label
32+
label4: if (1 > 2) then
33+
end if label4 ! bug continuous to new line
34+
35+
! nested labels with whitespaces
36+
if (1 > 2) then
37+
label5: if (1) then
38+
end if label5 !
39+
else
40+
! whitespace in the "end if label5 " causes else to be incorrect
41+
end if

0 commit comments

Comments
 (0)