Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctags regex for multiple declarations in one line

I'm writing a .ctags file for a custom language... Like most languages, it allows for multiple variable declarations in one line.. i.e.:

int a, b, c;

I have a basic regex which recognizes 'a':

--regex-mylang=/^[ \t]*int[ \t]*([a-zA-Z_0-9]+)/\1/v,variable/

How do I modify this to have it match 'b' and 'c', as well? I can't find anything in ctags documentation that deals with multiple matches in a single line.

like image 581
Stan Avatar asked May 24 '12 16:05

Stan


2 Answers

The latest Universal-ctags can capture them.

[jet@localhost]/tmp% cat input.x 
int a, b, c;

[jet@localhost]/tmp% cat x.ctags 
--langdef=X
--map-X=.x

--kinddef-X=v,var,variables
--_tabledef-X=main
--_tabledef-X=vardef

--_mtable-regex-X=main/int[ \t]+//{tenter=vardef}
--_mtable-regex-X=main/.//

--_mtable-regex-X=vardef/([a-zA-Z0-9]+)/\1/v/
--_mtable-regex-X=vardef/;//{tleave}
--_mtable-regex-X=vardef/.//


[jet@localhost]/tmp% u-ctags --options=x.ctags -o - ./input.x 
a   ./input.x   /^int a, b, c;$/;"  v
b   ./input.x   /^int a, b, c;$/;"  v
c   ./input.x   /^int a, b, c;$/;"  v

See https://docs.ctags.io/en/latest/optlib.html#advanced-pattern-matching-with-multiple-regex-tables for more details.

like image 103
Masatake YAMATO Avatar answered Nov 15 '22 07:11

Masatake YAMATO


After going through this for a few hours, I'm convinced it can't be done. No matter what, the regular expression will only expand to one tag per line. Even if you put \1 \2 \3 ... as the expansion, that would just cause a tag consisting of multiple matches, instead of one tag per match.

It parses the C example correctly because inside the ctags source code it uses an actual code parser, not a regexp.

like image 34
Thomas Vander Stichele Avatar answered Nov 15 '22 07:11

Thomas Vander Stichele