Skip to content

Commit

Permalink
Add support for $ in fortran identifiers and clickable .i include fil…
Browse files Browse the repository at this point in the history
…es. (#4642)

fixes #4610

Signed-off-by: Navin P S <[email protected]>
Co-authored-by: Vladimir Kotal <[email protected]>
  • Loading branch information
navinp0304 and vladak authored Oct 4, 2024
1 parent 56251fa commit 2c08f40
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public class FortranAnalyzerFactory extends FileAnalyzerFactory {
"F95",
"F03",
"F08",
"F15"};
"F15",
"F77"};

public FortranAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
*/

Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
Identifier = [a-zA-Z_] [a-zA-Z0-9_$]*
Label = [0-9]+

Number = ([0-9]+\.[0-9]+|[0-9][0-9]* | [0][xX] [0-9a-fA-F]+ )([uUdDlL]+)?
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
return yystate(); }
}

{WhspChar}* "include" {WhspChar}* (\'[^\'\n\r]+\'| \"[^\"\n\r]+\") {}
{Number} {}

\" { yybegin(STRING); }
\' { yybegin(QSTRING); }
\! { yybegin(SCOMMENT); }
"C" { yybegin(SCOMMENT); }
}

<STRING> {
Expand Down
11 changes: 6 additions & 5 deletions opengrok-indexer/src/main/jflex/analysis/fortran/FortranXref.lex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import org.opengrok.indexer.web.HtmlConsts;
}
%}

File = [a-zA-Z]{FNameChar}* ".inc"
File = [a-zA-Z]{FNameChar}* "." ("i"|"inc")

%state STRING SCOMMENT QSTRING LCOMMENT

Expand All @@ -86,13 +86,14 @@ File = [a-zA-Z]{FNameChar}* ".inc"
onFilteredSymbolMatched(yytext(), yychar, Consts.kwd, false);
}

"'" ({File}|{FPath}) "'" |
"<" ({File}|{FPath}) ">" {
chkLOC();
onNonSymbolMatched("<", yychar);
String file = yytext();
file = file.substring(1, file.length() - 1);
String cmatch = yytext();
onNonSymbolMatched(cmatch.substring(0, 1), yychar);
String file = cmatch.substring(1, cmatch.length() - 1);
onFilelikeMatched(file, yychar + 1);
onNonSymbolMatched(">", yychar + 1 + file.length());
onNonSymbolMatched(cmatch.substring(cmatch.length() - 1, 1), yychar + 1 + file.length());
}

