Skip to content

Commit e9daadb

Browse files
authored
Merge pull request #4064 from masatake/optscript--fix-bugs-in-foreigntag-proc
Optscript: fix bugs in foreigntag proc
2 parents 3d76ff3 + 1429090 commit e9daadb

File tree

14 files changed

+223
-29
lines changed

14 files changed

+223
-29
lines changed

Tmain/broken-extradef.d/stderr-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ ctags: no extra definition specified in "--_extradef-IMAGINARY" option
1010
# wrong char in a field name
1111
ctags: no extra description specified in "--_extradef-IMAGINARY" option
1212
ctags: no extra description specified in "--_extradef-IMAGINARY" option
13-
ctags: unacceptable char as part of extra name in "--_extradef-IMAGINARY" option
14-
ctags: unacceptable char as part of extra name in "--_extradef-IMAGINARY" option
13+
ctags: unacceptable char as part of extra name in "--_extradef-IMAGINARY" option: ':'
14+
ctags: unacceptable char as part of extra name in "--_extradef-IMAGINARY" option: ':'
1515

1616
# empty extra name
1717
ctags: the extra name in "--_extradef-IMAGINARY" option is empty

Tmain/broken-fielddef.d/stderr-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ ctags: no field definition specified in "--_fielddef-IMAGINARY" option
1010
# wrong char in a field name
1111
ctags: no field description specified in "--_fielddef-IMAGINARY" option
1212
ctags: no field description specified in "--_fielddef-IMAGINARY" option
13-
ctags: unacceptable char as part of field name in "--_fielddef-IMAGINARY" option
14-
ctags: unacceptable char as part of field name in "--_fielddef-IMAGINARY" option
13+
ctags: unacceptable char as part of field name in "--_fielddef-IMAGINARY" option: ':'
14+
ctags: unacceptable char as part of field name in "--_fielddef-IMAGINARY" option: ':'
1515

1616
# empty field name
1717
ctags: the field name in "--_fielddef-IMAGINARY" option is empty

