Skip to content

Commit 72847ce

Browse files
authored
Merge pull request #3548 from masatake/readtags--nth-fields
readtags: add $nth and &nth field values
2 parents a62336c + 7389f42 commit 72847ce

File tree

9 files changed

+80
-13
lines changed

9 files changed

+80
-13
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* ctags --options=NONE --sort=yes--kinds-C=+z --fields=+o output.tags */
2+
int z(int y, int x)
3+
{
4+
return 0;
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2+
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3+
!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/
4+
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
5+
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
6+
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
7+
!_TAG_PROC_CWD /home/jet/var/ctags-github/Tmain/readtags-qualifier-nth-field.d/ //
8+
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
9+
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
10+
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
11+
!_TAG_PROGRAM_VERSION 5.9.0 //
12+
x input.c /^int z(int y, int x)$/;" z function:z typeref:typename:int file: nth:1
13+
y input.c /^int z(int y, int x)$/;" z function:z typeref:typename:int file: nth:0
14+
z input.c /^int z(int y, int x)$/;" f typeref:typename:int
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# Copyright: 2016 Masatake YAMATO
4+
# License: GPL-2
5+
6+
READTAGS=$3
7+
8+
. ../utils.sh
9+
10+
#V="valgrind --leak-check=full -v"
11+
V=
12+
13+
if ! [ -x "${READTAGS}" ]; then
14+
skip "no readtags"
15+
fi
16+
17+
if ! ( "${READTAGS}" -h | grep -q -e -Q ); then
18+
skip "no qualifier function in readtags"
19+
fi
20+
21+
${V} ${READTAGS} -e -t output.tags \
22+
-Q '(eq? $kind "z")' \
23+
-S '(<> $nth &nth)' \
24+
-F '(list $name ":" $nth #t)' \
25+
-l

Tmain/readtags-qualifier-nth-field.d/stderr-expected.txt

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
y:0
2+
x:1

dsl/dsl.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ DECLARE_VALUE_FN(inherits);
9696
DECLARE_VALUE_FN(implementation);
9797
DECLARE_VALUE_FN(kind);
9898
DECLARE_VALUE_FN(language);
99+
DECLARE_VALUE_FN(nth);
99100
DECLARE_VALUE_FN(scope);
100101
DECLARE_VALUE_FN(scope_kind);
101102
DECLARE_VALUE_FN(scope_name);
@@ -213,6 +214,8 @@ static DSLProcBind pbinds [] = {
213214
.helpstr = "-> <list>" },
214215
{ "$implementation", value_implementation, NULL, DSL_PATTR_MEMORABLE, 0UL,
215216
.helpstr = "-> #f|<string>" },
217+
{ "$nth", value_nth, NULL, DSL_PATTR_MEMORABLE, 0UL,
218+
.helpstr = "-> #f|<integer>"},
216219
{ "$kind", value_kind, NULL, DSL_PATTR_MEMORABLE, 0UL,
217220
.helpstr = "-> #f|<string>"},
218221
{ "$language", value_language, NULL, DSL_PATTR_MEMORABLE, 0UL,
@@ -903,6 +906,7 @@ DEFINE_VALUE_FN(inherits)
903906
DEFINE_VALUE_FN(implementation)
904907
DEFINE_VALUE_FN(kind)
905908
DEFINE_VALUE_FN(language)
909+
DEFINE_VALUE_FN(nth)
906910
DEFINE_VALUE_FN(scope)
907911
DEFINE_VALUE_FN(scope_kind)
908912
DEFINE_VALUE_FN(scope_name)
@@ -937,6 +941,23 @@ EsObject* dsl_entry_xget_string (const tagEntry *entry, const char* name)
937941
return es_false;
938942
}
939943

944+
EsObject* dsl_entry_xget_integer (const tagEntry *entry, const char* name)
945+
{
946+
const char *end_str = entry_xget(entry, name);
947+
EsObject *o;
948+
949+
if (end_str)
950+
{
951+
o = es_read_from_string (end_str, NULL);
952+
if (es_integer_p (o))
953+
return es_object_autounref (o);
954+
else
955+
return es_false;
956+
}
957+
else
958+
return es_false;
959+
}
960+
940961
/*
941962
* Accessesors for tagEntry
942963
*/
@@ -978,6 +999,11 @@ EsObject* dsl_entry_language (const tagEntry *entry)
978999
return dsl_entry_xget_string (entry, "language");
9791000
}
9801001

