1#!/usr/bin/env perl 2# 3# Parse .rst files and generate tags. 4 5use strict; 6use warnings; 7 8my $id = '[a-zA-Z_0-9]'; 9my @tags; 10for my $file (@ARGV) { 11 open my $fh, '<', $file 12 or die "Cannot open $file for reading: $!"; 13 while (<$fh>) { 14 chomp; 15 if (m/^(\.\. function:: )(.+)/) { 16 my ($pfx, $val) = ($1, $2); 17 if ($val =~ m/($id+) \(/o) { 18 push @tags, "$1\t$file\t/^$pfx$val/\n"; 19 } else { 20 warn "unknown pattern in $file:$.: $_\n"; 21 } 22 } elsif (m/^(\s*\.\. (?:type|member):: )(.+)/) { 23 my ($pfx, $val) = ($1, $2); 24 if ($val =~ m/\(\*([^\)]+)\)/) { 25 push @tags, "$1\t$file\t/^$pfx$val/\n"; 26 } elsif ($val =~ m/($id+)(?::\d+)?\s*$/o) { 27 push @tags, "$1\t$file\t/^$pfx$val/\n"; 28 } else { 29 warn "unknown pattern in $file:$.: $_\n"; 30 } 31 } elsif (m/^(\s*\.\. var:: )(.+)/) { 32 my ($pfx, $val) = ($1, $2); 33 if ($val =~ m/($id+)(?:\[[^\]]*\])?\s*$/o) { 34 push @tags, "$1\t$file\t/^$pfx$val/\n"; 35 } else { 36 warn "unknown pattern in $file:$.: $_\n"; 37 } 38 } elsif (m/^(\s*\.\. macro::\s+)(\S+)\s*$/) { 39 push @tags, "$2\t$file\t/^$1$2/\n"; 40 } elsif (m/^\s*\.\. (?:toctree|image|highlight|code-block)::/) { 41 # Skip 42 } elsif (m/^\s*\.\.\s*\S+::/) { 43 warn "unknown pattern in $file:$.: $_\n"; 44 } 45 } 46} 47 48print sort @tags; 49