Tmain/broken-paramdef.d/run.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright: 2018 Masatake YAMATO
2+
# License: GPL-2
3+
4+
CTAGS="$1 --quiet --options=NONE"
5+
6+
title()
7+
{
8+
echo
9+
echo "$@"
10+
11+
{
12+
echo
13+
echo "$@"
14+
} 1>&2
15+
}
16+
17+
{
18+
title '# echo unknown lang'
19+
${CTAGS} --_paramdef-NOSUCHLANG
20+
${CTAGS} --_paramdef-NOSUCHLANG=param,desc
21+
22+
title '# no option value'
23+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY
24+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=
25+
26+
title '# wrong char in a field name'
27+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=:
28+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=:abc
29+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=:abc,
30+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=:abc,description
31+
32+
title '# empty parameter name'
33+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=,
34+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=,abc
35+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=,abc,
36+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=,abc,description
37+
38+
title '# empty description'
39+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=abc
40+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=abc,
41+
42+
title '# no input file'
43+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY=abc,desc
44+
45+
title '# inject a flag separator'
46+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,desc{foo}' --list-params=IMAGINARY
47+
48+
title '# inject a broken flag separator(1)'
49+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,desc{foo' --list-params=IMAGINARY
50+
51+
title '# inject a broken flag separator(2)'
52+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,desc{' --list-params=IMAGINARY
53+
54+
title '# use a { in description (1)'
55+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,desc\{' --list-params=IMAGINARY
56+
57+
title '# use a { in description (2)'
58+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,desc\{}' --list-params=IMAGINARY
59+
60+
title '# use a \ in description'
61+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,desc\\backslash' --list-params=IMAGINARY
62+
63+
title '# description started from {'
64+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,{' --list-params=IMAGINARY
65+
66+
title '# description started from \{'
67+
${CTAGS} --langdef=IMAGINARY --_paramdef-IMAGINARY='param,\{' --list-params=IMAGINARY
68+
69+
} > /tmp/ctags-tmain-$$.stdout 2>/tmp/ctags-tmain-$$.stderr
70+
71+
sed -e 's/\.exe//g' < /tmp/ctags-tmain-$$.stdout
72+
rm /tmp/ctags-tmain-$$.stdout
73+
74+
sed -e 's/\.exe//g' < /tmp/ctags-tmain-$$.stderr 1>&2
75+
rm /tmp/ctags-tmain-$$.stderr
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
# echo unknown lang
3+
ctags: Unknown language "NOSUCHLANG" in "_paramdef-NOSUCHLANG" option
4+
ctags: Unknown language "NOSUCHLANG" in "_paramdef-NOSUCHLANG" option
5+
6+
# no option value
7+
ctags: no parameter definition specified in "--_paramdef-IMAGINARY" option
8+
ctags: no parameter definition specified in "--_paramdef-IMAGINARY" option
9+
10+
# wrong char in a field name
11+
ctags: no parameter description specified in "--_paramdef-IMAGINARY" option
12+
ctags: no parameter description specified in "--_paramdef-IMAGINARY" option
13+
ctags: unacceptable char as part of parameter name in "--_paramdef-IMAGINARY" option: ':'
14+
ctags: unacceptable char as part of parameter name in "--_paramdef-IMAGINARY" option: ':'
15+
16+
# empty parameter name
17+
ctags: the parameter name in "--_paramdef-IMAGINARY" option is empty
18+
ctags: the parameter name in "--_paramdef-IMAGINARY" option is empty
19+
ctags: the parameter name in "--_paramdef-IMAGINARY" option is empty
20+
ctags: the parameter name in "--_paramdef-IMAGINARY" option is empty
21+
22+
# empty description
23+
ctags: no parameter description specified in "--_paramdef-IMAGINARY" option
24+
ctags: parameter description in "--_paramdef-IMAGINARY" option is empty
25+
26+
# no input file
27+
ctags: No files specified. Try "ctags --help".
28+
29+
# inject a flag separator
30+
31+
# inject a broken flag separator(1)
32+
ctags: Warning: long flags specifier opened with `{' is not closed `}': "{foo"
33+
34+
# inject a broken flag separator(2)
35+
ctags: Warning: long flags specifier opened with `{' is not closed `}': "{"
36+
37+
# use a { in description (1)
38+
39+
# use a { in description (2)
40+
41+
# use a \ in description
42+
43+
# description started from {
44+
ctags: parameter description in "--_paramdef-IMAGINARY" option is empty
45+
46+
# description started from \{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# echo unknown lang
3+
4+
# no option value
5+
6+
# wrong char in a field name
7+
8+
# empty parameter name
9+
10+
# empty description
11+
12+
# no input file
13+
14+
# inject a flag separator
15+
#NAME DESCRIPTION
16+
param desc
17+
18+
# inject a broken flag separator(1)
19+
#NAME DESCRIPTION
20+
param desc
21+
22+
# inject a broken flag separator(2)
23+
#NAME DESCRIPTION
24+
param desc
25+
26+
# use a { in description (1)
27+
#NAME DESCRIPTION
28+
param desc{
29+
30+
# use a { in description (2)
31+
#NAME DESCRIPTION
32+
param desc{}
33+
34+
# use a \ in description
35+
#NAME DESCRIPTION
36+
param desc\backslash
37+
38+
# description started from {
39+
40+
# description started from \{
41+
#NAME DESCRIPTION
42+
param {

Tmain/roledef.d/stderr-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ctags: the role name in "--_roledef-IMAGINARY.{variable}" option is empty
4545
ctags: the role name in "--_roledef-IMAGINARY.{variable}" option is empty
4646

4747
# wrong char in role name
48-
ctags: unacceptable char as part of role name in "--_roledef-IMAGINARY.v" option: +
49-
ctags: unacceptable char as part of role name in "--_roledef-IMAGINARY.{variable}" option: +
48+
ctags: unacceptable char as part of role name in "--_roledef-IMAGINARY.v" option: '+'
49+
ctags: unacceptable char as part of role name in "--_roledef-IMAGINARY.{variable}" option: '+'
5050

5151
# empty description
5252
ctags: no role description specified in "--_roledef-IMAGINARY.v" option

Units/optscript.r/with-foreignLanguage-flag.d/args.ctags

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
--langdef=XXX{_foreignLanguage=C}
66
--map-XXX=.xxx
7+
--fields=+n
8+
79
--kinddef-XXX=a,abc,abcx
810
--_roledef-XXX.a=assigned,assigned
911

@@ -27,6 +29,21 @@
2729
--regex-XXX=/\/\*(D)\(\)\*\//\1/f/{_role=arolefortesting}{_language=C}
2830
--regex-XXX=/\/\*(E)\(\)\*\///{{
2931
\1 /C /function /arolefortesting _foreignreftag _commit pop
32+
1 _matchloc
33+
}}
34+
35+
--regex-XXX=/\/\*(F)\(\)\*\///{{
36+
dup
37+
\1 /C /function 4 -1 roll _foreigntag _commit pop
38+
}}
39+
40+
--regex-XXX=/\/\*(G)\(\)\*\///{{
41+
dup
42+
\1 /C /function /arolefortesting 5 -1 roll _foreignreftag _commit pop
43+
}}
44+
45+
--regex-XXX=/\/\*(H)\(\)\*\///{{
46+
\1 /C /function null 5 -1 roll _foreignreftag _commit pop
3047
}}
3148