1002+
EsObject* dsl_entry_nth (const tagEntry *entry)
1003+
{
1004+
return dsl_entry_xget_integer(entry, "nth");
1005+
}
1006+
9811007
EsObject* dsl_entry_implementation (const tagEntry *entry)
9821008
{
9831009
return dsl_entry_xget_string (entry, "implementation");
@@ -1005,19 +1031,7 @@ EsObject* dsl_entry_extras (const tagEntry *entry)
10051031

10061032
EsObject* dsl_entry_end (const tagEntry *entry)
10071033
{
1008-
const char *end_str = entry_xget(entry, "end");
1009-
EsObject *o;
1010-
1011-
if (end_str)
1012-
{
1013-
o = es_read_from_string (end_str, NULL);
1014-
if (es_integer_p (o))
1015-
return es_object_autounref (o);
1016-
else
1017-
return es_false;
1018-
}
1019-
else
1020-
return es_false;
1034+
return dsl_entry_xget_integer(entry, "end");
10211035
}
10221036

10231037
EsObject* dsl_entry_kind (const tagEntry *entry)

dsl/dsl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ EsObject *dsl_compile_and_eval (EsObject *expr, DSLEnv *env);
9797

9898

9999
EsObject* dsl_entry_xget_string (const tagEntry *entry, const char* name);
100+
EsObject* dsl_entry_xget_integer (const tagEntry *entry, const char* name);
100101

101102
EsObject* dsl_entry_name (const tagEntry *entry);
102103
EsObject* dsl_entry_input (const tagEntry *entry);
@@ -111,6 +112,7 @@ EsObject* dsl_entry_inherits (const tagEntry *entry);
111112
EsObject* dsl_entry_implementation (const tagEntry *entry);
112113
EsObject* dsl_entry_kind (const tagEntry *entry);
113114
EsObject* dsl_entry_language (const tagEntry *entry);
115+
EsObject* dsl_entry_nth (const tagEntry *entry);
114116
EsObject* dsl_entry_scope (const tagEntry *entry);
115117
EsObject* dsl_entry_scope_kind (const tagEntry *entry);
116118
EsObject* dsl_entry_scope_name (const tagEntry *entry);

dsl/sorter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ DECLARE_ALT_VALUE_FN(inherits);
5959
DECLARE_ALT_VALUE_FN(implementation);
6060
DECLARE_ALT_VALUE_FN(kind);
6161
DECLARE_ALT_VALUE_FN(language);
62+
DECLARE_ALT_VALUE_FN(nth);
6263
DECLARE_ALT_VALUE_FN(scope);
6364
DECLARE_ALT_VALUE_FN(scope_kind);
6465
DECLARE_ALT_VALUE_FN(scope_name);
@@ -115,6 +116,8 @@ static DSLProcBind pbinds [] = {
115116
.helpstr = "-> #f|<string>"},
116117
{ "&language", alt_value_language, NULL, DSL_PATTR_MEMORABLE, 0UL,
117118
.helpstr = "-> #f|<string>" },
119+
{ "&nth", alt_value_nth, NULL, DSL_PATTR_MEMORABLE, 0UL,
120+
.helpstr = "-> #f|<integer>"},
118121
{ "&scope", alt_value_scope, NULL, DSL_PATTR_MEMORABLE, 0UL,
119122
.helpstr = "-> #f|<string>; $scope-kind:$scope-name"},
120123
{ "&scope-kind", alt_value_scope_kind, NULL, DSL_PATTR_MEMORABLE, 0UL,
@@ -155,6 +158,7 @@ DEFINE_ALT_VALUE_FN(inherits);
155158
DEFINE_ALT_VALUE_FN(implementation);
156159
DEFINE_ALT_VALUE_FN(kind);
157160
DEFINE_ALT_VALUE_FN(language);
161+
DEFINE_ALT_VALUE_FN(nth);
158162
DEFINE_ALT_VALUE_FN(scope);
159163
DEFINE_ALT_VALUE_FN(scope_kind);
160164
DEFINE_ALT_VALUE_FN(scope_name);

0 commit comments

Comments
 (0)