Skip to content

Commit 0e819f6

Browse files
committed
main: consider foreign languages when solving the field type specifying _field regex flag
The original code assumed the parser specified in a regex pattern was the owner of the field specified with the _field regex flag in the pattern. For an example, in the option --regex-Foo=/.../{_field=afield:\1}... , ctags assumed "afield" was a specific field of "Foo" parser. The original code didn't consider an option like --regex-Foo=/.../{_language=Bar}{_field=afield:\1}... In this case, ctags should consider "afield" as a specific field 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 a7b07d7 commit 0e819f6

File tree

13 files changed

+78
-6
lines changed

13 files changed

+78
-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
@@ -10,7 +10,7 @@ p pcre2 use pcre2 regex engine
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
1212
- _extra=EXTRA record the tag only when the extra is enabled
13-
- _field=FIELD:VALUE record the matched string(VALUE) to parser own FIELD of the tag
13+
- _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
1616
- _role=ROLE set the given ROLE to the roles field

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ p pcre2 use pcre2 regex engine
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
1818
- _extra=EXTRA record the tag only when the extra is enabled
19-
- _field=FIELD:VALUE record the matched string(VALUE) to parser own FIELD of the tag
19+
- _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
2222
- _role=ROLE set the given ROLE to the roles field

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ x exclusive skip testing the other pat
1111
- warning="MESSAGE" print the given MESSAGE at WARNING level
1212
- _anonymous=PREFIX make an anonymous tag with PREFIX
1313
- _extra=EXTRA record the tag only when the extra is enabled
14-
- _field=FIELD:VALUE record the matched string(VALUE) to parser own FIELD of the tag
14+
- _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
1717
- _role=ROLE set the given ROLE to the roles field
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+
${V} ${CTAGS} --quiet --options=NONE \
12+
\
13+
--langdef=NOSUCHLANG'{_foreignLanguage=Kconfig}' \
14+
--_fielddef-NOSUCHLANG='NOSUCHFIELD,but this is not the part of Kconfig' \
15+
--regex-NOSUCHLANG='/^\# (CONFIG_[^ ]+) is (not set)/\1/c/{_language=Kconfig}{_field=NOSUCHFIELD:\1}{exclusive}' \
16+
\
17+
--_force-quit=0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ctags: Warning: no such field "NOSUCHFIELD" in Kconfig
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public func foo(n, m);
2+
protected func bar(n);
3+
private func baz(n,...);
4+
X:tagme@iamowner
5+
Y:iamowner2=tagme2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--langdef=knownz
2+
--kinddef-knownz=m,mark,makers
3+
4+
--_fielddef-knownz=owner,the owner of the markers
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --options=./unknownx.ctags \
12+
--fields=+l \
13+
--fields-unknownx=+'{protection}{signature}' \
14+
--fields-knownz=+'{owner}' \
15+
-o - input.unknownx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ctags: Notice: No options will be read from files or environment
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bar input.unknownx /^protected func bar(n);$/;" f language:unknownx protection:protected signature:(n)
2+
baz input.unknownx /^private func baz(n,...);$/;" f language:unknownx protection:private signature:(n,...)
3+
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
4+
tagme input.unknownx /^X:tagme@iamowner$/;" m language:knownz owner:iamowner
5+
tagme2 input.unknownx /^Y:iamowner2=tagme2$/;" m language:knownz owner:iamowner2

0 commit comments

Comments
 (0)