universal-ctags/issues-we-will-not-fix-in-soon

Questions: Any way to parse text in memory?

Closed this issue · 5 comments

I use following command to parse the test.cpp and result is as following.
universal-ctags-x64.exe --output-format=json --langmap=c:+.inc.def --kinds-c=+plz --fields=+ne -o - D:\projects\demo\test.cpp

test.cpp
const ProcItemStru g_strc[5] = {
{JOB1, JOB1, 0, 0, JOB1}, {JOB1, JOB1, 0, 0, JOB1},
{JOB1, JOB1, 0, 0, JOB1}, {JOB1, JOB1, 0, 0, JOB1},
{JOB1, JOB1, 0, 0, JOB1},
};

if I have got file content, any ways to use ctags to parse the text in memory directly?

ctags is a command. Therefore there is no way to access the memory address space of your program.

You have to copy & paste ctags code into your program to use the feature of ctags in your program.

Here is an example.
https://github.com/universal-ctags/ctags/blob/master/main/mini-geany.c

My thought is we can use a named pipe for this, like:

$ mkfifo /tmp/test.c
$ printf "int a;\n" > /tmp/test.c &
[1] 3278
$ ctags -f- /tmp/test.c
(no output)
$ cat /tmp/test.c
int a;
[1]+  Done                    printf "int a;\n" > /tmp/test.c

But this doesn't work. Seems ctags didn't consume the content in that pipe. @masatake do you know why?

eStat() defined in main/routines.c verifies whether the input file is a regular file or not.
ctags expects the input is "seekable". The pipe is not seekable.

If you want to use ctags in that way, you may have interests in --_interactive option described in https://docs.ctags.io/en/latest/interactive-mode.html.

It would be nice if there was a way to parse the files in memory. For example, the use case can be if I am trying to walk through a git repo and read its files in memory and then parse them and get the required details from them rather than having to check out the repo to do the same.
Is there any way as of now to achieve the above-mentioned use case?

Feel free to fork this repository to parse the contents on the memory.
We don't have enough resources to maintain the API for the purpose. Moreover, I don't have enough skill to design the API for the purpose. mini-geany.c is very special. It is for people who know C tags very well.