ctags icon indicating copy to clipboard operation
ctags copied to clipboard

What is the syntax of the pattern appearing in each line of tag file?

Open rafmartom opened this issue 9 months ago • 8 comments

I have a my own custom format .dan files for a vim plugin I am developing, and ctags is working like a charm. The tag file generated looks something like

o#5m	nodejs.dan	/^ outgoingMessage.write(chunk[, encoding][, callback])   <L=o#5m>#<\/L><I=o#5m>  $/;"	i
o#5n	nodejs.dan	/^ http.METHODS   <L=o#5n>#<\/L><I=o#5n>  $/;"	i
o#5o	nodejs.dan	/^ http.STATUS_CODES   <L=o#5o>#<\/L><I=o#5o>  $/;"	i
o#5p	nodejs.dan	/^ http.createServer([options][, requestListener])   <L=o#5p>#<\/L><I=o#5p>  $/;"	i

And in the file I will have

 http.createServer([options][, requestListener])   <L=o#5p>#</L><I=o#5p>   

That will match in vim :tag o#5p

The issue is that in this format the user is expected to add some string to it so for instance the previous line may be altered to

 http.createServer([options][, requestListener])   <L=o#5p>#</L><I=o#5p>   (X)

In which now doing :tag o#5p wont be working anymore ,without regenerating the .ctags file with something like (\s\(X\)){0,1}$ at the end of the tag definition

But the files are incredibly long , so full of tags, that I dont want the user to have to re-generate the tagfile for each simple change. The user is neither not meant to alter the file for anything else , just adding these (X) at the end of some lines.

So I was looking into just manipulating the tagfile with sed , adding the following

o#5o	nodejs.dan	/^ http.STATUS_CODES   <L=o#5o>#<\/L><I=o#5o>  (\s\(X\)){0,1}$/;"	i
o#5p	nodejs.dan	/^ http.createServer([options][, requestListener])   <L=o#5p>#<\/L><I=o#5p>  (\s\(X\)){0,1}$/;"	i

But that just doesn't work.

I dont understand actually what it is allowed on that tagfile , as pattern , as I see it shouldnt be a normal Regex as it has generated unescapped () [] / .

Do you see any posibility to do this manually?

rafmartom avatar May 30 '25 13:05 rafmartom

I don't know. Vim people may know.

Regarding reading https://docs.ctags.io/en/stable/man/tags.5.html , vi handles patterns as Ex commands. So your question is "What is the syntax of the Ex command?"

masatake avatar May 30 '25 16:05 masatake

Thank you. It turns out as you said it follows the syntax of g/^{myPattern}$/

In my case I solved it doing \( (X)\)\?$

Having to modify all the tag files in this way

file=""
pattern=$(cat << 'EOF'
s/\$\/;"/\\( (X)\\)\\?\$\/;"/
EOF
)

sed -i "${pattern}" "${file}"

May that come handy to anyone to have less restrictive tagfiles , for use with vim

rafmartom avatar May 31 '25 14:05 rafmartom

May that come handy to anyone to have less restrictive tagfiles , for use with vim

I don't understand what you wrote well. Could you tell me more?

We can add patternAppend as a mtable-regex-flag that does what your sed command line did.

--_mtable-regex-dantags=toplevel/^<B=([a-zA-Z0-9]+)>/\1/b/{scope=set}{tenter=blocktab}{patternAppend=\\( (X)\\)\\?}

masatake avatar May 31 '25 17:05 masatake

Thanks @masatake , but I actually changed to a more simpler approach in my project , I just made all the links Absolute , so I dont need to be messing with scopes.

So what it used to be in the .dan documents <B=3> <I=5> <\B> Now is <B=3> <I=3#5> <\B>

Basically dan.ctags is ending up like this

--langdef=dantags
--langmap=dantags:.dan
--kinddef-dantags=b,block,blocks
--kinddef-dantags=i,inline,inlines

--regex-dantags=/^<B=([a-zA-Z0-9]+)>/\1/b/

--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\1/i/
--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\2/i/
--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\3/i/
--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\1/i/
--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>[^<]*<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\2/i/
--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\1/i/

rafmartom avatar May 31 '25 18:05 rafmartom

So I wonder what you want is patternAppend regex flag that can be used like:

--regex-dantags=/<I=([a-zA-Z0-9]+#[a-zA-Z0-9]+)>/\1/i/{patternAppend=\\( (X)\\)\\?}

Of course, using sed is not a bad idea.

masatake avatar May 31 '25 19:05 masatake

Didnt know that flag, I will have a look to include it in my .ctags file , so I dont have to run sed afterwards. Thanks

rafmartom avatar Jun 02 '25 08:06 rafmartom

patternAppend is not implemented yet. Just an idea. Would you like such a flag?

masatake avatar Jun 02 '25 09:06 masatake

I think is a really specific case, my case. Because it could be either patternAppend or patternPreppend. That is what I believe. For my case it looks good to be implemented but you do decide if its really a need that many people need to solve

rafmartom avatar Jun 02 '25 09:06 rafmartom