/*{Hier}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void sampleTest() throws IOException {
writeAndCompare(new FortranAnalyzerFactory(),
"analysis/fortran/sample.f",
"analysis/fortran/sample_xref.html",
readTagsFromResource("analysis/fortran/sampletags"), 28);
readTagsFromResource("analysis/fortran/sampletags"), 32);
}

@Test
Expand Down
12 changes: 12 additions & 0 deletions opengrok-indexer/src/test/resources/analysis/fortran/sample.f
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,16 @@ SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )
* End of DGESV
*
END

* A Fortran 77 subroutine that ends in $
* =====================================================================
SUBROUTINE SUBF77$()
*
INTEGER VARF77$
VARF77$ = 0
*
* =====================================================================
*
CALL SUBF77$

CALL 'http://example.com'

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ IPIV
B
LDB
INFO
SUBF77$
VARF77$
VARF77$
SUBF77$
60 changes: 48 additions & 12 deletions opengrok-indexer/src/test/resources/analysis/fortran/sampletags
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/
!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/
!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/
!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/
!_TAG_FIELD_DESCRIPTION epoch /the last modified time of the input file (only for F\/file kind tag)/
!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/
!_TAG_FIELD_DESCRIPTION input /input file/
!_TAG_FIELD_DESCRIPTION name /tag name/
!_TAG_FIELD_DESCRIPTION pattern /pattern/
!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_KIND_DESCRIPTION!Fortran E,enum /enumerations/
!_TAG_KIND_DESCRIPTION!Fortran L,local /local, common block, and namelist variables/
!_TAG_KIND_DESCRIPTION!Fortran M,method /type bound procedures/
!_TAG_KIND_DESCRIPTION!Fortran N,enumerator /enumeration values/
!_TAG_KIND_DESCRIPTION!Fortran S,submodule /submodules/
!_TAG_KIND_DESCRIPTION!Fortran b,blockData /block data/
!_TAG_KIND_DESCRIPTION!Fortran c,common /common blocks/
!_TAG_KIND_DESCRIPTION!Fortran e,entry /entry points/
!_TAG_KIND_DESCRIPTION!Fortran f,function /functions/
!_TAG_KIND_DESCRIPTION!Fortran i,interface /interface contents, generic names, and operators/
!_TAG_KIND_DESCRIPTION!Fortran k,component /type and structure components/
!_TAG_KIND_DESCRIPTION!Fortran l,label /labels/
!_TAG_KIND_DESCRIPTION!Fortran m,module /modules/
!_TAG_KIND_DESCRIPTION!Fortran n,namelist /namelists/
!_TAG_KIND_DESCRIPTION!Fortran p,program /programs/
!_TAG_KIND_DESCRIPTION!Fortran s,subroutine /subroutines/
!_TAG_KIND_DESCRIPTION!Fortran t,type /derived types and structures/
!_TAG_KIND_DESCRIPTION!Fortran v,variable /program (global) and module variables/
!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_OUTPUT_VERSION 0.0 /current.age/
!_TAG_PARSER_VERSION!Fortran 1.1 /current.age/
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
!_TAG_PROC_CWD /home/navin.parakkal/OpenGrok/opengrok-indexer/src/test/resources/analysis/fortran/ //
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
!_TAG_PROGRAM_VERSION 0.0.0 /b13cb551/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
DGESV grok.f /^ SUBROUTINE DGESV(/;" subroutine line:173 signature:(N, NRHS, A, LDA, IPIV, B, LDB, INFO)
INFO grok.f /^ INTEGER INFO,/;" local line:181 subroutine:DGESV
LDA grok.f /^ INTEGER INFO, LDA,/;" local line:181 subroutine:DGESV
LDB grok.f /^ INTEGER INFO, LDA, LDB,/;" local line:181 subroutine:DGESV
N grok.f /^ INT/;" local line:181 subroutine:DGESV
NRHS grok.f /^ INTEGER INFO, LDA, LDB, N, NRHS$/;" local line:181 subroutine:DGESV
IPIV grok.f /^ INTEGER IPIV(/;" local line:184 subroutine:DGESV
A grok.f /^ DOUBLE PRECISION A(/;" local line:185 subroutine:DGESV
B grok.f /^ DOUBL/;" local line:185 subroutine:DGESV
!_TAG_PROGRAM_VERSION 6.1.0 /p6.1.20240714.0/
A sample.f /^ DOUBLE PRECISION A( LDA,/;" L subroutine:DGESV file:
B sample.f /^ DOUBLE PRECISION A( LDA, * ), B( LDB,/;" L subroutine:DGESV file:
DGESV sample.f /^ SUBROUTINE DGESV(/;" s
INFO sample.f /^ INTEGER INFO,/;" L subroutine:DGESV file:
IPIV sample.f /^ INTEGER IPIV(/;" L subroutine:DGESV file:
LDA sample.f /^ INTEGER INFO, LDA,/;" L subroutine:DGESV file:
LDB sample.f /^ INTEGER INFO, LDA, LDB,/;" L subroutine:DGESV file:
N sample.f /^ INTEGER INFO, LDA, LDB, N, NR/;" L subroutine:DGESV file:
NRHS sample.f /^ INTEGER INFO, LDA, LDB, N, NRHS$/;" L subroutine:DGESV file:
SUBF77$ sample.f /^ SUBROUTINE SUBF77$(/;" s
VARF77$ sample.f /^ INTEGER VARF77\$$/;" L subroutine:SUBF77$ file:

0 comments on commit 2c08f40

Please sign in to comment.