3249
--regex-C=/FUNC\(([a-z]*)\);/\1/f/
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
a input.xxx /^a$/;" a language:XXX roles:def
2-
b input.xxx /^b$/;" a language:XXX roles:def
3-
c input.xxx /^c$/;" a language:XXX roles:assigned
4-
d input.xxx /^d$/;" a language:XXX roles:assigned
5-
A input.xxx /^\/*A()*\/$/;" f language:C roles:def
6-
B input.xxx /^\/*B()*\/$/;" f language:C roles:def
7-
C input.xxx /^\/*C()*\/$/;" f language:C roles:arolefortesting
8-
D input.xxx /^\/*D()*\/$/;" f language:C roles:arolefortesting
9-
E input.xxx /^\/*E()*\/$/;" f language:C roles:arolefortesting
10-
myfunc input-0.c /^FUNC(myfunc);$/;" f language:C roles:def
1+
a input.xxx /^a$/;" a line:1 language:XXX roles:def
2+
b input.xxx /^b$/;" a line:2 language:XXX roles:def
3+
c input.xxx /^c$/;" a line:3 language:XXX roles:assigned
4+
d input.xxx /^d$/;" a line:4 language:XXX roles:assigned
5+
A input.xxx /^\/*A()*\/$/;" f line:5 language:C roles:def
6+
B input.xxx /^\/*B()*\/$/;" f line:6 language:C roles:def
7+
C input.xxx /^\/*C()*\/$/;" f line:7 language:C roles:arolefortesting
8+
D input.xxx /^\/*D()*\/$/;" f line:8 language:C roles:arolefortesting
9+
E input.xxx /^\/*E()*\/$/;" f line:9 language:C roles:arolefortesting
10+
F input.xxx /^\/*E()*\/$/;" f line:9 language:C roles:def
11+
G input.xxx /^\/*E()*\/$/;" f line:9 language:C roles:arolefortesting
12+
H input.xxx /^\/*E()*\/$/;" f line:9 language:C roles:def
13+
myfunc input-0.c /^FUNC(myfunc);$/;" f line:1 language:C roles:def

Units/optscript.r/with-foreignLanguage-flag.d/input.xxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ d
77
/*C()*/
88
/*D()*/
99
/*E()*/
10+
/*F()*/
11+
/*G()*/
12+
/*H()*/

docs/optlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ When defining a new parser specific field, it is disabled by default. Enable the
465465
field explicitly to use the field. See ":ref:`Parser specific fields <parser-specific-fields>`"
466466
about ``--fields-<LANG>`` option.
467467

468-
`passwd` parser is a simple example that uses ``--fields-<LANG>`` option.
468+
`Passwd` parser is a simple example that uses ``--fields-<LANG>`` option.
469469

470470
By default, ctags assumes the field is a part of the language specified
471471
with `<LANG>` in ``--regex-<LANG>``. Together with ``{_language=<LANG>}``

