Skip to content

Commit 63383cc

Browse files
authored
Merge pull request #3292 from masatake/choose-guest-with-aliases
lregex: consider aliases of parsers when finding a guest parser
2 parents 27d0bb2 + 6024dee commit 63383cc

File tree

8 files changed

+90
-25
lines changed

8 files changed

+90
-25
lines changed

Units/guest-in-optlib-single-line.d/args.ctags

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99

1010
--regex-single=/^DEF:([a-zA-Z0-9]+)/\1/d
1111

12-
--regex-single=/^BEGIN:([a-zA-Z0-9]+)$//{guest=\1,0end,}
13-
--regex-single=/^BEGIN$//{guest=,0end,}
14-
--regex-single=/^END:([a-zA-Z0-9]+)$//{guest=\1,,0start}
15-
--regex-single=/^END$//{guest=,,0start}
16-
17-
--regex-single=/^BEGIN_FILE:([a-zA-Z0-9.]+)$//{guest=*1,0end,}
18-
--regex-single=/^BEGIN_FILE$//{guest=,0end,}
19-
--regex-single=/^END_FILE:([a-zA-Z0-9.]+)$//{guest=*1,,0start}
20-
--regex-single=/^END_FILE$//{guest=,,0start}
21-
22-
--regex-single=/^BEGIN_C$//{guest=C,0end,}
23-
--regex-single=/^END_C$//{guest=C,,0start}
24-
25-
--regex-single=/^(BEGIN:([a-zA-Z0-9]+)<).*(>END)$//{guest=\2,1end,3start}
26-
--regex-single=/^BEGIN_FILE:([a-zA-Z0-9.]+)<(.*)>END_FILE$//{guest=*1,2start,2end}
27-
--regex-single=/^(BEGIN_C<).*(>END_C)$//{guest=C,1end,2start}
28-
12+
--regex-single=/^BEGIN:([a-zA-Z0-9]+)$//{_guest=\1,0end,}
13+
--regex-single=/^BEGIN$//{_guest=,0end,}
14+
--regex-single=/^END:([a-zA-Z0-9]+)$//{_guest=\1,,0start}
15+
--regex-single=/^END$//{_guest=,,0start}
16+
17+
--regex-single=/^BEGIN_FILE:([a-zA-Z0-9.]+)$//{_guest=*1,0end,}
18+
--regex-single=/^BEGIN_FILE$//{_guest=,0end,}
19+
--regex-single=/^END_FILE:([a-zA-Z0-9.]+)$//{_guest=*1,,0start}
20+
--regex-single=/^END_FILE$//{_guest=,,0start}
21+
22+
--regex-single=/^BEGIN_C$//{_guest=C,0end,}
23+
--regex-single=/^END_C$//{_guest=C,,0start}
24+
25+
--regex-single=/^(BEGIN:([a-zA-Z0-9]+)<).*(>END)$//{_guest=\2,1end,3start}
26+
--regex-single=/^BEGIN_FILE:([a-zA-Z0-9.]+)<(.*)>END_FILE$//{_guest=*1,2start,2end}
27+
--regex-single=/^(BEGIN_C<).*(>END_C)$//{_guest=C,1end,2start}

