Fortran: allow keywords as names
Allow keywords for names of modules, programs, types, interfaces, structures and enums. Test case contributed by Adam Hirst, thanks.
This commit is contained in:
parent
e47d45eb28
commit
ed1dc50062
@ -1610,8 +1610,11 @@ static void parseStructureStmt (tokenInfo *const token)
|
|||||||
strcmp (vStringValue (token->string), "/") == 0)
|
strcmp (vStringValue (token->string), "/") == 0)
|
||||||
{ /* read structure name */
|
{ /* read structure name */
|
||||||
readToken (token);
|
readToken (token);
|
||||||
if (isType (token, TOKEN_IDENTIFIER))
|
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
|
||||||
|
{
|
||||||
name = newTokenFrom (token);
|
name = newTokenFrom (token);
|
||||||
|
name->type = TOKEN_IDENTIFIER;
|
||||||
|
}
|
||||||
skipPast (token, TOKEN_OPERATOR);
|
skipPast (token, TOKEN_OPERATOR);
|
||||||
}
|
}
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
@ -1728,8 +1731,11 @@ static void parseDerivedTypeDef (tokenInfo *const token)
|
|||||||
parseQualifierSpecList (token);
|
parseQualifierSpecList (token);
|
||||||
if (isType (token, TOKEN_DOUBLE_COLON))
|
if (isType (token, TOKEN_DOUBLE_COLON))
|
||||||
readToken (token);
|
readToken (token);
|
||||||
if (isType (token, TOKEN_IDENTIFIER))
|
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
|
||||||
|
{
|
||||||
|
token->type = TOKEN_IDENTIFIER;
|
||||||
makeFortranTag (token, TAG_DERIVED_TYPE);
|
makeFortranTag (token, TAG_DERIVED_TYPE);
|
||||||
|
}
|
||||||
ancestorPush (token);
|
ancestorPush (token);
|
||||||
skipToNextStatement (token);
|
skipToNextStatement (token);
|
||||||
if (isKeyword (token, KEYWORD_private) ||
|
if (isKeyword (token, KEYWORD_private) ||
|
||||||
@ -1777,11 +1783,7 @@ static void parseInterfaceBlock (tokenInfo *const token)
|
|||||||
tokenInfo *name = NULL;
|
tokenInfo *name = NULL;
|
||||||
Assert (isKeyword (token, KEYWORD_interface));
|
Assert (isKeyword (token, KEYWORD_interface));
|
||||||
readToken (token);
|
readToken (token);
|
||||||
if (isType (token, TOKEN_IDENTIFIER))
|
if (isKeyword (token, KEYWORD_assignment) ||
|
||||||
{
|
|
||||||
name = newTokenFrom (token);
|
|
||||||
}
|
|
||||||
else if (isKeyword (token, KEYWORD_assignment) ||
|
|
||||||
isKeyword (token, KEYWORD_operator))
|
isKeyword (token, KEYWORD_operator))
|
||||||
{
|
{
|
||||||
readToken (token);
|
readToken (token);
|
||||||
@ -1790,6 +1792,11 @@ static void parseInterfaceBlock (tokenInfo *const token)
|
|||||||
if (isType (token, TOKEN_OPERATOR))
|
if (isType (token, TOKEN_OPERATOR))
|
||||||
name = newTokenFrom (token);
|
name = newTokenFrom (token);
|
||||||
}
|
}
|
||||||
|
else if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
|
||||||
|
{
|
||||||
|
name = newTokenFrom (token);
|
||||||
|
name->type = TOKEN_IDENTIFIER;
|
||||||
|
}
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
{
|
{
|
||||||
name = newAnonTokenFrom (token, "Interface");
|
name = newAnonTokenFrom (token, "Interface");
|
||||||
@ -1844,8 +1851,11 @@ static void parseEnumBlock (tokenInfo *const token)
|
|||||||
parseKindSelector (token);
|
parseKindSelector (token);
|
||||||
if (isType (token, TOKEN_DOUBLE_COLON))
|
if (isType (token, TOKEN_DOUBLE_COLON))
|
||||||
readToken (token);
|
readToken (token);
|
||||||
if (isType (token, TOKEN_IDENTIFIER))
|
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
|
||||||
|
{
|
||||||
name = newTokenFrom (token);
|
name = newTokenFrom (token);
|
||||||
|
name->type = TOKEN_IDENTIFIER;
|
||||||
|
}
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
{
|
{
|
||||||
name = newAnonTokenFrom (token, "Enum");
|
name = newAnonTokenFrom (token, "Enum");
|
||||||
@ -2101,8 +2111,11 @@ static void parseModule (tokenInfo *const token)
|
|||||||
{
|
{
|
||||||
Assert (isKeyword (token, KEYWORD_module));
|
Assert (isKeyword (token, KEYWORD_module));
|
||||||
readToken (token);
|
readToken (token);
|
||||||
if (isType (token, TOKEN_IDENTIFIER))
|
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
|
||||||
|
{
|
||||||
|
token->type = TOKEN_IDENTIFIER;
|
||||||
makeFortranTag (token, TAG_MODULE);
|
makeFortranTag (token, TAG_MODULE);
|
||||||
|
}
|
||||||
ancestorPush (token);
|
ancestorPush (token);
|
||||||
skipToNextStatement (token);
|
skipToNextStatement (token);
|
||||||
parseSpecificationPart (token);
|
parseSpecificationPart (token);
|
||||||
@ -2182,8 +2195,11 @@ static void parseSubprogram (tokenInfo *const token, const tagType tag)
|
|||||||
isKeyword (token, KEYWORD_function) ||
|
isKeyword (token, KEYWORD_function) ||
|
||||||
isKeyword (token, KEYWORD_subroutine));
|
isKeyword (token, KEYWORD_subroutine));
|
||||||
readToken (token);
|
readToken (token);
|
||||||
if (isType (token, TOKEN_IDENTIFIER))
|
if (isType (token, TOKEN_IDENTIFIER) || isType (token, TOKEN_KEYWORD))
|
||||||
|
{
|
||||||
|
token->type = TOKEN_IDENTIFIER;
|
||||||
makeFortranTag (token, tag);
|
makeFortranTag (token, tag);
|
||||||
|
}
|
||||||
ancestorPush (token);
|
ancestorPush (token);
|
||||||
skipToNextStatement (token);
|
skipToNextStatement (token);
|
||||||
parseSpecificationPart (token);
|
parseSpecificationPart (token);
|
||||||
|
@ -158,6 +158,7 @@ test_sources = \
|
|||||||
keyword_implicit.cs \
|
keyword_implicit.cs \
|
||||||
keyword_interface.cs \
|
keyword_interface.cs \
|
||||||
keyword_namespace.cs \
|
keyword_namespace.cs \
|
||||||
|
keyword_names.f90 \
|
||||||
keyword_out.cs \
|
keyword_out.cs \
|
||||||
keyword_override.cs \
|
keyword_override.cs \
|
||||||
keyword_params.cs \
|
keyword_params.cs \
|
||||||
|
28
tests/ctags/keyword_names.f90
Normal file
28
tests/ctags/keyword_names.f90
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
! For some reason, the Fortran standard does not prohibit this...
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
program Interface
|
||||||
|
use Program
|
||||||
|
! ...
|
||||||
|
end program Interface
|
8
tests/ctags/keyword_names.f90.tags
Normal file
8
tests/ctags/keyword_names.f90.tags
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# format=tagmanager
|
||||||
|
DataÌ1ÎProgramÖ0
|
||||||
|
InterfaceÌ2048Ö0
|
||||||
|
MyFuncÌ16ÎProgramÖ0
|
||||||
|
ProgramÌ256Ö0
|
||||||
|
ProgramÌ32ÎProgramÖ0
|
||||||
|
contentsÌ64ÎDataÖ0
|
||||||
|
iÌ16384ÎProgramÖ0
|
Loading…
x
Reference in New Issue
Block a user