Skip to content

Commit 500d0b6

Browse files
committed
main: consider foreign languages when solving the extra specifying _extra regex flag
The original code assumed the parser specified in a regex pattern was the owner of the extra specified with the _extra regex flag in the pattern. For an example, in the option --regex-Foo=/.../{_extra=anextra}... , ctags assumed "anextra" was a specific extra of "Foo" parser. The original code didn't consider an option like --regex-Foo=/.../{_language=Bar}{_extra=anextra}... In this case, ctags should consider "anextra" as a specific extra of "Bar" parser. NOTE: the language specified with _language flag must be declared with _foreignLanguage= in --langdef-Foo. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent a424cf5 commit 500d0b6

File tree

12 files changed

+55
-6
lines changed

12 files changed

+55
-6
lines changed

Tmain/list-mline-regex-flags.d/stdout-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ p pcre2 use pcre2 regex engine
99
- warning="MESSAGE" print the given MESSAGE at WARNING level
1010
- _advanceTo=N[start|end] a group in pattern from where the next scan starts [0end]
1111
- _anonymous=PREFIX make an anonymous tag with PREFIX
12-
- _extra=EXTRA record the tag only when the extra is enabled
12+
- _extra=EXTRA record the tag only when the (foreign) extra is enabled
1313
- _field=FIELD:VALUE record the matched string(VALUE) to the (foreign) language specific FIELD of the tag
1414
- _guest=PARSERSPEC,N0[start|end],N1[start|end] run guest parser on the area
1515
- _language=LANG make a foreign tag for LANG

Tmain/list-mtable-regex-flags.d/stdout-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ p pcre2 use pcre2 regex engine
1515
- warning="MESSAGE" print the given MESSAGE at WARNING level
1616
- _advanceTo=N[start|end] a group in pattern from where the next scan starts [0end]
1717
- _anonymous=PREFIX make an anonymous tag with PREFIX
18-
- _extra=EXTRA record the tag only when the extra is enabled
18+
- _extra=EXTRA record the tag only when the (foreign) extra is enabled
1919
- _field=FIELD:VALUE record the matched string(VALUE) to the (foreign) language specific FIELD of the tag
2020
- _guest=PARSERSPEC,N0[start|end],N1[start|end] run guest parser on the area
2121
- _language=LANG make a foreign tag for LANG

Tmain/list-regex-flags.d/stdout-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ x exclusive skip testing the other pat
1010
- scope=ACTION use scope stack: ACTION = ref|push|pop|clear|set|replace|intervaltab
1111
- warning="MESSAGE" print the given MESSAGE at WARNING level
1212
- _anonymous=PREFIX make an anonymous tag with PREFIX
13-
- _extra=EXTRA record the tag only when the extra is enabled
13+
- _extra=EXTRA record the tag only when the (foreign) extra is enabled
1414
- _field=FIELD:VALUE record the matched string(VALUE) to the (foreign) language specific FIELD of the tag
1515
- _guest=PARSERSPEC,N0[start|end],N1[start|end] run guest parser on the area
1616
- _language=LANG make a foreign tag for LANG
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
D:def00
2+
d:def01
3+
v:var0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
D:def10
2+
d:def11
3+
v:var1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright: 2024 Masatake YAMATO
2+
# License: GPL-2
3+
4+
. ../utils.sh
5+
6+
CTAGS=$1
7+
8+
V=
9+
# V=valgrind
10+
11+
printf "# %s\n" --extras-X0=+'{iname}'
12+
${V} ${CTAGS} --quiet --options=NONE --options=./x0.ctags --options=./x1.ctags \
13+
--extras-X0=+'{iname}' --fields=+'{extras}{language}' -o - input-0.x1
14+
15+
printf "# %s\n" --extras-X0=-'{iname}'
16+
${V} ${CTAGS} --quiet --options=NONE --options=./x0.ctags --options=./x1.ctags \
17+
--extras-X0=-'{iname}' --fields=+'{extras}{language}' -o - input-1.x1