Units/guest-in-optlib-single-line.d/expected.tags

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ f4 input.single /^int f4 (void)$/;" f line:37 language:C typeref:typename:int
2222
f5 input.single /(defun f5 () (list))/;" f line:46 language:Lisp
2323
f6 input.single /(defun f6 () (list))/;" f line:50 language:Lisp
2424
f7 input.single /int f7 (void) { return 0; }/;" f line:54 language:C typeref:typename:int
25-
v0 input-0.single /(defvar v0 0/;" f line:1 language:Lisp
25+
v0 input-0.single /(defvar v0 0/;" v line:1 language:Lisp
2626
g0 input-1.single /^(defun g0 () (list))$/;" f line:2 language:Lisp
2727
g1 input-1.single /^int g1 (void) { return 0; }$/;" f line:6 language:C typeref:typename:int
2828
g2 input-1.single /^function g2$/;" f line:10 language:Sh
2929
EOF input-1.single /^ cat > foo.rst <<EOF$/;" h line:12 language:Sh
30-
G2 on g2 input-1.single /^G2 on g2$/;" c line:14 language:ReStructuredText
30+
G2 on g2 input-1.single /^G2 on g2$/;" H line:14 language:ReStructuredText
31+
f input-2.single /^f()$/;" f line:4 language:Sh
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ksh is an alias for Sh parser.
2+
3+
BEGIN:ksh
4+
f()
5+
{
6+
echo x
7+
}
8+
END
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
DEF:S0
2+
3+
BEGIN:lisp
4+
(defun f0 () (list))
5+
END
6+
7+
DEF:E0
8+
9+
10+
DEF:S1
11+
12+
BEGIN
13+
(defun f1 () (list))
14+
END:lisp
15+
16+
DEF:E1
17+
18+
DEF:S2
19+
20+
BEGIN_FILE:foo.cl
21+
(defun f2 () (list))
22+
END_FILE
23+
24+
DEF:E2
25+
26+
DEF:S3
27+
28+
BEGIN_FILE
29+
(defun f3 () (list))
30+
END_FILE:foo.cl
31+
32+
DEF:E3
33+
34+
DEF:S4
35+
36+
BEGIN_C
37+
int f4 (void)
38+
{
39+
return 0;
40+
}
41+
END_C
42+
43+
DEF:E4
44+
45+
DEF:S5
46+
BEGIN:lisp<(defun f5 () (list))>END
47+
DEF:E5
48+
49+
DEF:S6
50+
BEGIN_FILE:bar.cl<(defun f6 () (list))>END_FILE
51+
DEF:E6
52+
53+
DEF:S7
54+
BEGIN_C<int f7 (void) { return 0; }>END_C
55+
DEF:E7

docs/optlib.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,8 @@ For *<PARSER>*, you can specify one of the following items:
15371537
a name of a parser
15381538

15391539
If you know the guest parser you want to run before parsing
1540-
the input file, specify the name of the parser.
1540+
the input file, specify the name of the parser. Aliases of parsers
1541+
are also considered when finding a parser for the name.
15411542

15421543
An example of running C parser as a guest parser::
15431544

@@ -1548,7 +1549,8 @@ the group number of a regex pattern started from '``\``' (backslash)
15481549
If a parser name appears in an input file, write a regex pattern
15491550
to capture the name. Specify the group number where the name is
15501551
stored to the parser. In such case, use '``\``' as the prefix for
1551-
the number.
1552+
the number. Aliases of parsers are also considered when finding
1553+
a parser for the name.
15521554

15531555
Let's see an example. Git Flavor Markdown (GFM) is a language for
15541556
documentation. It provides a notation for quoting a snippet of

main/lregex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ static void pre_ptrn_flag_guest_long (const char* const s, const char* const v,
839839
}
840840
else
841841
{
842-
guest->lang.spec.lang = getNamedLanguage (v, (tmp - v));
842+
guest->lang.spec.lang = getNamedLanguageOrAlias (v, (tmp - v));
843843
if (guest->lang.spec.lang == LANG_IGNORE)
844844
{
845845
error (WARNING, "no parser found for the guest spec: %s", v);
@@ -1810,7 +1810,7 @@ static bool fillGuestRequest (const char *start,
18101810
- pmatch [guest_spec->lang.spec.patternGroup].rm_so;
18111811
if (size > 0)
18121812
{
1813-
guest_req->lang = getNamedLanguage (name, size);
1813+
guest_req->lang = getNamedLanguageOrAlias (name, size);
18141814
guest_req->lang_set = true;
18151815
}
18161816
}

optlib/systemtap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ extern parserDefinition* SystemTapParser (void)
395395
};
396396

397397
static const char *const aliases [] = {
398-
".stap",
398+
"stap",
399399
NULL
400400
};
401401

optlib/systemtap.ctags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
--langdef=SystemTap
3030
--map-SystemTap=+.stp
3131
--map-SystemTap=+.stpm
32-
--alias-SystemTap=+.stap
32+
--alias-SystemTap=+stap
3333

3434
--kinddef-SystemTap=p,probe,probe aliases
3535
--kinddef-SystemTap=f,function,functions

0 commit comments

Comments
 (0)