main/CommonPrelude.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,19 @@ const char ctagsCommonPrelude []=
250250
" _foreignreftag\n"
251251
"} __bddef\n"
252252
"\n"
253-
"(name:str language:name kind:name matchloc _FOREIGNTAG tag\n"
253+
"(name:str lang:name kind:name matchloc _FOREIGNTAG tag\n"
254254
" name:str lang:name kind:name _FOREIGNTAG tag)\n"
255255
"/_foreigntag {\n"
256-
" null _foreignreftag\n"
256+
" dup type /nametype eq {\n"
257+
" % name:str lang:name kind:name\n"
258+
" null\n"
259+
" % name:str lang:name kind:name null\n"
260+
" _foreignreftag\n"
261+
" } {\n"
262+
" % name:str language:name kind:name matchloc\n"
263+
" null exch\n"
264+
" % name:str language:name kind:name null matchloc\n"
265+
" _foreignreftag\n"
266+
" } ifelse\n"
257267
"} __bddef\n"
258268
;

main/CommonPrelude.ps

290 Bytes
Binary file not shown.

main/lregex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4402,7 +4402,7 @@ static struct optscriptOperatorRegistration lropOperators [] = {
44024402
.name = "_foreignreftag",
44034403
.fn = lrop_make_foreignreftag,
44044404
.arity = -1,
4405-
.help_str = "name:str lang:name kind:name role:name matchloc _FOREIGNREFTAG tag%"
4405+
.help_str = "name:str lang:name kind:name role:name|null matchloc _FOREIGNREFTAG tag%"
44064406
"name:str lang:name|null kind:name role:name|null _FOREIGNREFTAG tag%",
44074407
},
44084408
{

main/parse.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,7 @@ static bool processLangDefineRole(const langType language,
28682868
while (p != tmp_end)
28692869
{
28702870
if (!isalnum ((unsigned char) *p))
2871-
error (FATAL, "unacceptable char as part of role name in \"--%s\" option: %c",
2871+
error (FATAL, "unacceptable char as part of role name in \"--%s\" option: '%c'",
28722872
option, *p);
28732873
p++;
28742874
}
@@ -3553,8 +3553,8 @@ static bool processLangDefineParam (const langType language,
35533553
for (; p < name_end; p++)
35543554
{
35553555
if (!isalnum ((unsigned char) *p) && *p != '_')
3556-
error (FATAL, "unacceptable char as part of extra name in \"--%s\" option",
3557-
option);
3556+
error (FATAL, "unacceptable char as part of parameter name in \"--%s\" option: '%c'",
3557+
option, *p);
35583558
}
35593559

35603560
p++;
@@ -3567,10 +3567,8 @@ static bool processLangDefineParam (const langType language,
35673567
pdef->name = eStrndup (parameter, name_end - parameter);
35683568
pdef->desc = desc;
35693569

3570-
#if 0
35713570
if (flags)
35723571
flagsEval (flags, NULL, 0, pdef);
3573-
#endif
35743572

35753573
parser = LanguageTable + language;
35763574
defineParam (parser->paramControlBlock, pdef, freePdef);
@@ -3959,8 +3957,8 @@ static bool processLangDefineExtra (const langType language,
39593957
for (; p < name_end; p++)
39603958
{
39613959
if (!isalnum ((unsigned char) *p))
3962-
error (FATAL, "unacceptable char as part of extra name in \"--%s\" option",
3963-
option);
3960+
error (FATAL, "unacceptable char as part of extra name in \"--%s\" option: '%c'",
3961+
option, *p);
39643962
}
39653963

39663964
p++;
@@ -4028,8 +4026,8 @@ static bool processLangDefineField (const langType language,
40284026
for (; p < name_end; p++)
40294027
{
40304028
if (!isalpha ((unsigned char) *p))
4031-
error (FATAL, "unacceptable char as part of field name in \"--%s\" option",
4032-
option);
4029+
error (FATAL, "unacceptable char as part of field name in \"--%s\" option: '%c'",
4030+
option, *p);
40334031
}
40344032

40354033
p++;

0 commit comments

Comments
 (0)