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

Fortran: How to include "$" in variable and function names #4033

Closed
navinp0304 opened this issue Jul 21, 2024 · 6 comments · Fixed by #4034
Closed

Fortran: How to include "$" in variable and function names #4033

navinp0304 opened this issue Jul 21, 2024 · 6 comments · Fixed by #4034

Comments

@navinp0304
Copy link

I want to index some fortran files from old code base .
The syntax is f77. In the old code base the identifiers are having $ for variable names and functions.

  1. How include "$" in the indentifier ?
  2. Is there a way without modifying source code ? What would be the command.
@masatake
Copy link
Member

How include "$" in the identifier ?

With patching this source of ctags:

diff --git a/parsers/fortran.c b/parsers/fortran.c
index 1c1175b3f..0f5b582dc 100644
--- a/parsers/fortran.c
+++ b/parsers/fortran.c
@@ -31,7 +31,7 @@
 /*
 *   MACROS
 */
-#define isident(c)              (isalnum(c) || (c) == '_')
+#define isident(c)              (isalnum(c) || (c) == '_' || (c) == '$')
 #define isBlank(c)              (bool) (c == ' ' || c == '\t')
 #define isType(token,t)         (bool) ((token)->type == (t))
 #define isKeyword(token,k)      (bool) ((token)->keyword == (k))
  1. Is there a way without modifying source code ? What would be the command.

There is no way without modifying the source code.

@masatake
Copy link
Member

If you provide a simple f77 input using $, I can extend ctags to support $ by default. Please let me know if you are interested.

@masatake masatake changed the title How to include "$" in variable and function names for fortran Fortran: How to include "$" in variable and function names Jul 21, 2024
@navinp0304
Copy link
Author

$ cat tmp.f
        function name$()
                integer name$
                name$ = 42
        end function

        function main()
                integer ret$
                ret$=name$()
                print *,ret$
        end function
$ ./a.out 
          42
$ 

Yes that works for me.
How do you list the regex supported by function in fortran or C for ctags? Is it possible to print it and how do i extend it ?

masatake added a commit to masatake/ctags that referenced this issue Jul 22, 2024
Close universal-ctags#4043.

The test case is taken from universal-ctags#4033 submitted by @navinp0304.

Signed-off-by: Masatake YAMATO <[email protected]>
@masatake
Copy link
Member

Based on your input, I made a pull request #4034.

How do you list the regex supported by function in fortran or C for ctags? Is it possible to print it and how do i extend it ?

They don't use regular expressions at all. So you cannot list.

@navinp0304
Copy link
Author

Then how do you construct a tag for function in C

@masatake
Copy link
Member

Then how do you construct a tag for function in C

Consider the following input as an example:

void foo(void) { ... }
  1. read the input file till finding {.
  2. if you find {, read backward till finding (.
  3. if you find (, read characters satisfying the following condition: 'a' <= character and character <= 'Z' and record the characters to a stack.
  4. pick the characters from the stack as a string.
  5. write the string as a tag to tags file.

If you want to know the details, see files in https://github.com/universal-ctags/ctags/tree/master/parsers/cxx .

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

Successfully merging a pull request may close this issue.

2 participants