comparison scripts/mk-doc.pl @ 28512:88f11d96d64c stable

* mk-doc.pl: Find classdef docstrings inside classdef code block.
author John W. Eaton <jwe@octave.org>
date Fri, 29 May 2020 08:50:29 -0400
parents bd51beb6205e
children bbbe4dcc7200
comparison
equal deleted inserted replaced
28511:59dfd9ed72a3 28512:88f11d96d64c
99 ################################################################################ 99 ################################################################################
100 sub gethelp 100 sub gethelp
101 { 101 {
102 my $fcn = shift; 102 my $fcn = shift;
103 my $fname = shift; 103 my $fname = shift;
104 my $have_cdef_file = 0;
105 my $found_code = 0;
106
104 open (my $fh, "<", $fname) or return; 107 open (my $fh, "<", $fname) or return;
105 108
106 my @help_txt; 109 my @help_txt;
107 while (my $line = <$fh>) 110 while (my $line = <$fh>)
108 { 111 {
109 next if $line =~ m/^[\s#%]*$/; # skip empty lines 112 next if $line =~ m/^[\s#%]*$/; # skip empty lines
110 last if $line !~ m/^\s*(#|%)/; # out of here once code starts 113
114 if ($line !~ m/^\s*(#|%)/)
115 {
116 if (! $found_code)
117 {
118 $found_code = 1;
119 $have_cdef_file = ! $have_cdef_file && $line =~ m/^\s*classdef/;
120 }
121
122 next if $have_cdef_file;
123 last;
124 }
111 125
112 my $reading_block = sub {defined ($line = <$fh>) && $line !~ m/^\s*$/}; 126 my $reading_block = sub {defined ($line = <$fh>) && $line !~ m/^\s*$/};
113 127
114 ## Skip this block 128 ## Skip this block
115 if ($line =~ /(Copyright|Author)/) 129 if ($line =~ /(Copyright|Author)/)
120 { 134 {
121 $line =~ s/^\s*(%|#)+ ?//; 135 $line =~ s/^\s*(%|#)+ ?//;
122 push (@help_txt, $line); 136 push (@help_txt, $line);
123 } while (&$reading_block ()); 137 } while (&$reading_block ());
124 last; 138 last;
139
140 ## Instead of jumping out here unconditionally, should we
141 ## attempt to extract multiple help comment blocks in a
142 ## classdef file by searching forward for the next line that
143 ## begins with "function" and then saving the first comment
144 ## block after that? We will need a way to recognize the
145 ## method name to print the docstring separator line. Maybe
146 ## we should just be using Octave's parser and help system for
147 ## this job?
148
149 ## if ($have_cdef_file)
150 ## {
151 ## while (my $line = <$fh>)
152 ## {
153 ## last if $line =~ /^\s*function/;
154 ## }
155 ## }
156 ## else
157 ## {
158 ## last;
159 ## }
125 } 160 }
126 } 161 }
127 162
128 close ($fh); 163 close ($fh);
129 return @help_txt; 164 return @help_txt;