Skip to content

Commit 993905f

Browse files
techeemasatake
authored andcommitted
Fortran: allow keyword names to be used for various kinds
Fortran allows keyword names to be used as identifiers of module, type, interface and other kinds. For instance, in the code below 'Program' is a keyword but can be used as a name of module, the same for 'Data' and also interface named 'Program': module Program type Data integer :: contents end type Data integer :: i interface Program function myFunc(arg) !... end function myFunc end interface Program contains function MyFunc(arg) ! ... end function MyFunc end module Program
1 parent 34c9f30 commit 993905f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Units/parser-fortran.r/fortran-submodule.d/expected.tags

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ example_smod input.f90 /^submodule (example_mod) example_smod$/;" submodule inhe
22
g input.f90 /^ module function g(/;" function submodule:example_smod
33
example_ssmod input.f90 /^submodule (example_mod:example_smod) example_ssmod$/;" submodule inherits:example_mod:example_smod
44
g2 input.f90 /^ module function g2(/;" function submodule:example_ssmod
5-
x input.f90 /^ integer :: x,/;" variable
6-
y input.f90 /^ integer :: x,y$/;" variable
5+
function input.f90 /^ module function /;" module
6+
x input.f90 /^ integer :: x,/;" variable module:function
7+
y input.f90 /^ integer :: x,y$/;" variable module:function

parsers/fortran.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ static void parseStructureStmt (tokenInfo *const token)
17681768
strcmp (vStringValue (token->string), "/") == 0)
17691769
{ /* read structure name */
17701770
readToken (token);
1771-
if (isType (token, TOKEN_IDENTIFIER))
1771+
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
17721772
{
17731773
name = newTokenFrom (token);
17741774
name->type = TOKEN_IDENTIFIER;
@@ -1937,8 +1937,9 @@ static void parseDerivedTypeDef (tokenInfo *const token)
19371937
qualifierToken = parseQualifierSpecList (token);
19381938
if (isType (token, TOKEN_DOUBLE_COLON))
19391939
readToken (token);
1940-
if (isType (token, TOKEN_IDENTIFIER))
1940+
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
19411941
{
1942+
token->type = TOKEN_IDENTIFIER;
19421943
if (qualifierToken)
19431944
{
19441945
if (qualifierToken->parentType)
@@ -2006,7 +2007,7 @@ static void parseInterfaceBlock (tokenInfo *const token)
20062007
if (isType (token, TOKEN_OPERATOR))
20072008
name = newTokenFrom (token);
20082009
}
2009-
else if (isType (token, TOKEN_IDENTIFIER))
2010+
else if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
20102011
{
20112012
name = newTokenFrom (token);
20122013
name->type = TOKEN_IDENTIFIER;
@@ -2066,7 +2067,7 @@ static void parseEnumBlock (tokenInfo *const token)
20662067
parseKindSelector (token);
20672068
if (isType (token, TOKEN_DOUBLE_COLON))
20682069
readToken (token);
2069-
if (isType (token, TOKEN_IDENTIFIER))
2070+
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
20702071
{
20712072
name = newTokenFrom (token);
20722073
name->type = TOKEN_IDENTIFIER;
@@ -2406,8 +2407,9 @@ static void parseModule (tokenInfo *const token, bool isSubmodule)
24062407
}
24072408

24082409
readToken (token);
2409-
if (isType (token, TOKEN_IDENTIFIER))
2410+
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
24102411
{
2412+
token->type = TOKEN_IDENTIFIER;
24112413
if (isSubmodule)
24122414
{
24132415
attachParentType (token, parentIdentifier);
@@ -2521,9 +2523,10 @@ static void parseSubprogramFull (tokenInfo *const token, const tagType tag)
25212523
isKeyword (token, KEYWORD_function) ||
25222524
isKeyword (token, KEYWORD_subroutine));
25232525
readToken (token);
2524-
if (isType (token, TOKEN_IDENTIFIER))
2526+
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
25252527
{
25262528
tokenInfo* name = newTokenFrom (token);
2529+
token->type = TOKEN_IDENTIFIER;
25272530
if (tag == TAG_SUBROUTINE ||
25282531
tag == TAG_PROTOTYPE)
25292532
name->signature = parseSignature (token);

0 commit comments

Comments
 (0)