oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.34k stars 745 forks source link

Add support for $ in fortran identifiers and clickable .i include files. #4610

Open navinp0304 opened 1 month ago

navinp0304 commented 1 month ago

How do i make #include 'file.i' as clickable i.e it is showing as text not a link ? For me #include "file.h" works as a clickable link. I tried adding it in suffix but it doesn't work. The format is #include 'file.i' not "file.i".

diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/fortran/FortranAnalyzerFactory.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/fortran/FortranAnalyzerFactory.java
index 3bc256d38d9..14a8fcf3ca1 100644
--- a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/fortran/FortranAnalyzerFactory.java
+++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/fortran/FortranAnalyzerFactory.java
@@ -49,7 +49,9 @@ public class FortranAnalyzerFactory extends FileAnalyzerFactory {
         "F95",
         "F03",
         "F08",
-        "F15"};
+        "F15",
+        "F77",
+        "I"};

Ctags has added support for fortran identifiers with $ https://github.com/universal-ctags/ctags/issues/4033

Please add support for opengrok as well. This works well for me.

diff --git a/opengrok-indexer/src/main/jflex/analysis/fortran/Fortran.lexh b/opengrok-indexer/src/main/jflex/analysis/fortran/Fortran.lexh
index 86994f85da2..7e9577f4588 100644
--- a/opengrok-indexer/src/main/jflex/analysis/fortran/Fortran.lexh
+++ b/opengrok-indexer/src/main/jflex/analysis/fortran/Fortran.lexh
@@ -22,7 +22,7 @@
  * Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
  */

-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]+)?
vladak commented 1 month ago

Care to submit a PR ?

navinp0304 commented 1 month ago

@vladak Yes but why aren't the include files clickable (without href) even after adding suffixes. I'll have that and then submit PR.

navinp0304 commented 1 month ago

@vladak Yes but why aren't the include files clickable (without href) even after adding suffixes. I'll have that and then submit PR.

Hi @vladak , can you please help with this ?

vladak commented 4 weeks ago

For the include directive I think this needs to be processed by the Fortran analyzer. I believe https://github.com/oracle/opengrok/blob/master/opengrok-indexer/src/main/jflex/analysis/fortran/FortranSymbolTokenizer.lex needs to obtain similar rule as e.g. in https://github.com/oracle/opengrok/blob/0e0e613f0e7824b129796f77d024a0455d659ed9/opengrok-indexer/src/main/jflex/analysis/c/CSymbolTokenizer.lex#L54 , just with the single quotes surrounding the file path element.

Is the file include a feature of (modern) Fortran actually ? Just asking, I have never worked with Fortran before.

vladak commented 4 weeks ago

The Fortran lexing rules already contain file/path matching: https://github.com/oracle/opengrok/blob/0e0e613f0e7824b129796f77d024a0455d659ed9/opengrok-indexer/src/main/jflex/analysis/fortran/FortranXref.lex#L166-L184 and there is also https://github.com/oracle/opengrok/blob/0e0e613f0e7824b129796f77d024a0455d659ed9/opengrok-indexer/src/main/jflex/analysis/fortran/FortranXref.lex#L89-L96 so perhaps these need to be augmented and/or receive rule similar to the one used for C: https://github.com/oracle/opengrok/blob/0e0e613f0e7824b129796f77d024a0455d659ed9/opengrok-indexer/src/main/jflex/analysis/c/CXref.lex#L98-L113 (which should match the rule added to FortranSymbolTokenizer.lex)

Further, there is also https://github.com/oracle/opengrok/blob/0e0e613f0e7824b129796f77d024a0455d659ed9/opengrok-indexer/src/main/jflex/analysis/fortran/FortranXref.lex#L62 which probably needs to be reconciled with the new state of include files in Fortran.

navinp0304 commented 3 weeks ago

For the include directive I think this needs to be processed by the Fortran analyzer. I believe https://github.com/oracle/opengrok/blob/master/opengrok-indexer/src/main/jflex/analysis/fortran/FortranSymbolTokenizer.lex needs to obtain similar rule as e.g. in

https://github.com/oracle/opengrok/blob/0e0e613f0e7824b129796f77d024a0455d659ed9/opengrok-indexer/src/main/jflex/analysis/c/CSymbolTokenizer.lex#L54

, just with the single quotes surrounding the file path element. Is the file include a feature of (modern) Fortran actually ? Just asking, I have never worked with Fortran before.

No it was there since Fortran 77 include 'file' or include "file" . Below is the link https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vna1/index.html

navinp0304 commented 3 weeks ago

Care to submit a PR ?

Submitted