Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
navinp0304 opened this issue Jul 27, 2024 · 7 comments
Open

Comments

@navinp0304
Copy link

navinp0304 commented Jul 27, 2024

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 $
universal-ctags/ctags#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
Copy link
Member

vladak commented Aug 1, 2024

Care to submit a PR ?

@navinp0304
Copy link
Author

navinp0304 commented Aug 1, 2024

@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
Copy link
Author

navinp0304 commented Aug 10, 2024

@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
Copy link
Member

vladak commented Aug 14, 2024

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

"#" {WhspChar}* "include" {WhspChar}* ("<"[^>\n\r]+">" | \"[^\"\n\r]+\") {}
, 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
Copy link
Member

vladak commented Aug 14, 2024

The Fortran lexing rules already contain file/path matching:

<SCOMMENT, STRING, QSTRING> {
{FPath} {
chkLOC();
onPathlikeMatched(yytext(), '/', false, yychar);
}
{File}
{
chkLOC();
String path = yytext();
onFilelikeMatched(path, yychar);
}
{FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
{
chkLOC();
onEmailAddressMatched(yytext(), yychar);
}
}
and there is also
"<" ({File}|{FPath}) ">" {
chkLOC();
onNonSymbolMatched("<", yychar);
String file = yytext();
file = file.substring(1, file.length() - 1);
onFilelikeMatched(file, yychar + 1);
onNonSymbolMatched(">", yychar + 1 + file.length());
}
so perhaps these need to be augmented and/or receive rule similar to the one used for C:
"#" {WhspChar}* "include" {WhspChar}* ("<"[^>\n\r]+">" | \"[^\"\n\r]+\") {
chkLOC();
String capture = yytext();
Matcher match = MATCH_INCLUDE.matcher(capture);
if (match.matches()) {
onNonSymbolMatched(match.group(INCL_HASH_G), yychar);
onFilteredSymbolMatched(match.group(INCLUDE_G), yychar, Consts.kwd);
onNonSymbolMatched(match.group(INCL_POST_G), yychar);
onNonSymbolMatched(match.group(INCL_PUNC0_G), yychar);
String path = match.group(INCL_PATH_G);
onPathlikeMatched(path, '/', false, yychar);
onNonSymbolMatched(match.group(INCL_PUNCZ_G), yychar);
} else {
onNonSymbolMatched(capture, yychar);
}
}
(which should match the rule added to FortranSymbolTokenizer.lex)

Further, there is also

which probably needs to be reconciled with the new state of include files in Fortran.

@navinp0304
Copy link
Author

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

"#" {WhspChar}* "include" {WhspChar}* ("<"[^>\n\r]+">" | \"[^\"\n\r]+\") {}

, 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 added a commit to navinp0304/opengrok that referenced this issue Aug 17, 2024
Implementation according to discussion based on vladak
oracle#4610

Signed-off-by: Navin P <navinp0304@gmail.com>
navinp0304 added a commit to navinp0304/opengrok that referenced this issue Aug 17, 2024
Implementation according to discussion based on vladak
oracle#4610

Signed-off-by: Navin P S <navinp0304@gmail.com>
@navinp0304
Copy link
Author

Care to submit a PR ?

Submitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants