Skip to content

Commit e9afc80

Browse files
authored
Merge pull request #3768 from masatake/readtags--regex-group-extraction
dsl: extend #/../ operator to be able to extract a matched group in the pattern
2 parents 0ae4783 + 3b59095 commit e9afc80

File tree

12 files changed

+405
-7
lines changed

12 files changed

+405
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* ../../ctags -o output.tags --fields=+Z'{nth}' --pseudo-tags= --pseudo-tags=+TAG_FILE_FORMAT --pseudo-tags=+TAG_FILE_SORTED input.c */
2+
3+
/* Taken from linux/include/uapi/linux/bpf.h */
4+
enum bpf_prog_type {
5+
BPF_PROG_TYPE_UNSPEC,
6+
BPF_PROG_TYPE_SOCKET_FILTER,
7+
BPF_PROG_TYPE_KPROBE,
8+
BPF_PROG_TYPE_SCHED_CLS,
9+
BPF_PROG_TYPE_SCHED_ACT,
10+
BPF_PROG_TYPE_TRACEPOINT,
11+
BPF_PROG_TYPE_XDP,
12+
BPF_PROG_TYPE_PERF_EVENT,
13+
BPF_PROG_TYPE_CGROUP_SKB,
14+
BPF_PROG_TYPE_CGROUP_SOCK,
15+
BPF_PROG_TYPE_LWT_IN,
16+
BPF_PROG_TYPE_LWT_OUT,
17+
BPF_PROG_TYPE_LWT_XMIT,
18+
BPF_PROG_TYPE_SOCK_OPS,
19+
BPF_PROG_TYPE_SK_SKB,
20+
BPF_PROG_TYPE_CGROUP_DEVICE,
21+
BPF_PROG_TYPE_SK_MSG,
22+
BPF_PROG_TYPE_RAW_TRACEPOINT,
23+
BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
24+
BPF_PROG_TYPE_LWT_SEG6LOCAL,
25+
BPF_PROG_TYPE_LIRC_MODE2,
26+
BPF_PROG_TYPE_SK_REUSEPORT,
27+
BPF_PROG_TYPE_FLOW_DISSECTOR,
28+
BPF_PROG_TYPE_CGROUP_SYSCTL,
29+
BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
30+
BPF_PROG_TYPE_CGROUP_SOCKOPT,
31+
BPF_PROG_TYPE_TRACING,
32+
BPF_PROG_TYPE_STRUCT_OPS,
33+
BPF_PROG_TYPE_EXT,
34+
BPF_PROG_TYPE_LSM,
35+
BPF_PROG_TYPE_SK_LOOKUP,
36+
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
37+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
BPF_PROG_TYPE_CGROUP_DEVICE input.c /^ BPF_PROG_TYPE_CGROUP_DEVICE,$/;" e scope:enum:bpf_prog_type file: nth:15
4+
BPF_PROG_TYPE_CGROUP_SKB input.c /^ BPF_PROG_TYPE_CGROUP_SKB,$/;" e scope:enum:bpf_prog_type file: nth:8
5+
BPF_PROG_TYPE_CGROUP_SOCK input.c /^ BPF_PROG_TYPE_CGROUP_SOCK,$/;" e scope:enum:bpf_prog_type file: nth:9
6+
BPF_PROG_TYPE_CGROUP_SOCKOPT input.c /^ BPF_PROG_TYPE_CGROUP_SOCKOPT,$/;" e scope:enum:bpf_prog_type file: nth:25
7+
BPF_PROG_TYPE_CGROUP_SOCK_ADDR input.c /^ BPF_PROG_TYPE_CGROUP_SOCK_ADDR,$/;" e scope:enum:bpf_prog_type file: nth:18
8+
BPF_PROG_TYPE_CGROUP_SYSCTL input.c /^ BPF_PROG_TYPE_CGROUP_SYSCTL,$/;" e scope:enum:bpf_prog_type file: nth:23
9+
BPF_PROG_TYPE_EXT input.c /^ BPF_PROG_TYPE_EXT,$/;" e scope:enum:bpf_prog_type file: nth:28
10+
BPF_PROG_TYPE_FLOW_DISSECTOR input.c /^ BPF_PROG_TYPE_FLOW_DISSECTOR,$/;" e scope:enum:bpf_prog_type file: nth:22
11+
BPF_PROG_TYPE_KPROBE input.c /^ BPF_PROG_TYPE_KPROBE,$/;" e scope:enum:bpf_prog_type file: nth:2
12+
BPF_PROG_TYPE_LIRC_MODE2 input.c /^ BPF_PROG_TYPE_LIRC_MODE2,$/;" e scope:enum:bpf_prog_type file: nth:20
13+
BPF_PROG_TYPE_LSM input.c /^ BPF_PROG_TYPE_LSM,$/;" e scope:enum:bpf_prog_type file: nth:29
14+
BPF_PROG_TYPE_LWT_IN input.c /^ BPF_PROG_TYPE_LWT_IN,$/;" e scope:enum:bpf_prog_type file: nth:10
15+
BPF_PROG_TYPE_LWT_OUT input.c /^ BPF_PROG_TYPE_LWT_OUT,$/;" e scope:enum:bpf_prog_type file: nth:11
16+
BPF_PROG_TYPE_LWT_SEG6LOCAL input.c /^ BPF_PROG_TYPE_LWT_SEG6LOCAL,$/;" e scope:enum:bpf_prog_type file: nth:19
17+
BPF_PROG_TYPE_LWT_XMIT input.c /^ BPF_PROG_TYPE_LWT_XMIT,$/;" e scope:enum:bpf_prog_type file: nth:12
18+
BPF_PROG_TYPE_PERF_EVENT input.c /^ BPF_PROG_TYPE_PERF_EVENT,$/;" e scope:enum:bpf_prog_type file: nth:7
19+
BPF_PROG_TYPE_RAW_TRACEPOINT input.c /^ BPF_PROG_TYPE_RAW_TRACEPOINT,$/;" e scope:enum:bpf_prog_type file: nth:17
20+
BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE input.c /^ BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,$/;" e scope:enum:bpf_prog_type file: nth:24
21+
BPF_PROG_TYPE_SCHED_ACT input.c /^ BPF_PROG_TYPE_SCHED_ACT,$/;" e scope:enum:bpf_prog_type file: nth:4
22+
BPF_PROG_TYPE_SCHED_CLS input.c /^ BPF_PROG_TYPE_SCHED_CLS,$/;" e scope:enum:bpf_prog_type file: nth:3
23+
BPF_PROG_TYPE_SK_LOOKUP input.c /^ BPF_PROG_TYPE_SK_LOOKUP,$/;" e scope:enum:bpf_prog_type file: nth:30
24+
BPF_PROG_TYPE_SK_MSG input.c /^ BPF_PROG_TYPE_SK_MSG,$/;" e scope:enum:bpf_prog_type file: nth:16
25+
BPF_PROG_TYPE_SK_REUSEPORT input.c /^ BPF_PROG_TYPE_SK_REUSEPORT,$/;" e scope:enum:bpf_prog_type file: nth:21
26+
BPF_PROG_TYPE_SK_SKB input.c /^ BPF_PROG_TYPE_SK_SKB,$/;" e scope:enum:bpf_prog_type file: nth:14
27+
BPF_PROG_TYPE_SOCKET_FILTER input.c /^ BPF_PROG_TYPE_SOCKET_FILTER,$/;" e scope:enum:bpf_prog_type file: nth:1
28+
BPF_PROG_TYPE_SOCK_OPS input.c /^ BPF_PROG_TYPE_SOCK_OPS,$/;" e scope:enum:bpf_prog_type file: nth:13
29+
BPF_PROG_TYPE_STRUCT_OPS input.c /^ BPF_PROG_TYPE_STRUCT_OPS,$/;" e scope:enum:bpf_prog_type file: nth:27
30+
BPF_PROG_TYPE_SYSCALL input.c /^ BPF_PROG_TYPE_SYSCALL, \/* a program that can execute syscalls *\/$/;" e scope:enum:bpf_prog_type file: nth:31
31+
BPF_PROG_TYPE_TRACEPOINT input.c /^ BPF_PROG_TYPE_TRACEPOINT,$/;" e scope:enum:bpf_prog_type file: nth:5
32+
BPF_PROG_TYPE_TRACING input.c /^ BPF_PROG_TYPE_TRACING,$/;" e scope:enum:bpf_prog_type file: nth:26
33+
BPF_PROG_TYPE_UNSPEC input.c /^ BPF_PROG_TYPE_UNSPEC,$/;" e scope:enum:bpf_prog_type file: nth:0
34+
BPF_PROG_TYPE_XDP input.c /^ BPF_PROG_TYPE_XDP,$/;" e scope:enum:bpf_prog_type file: nth:6
35+
bpf_prog_type input.c /^enum bpf_prog_type {$/;" g file:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
3+
# Copyright: 2023 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+
if ! ( "${READTAGS}" -h | grep -q -e -F ); then
22+
skip "no formatter function in readtags"
23+
fi
24+
25+
echo '#' /GROUP/
26+
${V} ${READTAGS} -t output.tags \
27+
-Q '(eq? $scope "enum:bpf_prog_type")' \
28+
-S '(<> $nth &nth)' \
29+
-F '(list "[" $nth "] = \"" (downcase (#/BPF_PROG_TYPE_(.*)/ $name 1)) "\",\n")' \
30+
-l
31+
32+
echo '#' /group/i
33+
${V} ${READTAGS} -t output.tags \
34+
-Q '(eq? $scope "enum:bpf_prog_type")' \
35+
-S '(<> $nth &nth)' \
36+
-F '(list "[" $nth "] = \"" (#/bpf_prog_type_(.*)/i $name 1) "\",\n")' \
37+
-l
38+
39+
echo '#' /GROUP/ with a fallback value
40+
${V} ${READTAGS} -t output.tags \
41+
-Q '(eq? $scope "enum:bpf_prog_type")' \
42+
-S '(<> $nth &nth)' \
43+
-F '(list "[" $nth "] = \"S" (#/BPF_PROG_TYPE_S(.*)/ $name 1 "???") "\",\n")' \
44+
-l
45+
46+
echo '#' /GROUP/i with a fallback value
47+
${V} ${READTAGS} -t output.tags \
48+
-Q '(eq? $scope "enum:bpf_prog_type")' \
49+
-S '(<> $nth &nth)' \
50+
-F '(list "[" $nth "] = \"s" (downcase (#/bpf_prog_type_s(.*)/i $name 1 "???")) "\",\n")' \
51+
-l
52+
53+
echo '#' /GROUP = 0/
54+
${V} ${READTAGS} -t output.tags \
55+
-Q '(eq? $scope "enum:bpf_prog_type")' \
56+
-S '(<> $nth &nth)' \
57+
-F '(list "[" $nth "] = \"" (downcase (#/BPF_PROG_TYPE_(.*)/ $name 0)) "\",\n")' \
58+
-l
59+
60+
echo '#' /GROUP = empty/
61+
${V} ${READTAGS} -t output.tags \
62+
-Q '(eq? $scope "enum:bpf_prog_type")' \
63+
-S '(<> $nth &nth)' \
64+
-F '(list "[" $nth "] = \"" (downcase (#/BPF_PROG_TYPE_UNSPE(.*)()/ $name 2)) "\",\n")' \
65+
-l
66+
67+
echo '#' /GROUP = 100/
68+
${V} ${READTAGS} -t output.tags \
69+
-Q '(eq? $scope "enum:bpf_prog_type")' \
70+
-S '(<> $nth &nth)' \
71+
-F '(list "[" $nth "] = \"" (downcase (#/BPF_PROG_TYPE_UNSPE(.*)/ $name 100)) "\",\n")' \
72+
-l
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GOT ERROR in FORMATTING: wrong-regex-group: (#/BPF_PROG_TYPE_(.*)/ $name 0)
2+
GOT ERROR in FORMATTING: wrong-regex-group: (#/BPF_PROG_TYPE_UNSPE(.*)/ $name 100)
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# /GROUP/
2+
[0] = "unspec",
3+
[1] = "socket_filter",
4+
[2] = "kprobe",
5+
[3] = "sched_cls",
6+
[4] = "sched_act",
7+
[5] = "tracepoint",
8+
[6] = "xdp",
9+
[7] = "perf_event",
10+
[8] = "cgroup_skb",
11+
[9] = "cgroup_sock",
12+
[10] = "lwt_in",
13+
[11] = "lwt_out",
14+
[12] = "lwt_xmit",
15+
[13] = "sock_ops",
16+
[14] = "sk_skb",
17+
[15] = "cgroup_device",
18+
[16] = "sk_msg",
19+
[17] = "raw_tracepoint",
20+
[18] = "cgroup_sock_addr",
21+
[19] = "lwt_seg6local",
22+
[20] = "lirc_mode2",
23+
[21] = "sk_reuseport",
24+
[22] = "flow_dissector",
25+
[23] = "cgroup_sysctl",
26+
[24] = "raw_tracepoint_writable",
27+
[25] = "cgroup_sockopt",
28+
[26] = "tracing",
29+
[27] = "struct_ops",
30+
[28] = "ext",
31+
[29] = "lsm",
32+
[30] = "sk_lookup",
33+
[31] = "syscall",
34+
# /group/i
35+
[0] = "UNSPEC",
36+
[1] = "SOCKET_FILTER",
37+
[2] = "KPROBE",
38+
[3] = "SCHED_CLS",
39+
[4] = "SCHED_ACT",
40+
[5] = "TRACEPOINT",
41+
[6] = "XDP",
42+
[7] = "PERF_EVENT",
43+
[8] = "CGROUP_SKB",
44+
[9] = "CGROUP_SOCK",
45+
[10] = "LWT_IN",
46+
[11] = "LWT_OUT",
47+
[12] = "LWT_XMIT",
48+
[13] = "SOCK_OPS",
49+
[14] = "SK_SKB",
50+
[15] = "CGROUP_DEVICE",
51+
[16] = "SK_MSG",
52+
[17] = "RAW_TRACEPOINT",
53+
[18] = "CGROUP_SOCK_ADDR",
54+
[19] = "LWT_SEG6LOCAL",
55+
[20] = "LIRC_MODE2",
56+
[21] = "SK_REUSEPORT",
57+
[22] = "FLOW_DISSECTOR",
58+
[23] = "CGROUP_SYSCTL",
59+
[24] = "RAW_TRACEPOINT_WRITABLE",
60+
[25] = "CGROUP_SOCKOPT",
61+
[26] = "TRACING",
62+
[27] = "STRUCT_OPS",
63+
[28] = "EXT",
64+
[29] = "LSM",
65+
[30] = "SK_LOOKUP",
66+
[31] = "SYSCALL",
67+
# /GROUP/ with a fallback value
68+
[0] = "S???",
69+
[1] = "SOCKET_FILTER",
70+
[2] = "S???",
71+
[3] = "SCHED_CLS",
72+
[4] = "SCHED_ACT",
73+
[5] = "S???",
74+
[6] = "S???",
75+
[7] = "S???",
76+
[8] = "S???",
77+
[9] = "S???",
78+
[10] = "S???",
79+
[11] = "S???",
80+
[12] = "S???",
81+
[13] = "SOCK_OPS",
82+
[14] = "SK_SKB",
83+
[15] = "S???",
84+
[16] = "SK_MSG",
85+
[17] = "S???",
86+
[18] = "S???",
87+
[19] = "S???",
88+
[20] = "S???",
89+
[21] = "SK_REUSEPORT",
90+
[22] = "S???",
91+
[23] = "S???",
92+
[24] = "S???",
93+
[25] = "S???",
94+
[26] = "S???",
95+
[27] = "STRUCT_OPS",
96+
[28] = "S???",
97+
[29] = "S???",
98+
[30] = "SK_LOOKUP",
99+
[31] = "SYSCALL",
100+
# /GROUP/i with a fallback value
101+
[0] = "s???",
102+
[1] = "socket_filter",
103+
[2] = "s???",
104+
[3] = "sched_cls",
105+
[4] = "sched_act",
106+
[5] = "s???",
107+
[6] = "s???",
108+
[7] = "s???",
109+
[8] = "s???",
110+
[9] = "s???",
111+
[10] = "s???",
112+
[11] = "s???",
113+
[12] = "s???",
114+
[13] = "sock_ops",
115+
[14] = "sk_skb",
116+
[15] = "s???",
117+
[16] = "sk_msg",
118+
[17] = "s???",
119+
[18] = "s???",
120+
[19] = "s???",
121+
[20] = "s???",
122+
[21] = "sk_reuseport",
123+
[22] = "s???",
124+
[23] = "s???",
125+
[24] = "s???",
126+
[25] = "s???",
127+
[26] = "s???",
128+
[27] = "struct_ops",
129+
[28] = "s???",
130+
[29] = "s???",
131+
[30] = "sk_lookup",
132+
[31] = "syscall",
133+
# /GROUP = 0/
134+
# /GROUP = empty/
135+
[0] = "",
136+
[1] = "",
137+
[2] = "",
138+
[3] = "",
139+
[4] = "",
140+
[5] = "",
141+
[6] = "",
142+
[7] = "",
143+
[8] = "",
144+
[9] = "",
145+
[10] = "",
146+
[11] = "",
147+
[12] = "",
148+
[13] = "",
149+
[14] = "",
150+
[15] = "",
151+
[16] = "",
152+
[17] = "",
153+
[18] = "",
154+
[19] = "",
155+
[20] = "",
156+
[21] = "",
157+
[22] = "",
158+
[23] = "",
159+
[24] = "",
160+
[25] = "",
161+
[26] = "",
162+
[27] = "",
163+
[28] = "",
164+
[29] = "",
165+
[30] = "",
166+
[31] = "",
167+
# /GROUP = 100/

docs/man/ctags-client-tools.7.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Options for Pseudo-tags
9999
If a name is preceded by either the '+' or '-' characters, that
100100
tags's effect has been added or removed. Otherwise the names replace
101101
any current settings. All entries are included if '*' is given.
102+
All entries are removed if nothing ('') is given.
102103

103104
``--fields=+E`` (or ``--fields=+{extras}``)
104105
Attach "extras:pseudo" field to pseudo-tags.

0 commit comments

Comments
 (0)