get_abi.pl: fix xref boundaries

There are some issues with the regex that seeks for What:
cross references: basically, it is mis-identifying the start
and the end boundaries of the regex, which causes :ref: to
be inseerted for the wrong symbols at the wrong places.

Fix it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/79a14d2518499b76931b5f29c50979987108152d.1616668017.git.mchehab+huawei@kernel.org
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
Mauro Carvalho Chehab 2021-03-25 11:38:24 +01:00 коммит произвёл Jonathan Corbet
Родитель d3e6b2235e
Коммит 50ebf8f493
1 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -281,8 +281,11 @@ sub create_labels {
# Outputs the book on ReST format # Outputs the book on ReST format
# #
# \b doesn't work well with paths. So, we need to define something else # \b doesn't work well with paths. So, we need to define something else:
my $bondary = qr { (?<![\w\/\`\{])(?=[\w\/\`\{])|(?<=[\w\/\`\{])(?![\w\/\`\{]) }x; # Boundaries are punct characters, spaces and end-of-line
my $start = qr {(^|\s|\() }x;
my $bondary = qr { ([,.:;\)\s]|\z) }x;
my $xref_match = qr { $start(\/sys\/[^,.:;\)\s]+)$bondary }x;
my $symbols = qr { ([\x01-\x08\x0e-\x1f\x21-\x2f\x3a-\x40\x7b-\xff]) }x; my $symbols = qr { ([\x01-\x08\x0e-\x1f\x21-\x2f\x3a-\x40\x7b-\xff]) }x;
sub output_rest { sub output_rest {
@ -390,16 +393,18 @@ sub output_rest {
$desc =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g; $desc =~ s,\bDocumentation/ABI/$f\b,:ref:`$xref`,g;
} }
@matches = $desc =~ m,$bondary(/sys/[^\s\.\,\;\:\*\s\`\'\(\)]+)$bondary,; # Seek for cross reference symbols like /sys/...
@matches = $desc =~ m/$xref_match/g;
foreach my $s (@matches) { foreach my $s (@matches) {
next if (!($s =~ m,/,));
if (defined($data{$s}) && defined($data{$s}->{label})) { if (defined($data{$s}) && defined($data{$s}->{label})) {
my $xref = $s; my $xref = $s;
$xref =~ s/$symbols/\\$1/g; $xref =~ s/$symbols/\\$1/g;
$xref = ":ref:`$xref <" . $data{$s}->{label} . ">`"; $xref = ":ref:`$xref <" . $data{$s}->{label} . ">`";
$desc =~ s,$bondary$s$bondary,$xref,g; $desc =~ s,$start$s$bondary,$1$xref$2,g;
} }
} }