Skip to content

Commit 6024dee

Browse files
committed
lregex: consider aliases of parsers when finding a guest parser
Suggested by @Pierre-Andre in #3288. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 5b13006 commit 6024dee

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ g1 input-1.single /^int g1 (void) { return 0; }$/;" f line:6 language:C typeref:
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
3030
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

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
}

0 commit comments

Comments
 (0)