Skip to content

Commit 3eac8fd

Browse files
authored
Merge pull request #509 from fortran-lang/gnikit/issue278
Removes need for matching begin-end scope names
2 parents 322be8f + d9ee62d commit 3eac8fd

File tree

4 files changed

+581
-6
lines changed

4 files changed

+581
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3535

3636
### Changed
3737

38+
- Changed need for matching begin-end scope names, in the following constructs:
39+
Functions, Modules, Programs, Module Procedures, Subroutines, Submodules.
40+
For a more detailed explanation as to why see the issue
41+
([#278](https://github.com/fortran-lang/vscode-fortran-support/issues/278))
3842
- Rewrote README to include links to fortran-lang and other projects
3943
([#485](https://github.com/fortran-lang/vscode-fortran-support/issues/485))
4044
([#501](https://github.com/fortran-lang/vscode-fortran-support/issues/501))

syntaxes/fortran_free-form.tmLanguage.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,7 +4060,7 @@
40604060
"name": "entity.name.function.fortran"
40614061
}
40624062
},
4063-
"end": "(?ix)\\s*\\b(?:(end\\s*function)(?:\\s+(\\1))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
4063+
"end": "(?ix)\\s*\\b(?:(end\\s*function)(?:\\s+([a-z_]\\w*))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
40644064
"endCaptures": {
40654065
"1": {
40664066
"name": "keyword.other.endfunction.fortran"
@@ -4148,7 +4148,7 @@
41484148
"name": "entity.name.class.module.fortran"
41494149
}
41504150
},
4151-
"end": "(?ix)\\b(?:(end\\s*module)(?:\\s+(\\1))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
4151+
"end": "(?ix)\\b(?:(end\\s*module)(?:\\s+([a-z_]\\w*))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
41524152
"endCaptures": {
41534153
"1": {
41544154
"name": "keyword.other.endmodule.fortran"
@@ -4218,7 +4218,7 @@
42184218
"name": "entity.name.program.fortran"
42194219
}
42204220
},
4221-
"end": "(?ix)\\b(?:(end\\s*program)(?:\\s+(\\1))?|(end))\\b\\s*([^;!\\n]+)?(?=[;!\\n])",
4221+
"end": "(?ix)\\b(?:(end\\s*program)(?:\\s+([a-z_]\\w*))?|(end))\\b\\s*([^;!\\n]+)?(?=[;!\\n])",
42224222
"endCaptures": {
42234223
"1": {
42244224
"name": "keyword.control.endprogram.fortran"
@@ -4289,7 +4289,7 @@
42894289
"name": "entity.name.function.procedure.fortran"
42904290
}
42914291
},
4292-
"end": "(?ix)\\s*\\b(?:(end\\s*procedure)(?:\\s+(\\1))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
4292+
"end": "(?ix)\\s*\\b(?:(end\\s*procedure)(?:\\s+([a-z_]\\w*))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
42934293
"endCaptures": {
42944294
"1": {
42954295
"name": "keyword.other.endprocedure.fortran"
@@ -4395,7 +4395,7 @@
43954395
"name": "entity.name.function.subroutine.fortran"
43964396
}
43974397
},
4398-
"end": "(?ix)\\b(?:(end\\s*subroutine)(?:\\s+(\\1))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
4398+
"end": "(?ix)\\b(?:(end\\s*subroutine)(?:\\s+([a-z_]\\w*))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
43994399
"endCaptures": {
44004400
"1": {
44014401
"name": "keyword.other.endsubroutine.fortran"
@@ -4493,7 +4493,7 @@
44934493
"name": "entity.name.module.submodule.fortran"
44944494
}
44954495
},
4496-
"end": "(?ix)\\s*\\b(?:(end\\s*submodule)(?:\\s+(\\1))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
4496+
"end": "(?ix)\\s*\\b(?:(end\\s*submodule)(?:\\s+([a-z_]\\w*))?|(end))\\b \\s*([^;!\\n]+)?(?=[;!\\n])",
44974497
"endCaptures": {
44984498
"1": {
44994499
"name": "keyword.other.endsubmodule.fortran"

test/resources/pp_in_func.f90

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
! Out of order nested function/subroutine definitions such as in the case
2+
! of preprocessing directives, where the inner scope is not the scope that closes
3+
! first, yield invalid.error syntax highlighting because we attempt to match
4+
! the name from the begin REGEX to the end REGEX match i.e. \\1
5+
! This can be circumvented by matching a word character instead [a-z_]\\w*
6+
! Obviously this is not going to highlight when the wrong name is used to
7+
! close a scope, but the linter should solve that
8+
9+
!
10+
subroutine blasmul_mm()
11+
interface
12+
#ifdef DOUBLEP
13+
SUBROUTINE DGEMM ( )
14+
#else
15+
SUBROUTINE SGEMM ( )
16+
#endif
17+
18+
#ifdef DOUBLEP
19+
END SUBROUTINE DGEMM
20+
#else
21+
END SUBROUTINE SGEMM
22+
#endif
23+
end interface
24+
25+
end subroutine blasmul_mm
26+
27+
! This would work with the previous definition of the end REGEX because the scopes
28+
! close in the order that they open
29+
subroutine blasmul_mm()
30+
interface
31+
#ifdef DOUBLEP
32+
SUBROUTINE DGEMM ( )
33+
#else
34+
SUBROUTINE SGEMM ( )
35+
#endif
36+
37+
#ifndef DOUBLEP
38+
END SUBROUTINE SGEMM
39+
#else
40+
END SUBROUTINE DGEMM
41+
#endif
42+
end interface
43+
44+
end subroutine blasmul_mm
45+
46+
REAL FUNCTION blasmul_mm() RESULT(VAL)
47+
interface
48+
#ifdef DOUBLEP
49+
FUNCTION DGEMM ( )
50+
#else
51+
FUNCTION SGEMM ( )
52+
#endif
53+
54+
#ifdef DOUBLEP
55+
END FUNCTION DGEMM
56+
#else
57+
END FUNCTION SGEMM
58+
#endif
59+
end interface
60+
61+
END FUNCTION blasmul_mm
62+
63+
MODULE blasmul_mm
64+
#ifdef DOUBLEP
65+
MODULE DGEMM
66+
#else
67+
MODULE SGEMM
68+
#endif
69+
70+
#ifdef DOUBLEP
71+
END MODULE DGEMM
72+
#else
73+
END MODULE SGEMM
74+
#endif
75+
76+
end MODULE blasmul_mm
77+
78+
SUBMODULE (name) blasmul_mm
79+
#ifdef DOUBLEP
80+
SUBMODULE (name) DGEMM
81+
#else
82+
SUBMODULE (name) SGEMM
83+
#endif
84+
85+
#ifdef DOUBLEP
86+
END SUBMODULE DGEMM
87+
#else
88+
END SUBMODULE SGEMM
89+
#endif
90+
91+
end SUBMODULE blasmul_mm
92+
93+
PROGRAM blasmul_mm
94+
#ifdef DOUBLEP
95+
PROGRAM DGEMM
96+
#else
97+
PROGRAM SGEMM
98+
#endif
99+
100+
#ifdef DOUBLEP
101+
END PROGRAM DGEMM
102+
#else
103+
END PROGRAM SGEMM
104+
#endif
105+
106+
end PROGRAM blasmul_mm
107+
108+
MODULE PROCEDURE blasmul_mm
109+
#ifdef DOUBLEP
110+
MODULE PROCEDURE DGEMM
111+
#else
112+
MODULE PROCEDURE SGEMM
113+
#endif
114+
115+
#ifdef DOUBLEP
116+
END PROCEDURE DGEMM
117+
#else
118+
END PROCEDURE SGEMM
119+
#endif
120+
121+
end PROCEDURE blasmul_mm

0 commit comments

Comments
 (0)