Tmain/parser-own-extras-for-foreign-lang.d/stderr-expected.txt

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# --extras-X0=+{iname}
2+
__def01__ input-0.x1 /^d:def01$/;" d language:X0 extras:iname
3+
def00 input-0.x1 /^D:def00$/;" d language:X0
4+
var0 input-0.x1 /^v:var0$/;" v language:X1
5+
# --extras-X0=-{iname}
6+
def10 input-1.x1 /^D:def10$/;" d language:X0
7+
var1 input-1.x1 /^v:var1$/;" v language:X1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--langdef=X0
2+
--kinddef-X0=d,def,definitions
3+
--_extradef-X0=iname,internal name like __x__
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--langdef=X1{_foreignLanguage=X0}
2+
--map-X1=+.x1
3+
--kinddef-X1=v,var,variables
4+
--regex-X1=/D:([a-z0-9]+)$/\1/d/{_language=X0}
5+
--regex-X1=/d:([a-z0-9]+)$/__\1__/d/{_language=X0}{_extra=iname}
6+
--regex-X1=/v:([a-z0-9]+)$/\1/v/

docs/optlib.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ The pattern matching is done only when the ``main`` is enabled.
371371
$ ctags --options=python-main.ctags -o - --extras-Python='+{main}' input.py
372372
__main__ input.py /^if __name__ == '__main__':$/;" f
373373
374+
By default, ctags assumes the extra is a part of the language specified
375+
with `<LANG>` in ``--regex-<LANG>``. Together with ``{_language=<LANG>}``
376+
flag, you can switch the language of the extra. See ":ref:`foreigntag`".
377+
The combination of these flags is new in version 6.2.0.
374378

375379
.. TODO: this "fields" section should probably be moved up this document, as a
376380
subsection in the "Regex option argument flags" section
@@ -1971,6 +1975,9 @@ the output for input.docc:
19711975
``{_language=<LANG>}`` flag affects ``{_field=FIELDNAME:GROUP}`` flag; ctags looks up
19721976
the field defintion in `<LANG>`.
19731977
1978+
``{_language=<LANG>}`` flag affects ``{_extra=XNAME}`` flag; ctags looks up
1979+
the extra defintion in `<LANG>`.
1980+
19741981
.. END: NOT REVIEWED YET
19751982
19761983
.. _optlib2c:

main/lregex.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,12 @@ static void common_flag_extra_long (const char* const s, const char* const v, vo
10841084
return;
10851085
}
10861086

1087-
cdata->ptrn->xtagType = getXtagTypeForNameAndLanguage (v, cdata->owner);
1087+
langType lang = (cdata->ptrn->foreign_lang == LANG_IGNORE)
1088+
? cdata->owner
1089+
: cdata->ptrn->foreign_lang;
1090+
cdata->ptrn->xtagType = getXtagTypeForNameAndLanguage (v, lang);
10881091
if (cdata->ptrn->xtagType == XTAG_UNKNOWN)
1089-
error (WARNING, "no such extra \"%s\" in %s", v, getLanguageName(cdata->owner));
1092+
error (WARNING, "no such extra \"%s\" in %s", v, getLanguageName(lang));
10901093
}
10911094

10921095

@@ -1271,7 +1274,7 @@ static flagDefinition commonSpecFlagDef[] = {
12711274
"\"MESSAGE\"", "print the given MESSAGE at WARNING level"},
12721275
#define EXPERIMENTAL "_"
12731276
{ '\0', EXPERIMENTAL "extra", NULL, common_flag_extra_long ,
1274-
"EXTRA", "record the tag only when the extra is enabled"},
1277+
"EXTRA", "record the tag only when the (foreign) extra is enabled"},
12751278
{ '\0', EXPERIMENTAL "field", NULL, common_flag_field_long ,
12761279
"FIELD:VALUE", "record the matched string(VALUE) to the (foreign) language specific FIELD of the tag"},
12771280
{ '\0', EXPERIMENTAL "role", NULL, common_flag_role_long,

0 commit comments

Comments
 (0)