| | @@ -6,11 +6,18 @@ |
| 6 | 6 | before it. |
| 7 | 7 | |
| 8 | 8 | Doc man Module.raz ... |
| 9 | | - prints the same of each module, as the manual page raz-lib(3), in |
| 10 | | - mdoc: the module's name a heading, each declaration a literal |
| 11 | | - display, each comment filled text, indented, but for its lines |
| 12 | | - indented further, which are code. |
| 9 | + prints the same of each module, in mdoc, for a library's manual page: |
| 10 | + the module's name a heading, each declaration a literal display, |
| 11 | + each comment filled text, indented, but for its lines indented |
| 12 | + further, which are code. It writes the modules only; the page's |
| 13 | + head (its date, name and description, up to .Sh MODULES) and tail |
| 14 | + are files of the library's own, put around it by its Makefile. |
| 13 | 15 | |
| 16 | + A comment on lines of its own just before const, type or var heads |
| 17 | + that group: it is written once, before the group's declarations, |
| 18 | + as a module's own comment is, and each declaration keeps the comment |
| 19 | + just before it. |
| 20 | + |
| 14 | 21 | Doc examples report.md dir |
| 15 | 22 | Doc examples page.7 dir |
| 16 | 23 | writes each example of the report, or of a manual page, that is a |
| | @@ -19,8 +26,6 @@ |
| 19 | 26 | module Doc; |
| 20 | 27 | import Out, Rt, Str, Buf, Heap, Scan, Files; |
| 21 | 28 | |
| 22 | | -const Date = "October 22, 2026"; (* raz-lib(3)'s, when the library last changed *) |
| 23 | | - |
| 24 | 29 | var |
| 25 | 30 | sc: Scan.Scanner; (* the text being read, at the current symbol *) |
| 26 | 31 | src: []U8; |
| | @@ -28,6 +33,7 @@ |
| 28 | 33 | man: BOOL; (* writing mdoc *) |
| 29 | 34 | atStart: BOOL; (* emit is at the start of a line *) |
| 30 | 35 | shown: BOOL; (* a literal display of mdoc's is open *) |
| 36 | + groupStart, groupEnd: INT; (* the comment that heads the group being read, not yet written, or -1 *) |
| 31 | 37 | |
| 32 | 38 | (* On to the next symbol that isn't a comment, keeping where the last |
| 33 | 39 | comment that starts a line was: one after code on its line belongs |
| | @@ -211,12 +217,24 @@ |
| 211 | 217 | if man then control(".Ed"); end; |
| 212 | 218 | end; |
| 213 | 219 | |
| 220 | +(* The comment that heads a group of constants, types or variables, |
| 221 | + written once, before the group's first exported declaration. *) |
| 222 | +proc heading; |
| 223 | +begin |
| 224 | + if not man then Out.ln; |
| 225 | + else close; |
| 226 | + end; |
| 227 | + comment(groupStart, groupEnd); |
| 228 | + groupStart := -1; |
| 229 | +end; |
| 230 | + |
| 214 | 231 | (* One declaration, from its first token, the comment before it kept. |
| 215 | 232 | In mdoc a module's test, its main, is left out, and declarations |
| 216 | 233 | with no comment share a display. *) |
| 217 | 234 | proc declaration(prefix: []U8; exported: BOOL; start, ds, de, stop: INT); |
| 218 | 235 | begin |
| 219 | 236 | if not exported then return; end; |
| 237 | + if (groupStart >= 0) and (LEN(prefix) > 0) then heading; end; |
| 220 | 238 | if not man then Out.ln; |
| 221 | 239 | elsif Str.hasPrefix(src[start..stop], "proc main*") then return; |
| 222 | 240 | elsif not shown then control(".Bd -literal"); shown := true; |
| | @@ -279,6 +297,7 @@ |
| 279 | 297 | var word: []U8; start, ds, de, stop: INT; exp: BOOL; |
| 280 | 298 | begin |
| 281 | 299 | word := text(); |
| 300 | + groupStart := docStart; groupEnd := docEnd; |
| 282 | 301 | next; |
| 283 | 302 | while (sc.kind = Scan.word) and not reserved() do |
| 284 | 303 | start := sc.start; ds := docStart; de := docEnd; |
| | @@ -288,6 +307,7 @@ |
| 288 | 307 | declaration(word, exp, start, ds, de, stop); |
| 289 | 308 | next; |
| 290 | 309 | end; |
| 310 | + groupStart := -1; |
| 291 | 311 | end; |
| 292 | 312 | |
| 293 | 313 | proc external; |
| | @@ -304,6 +324,7 @@ |
| 304 | 324 | proc document(path: []U8); |
| 305 | 325 | var b: Buf.Buf; start, ds, de: INT; |
| 306 | 326 | begin |
| 327 | + groupStart := -1; |
| 307 | 328 | Buf.init(b, Heap.heap); |
| 308 | 329 | if not Files.read(path, b) then Rt.stop("Doc: can't read the file"); end; |
| 309 | 330 | src := Buf.bytes(b); |
| | @@ -420,44 +441,18 @@ |
| 420 | 441 | end; |
| 421 | 442 | end; |
| 422 | 443 | |
| 423 | | -(* raz-lib(3): the modules named from argument 2 on, under a head and |
| 424 | | - above a tail of the page's own. *) |
| 444 | +(* The modules named from argument 2 on, as mdoc: what goes between a |
| 445 | + manual page's .Sh MODULES and its next heading. The page's head and |
| 446 | + tail, and its date, belong to the page, not to this tool: raz's |
| 447 | + Makefile puts doc/raz-lib.head and doc/raz-lib.tail around it. *) |
| 425 | 448 | proc page; |
| 426 | 449 | var i: INT; |
| 427 | 450 | begin |
| 428 | 451 | man := true; |
| 429 | 452 | atStart := true; |
| 430 | | - control(".\\\" raz-lib(3) - the library; made by tools/Doc.raz from lib/"); |
| 431 | | - Out.str(".Dd "); Out.str(Date); emit(10); |
| 432 | | - control(".Dt RAZ-LIB 3"); |
| 433 | | - control(".Os"); |
| 434 | | - control(".Sh NAME"); |
| 435 | | - control(".Nm raz-lib"); |
| 436 | | - control(".Nd the library of the raz language"); |
| 437 | | - control(".Sh DESCRIPTION"); |
| 438 | | - control("The modules a raz program imports from"); |
| 439 | | - control(".Pa lib/ ,"); |
| 440 | | - control("beside the compiler, each as its source gives it: the module's own"); |
| 441 | | - control("comment, then every declaration it exports, as it is written, with"); |
| 442 | | - control("the comment just before it."); |
| 443 | | - control("A module's"); |
| 444 | | - control(".Ic main ,"); |
| 445 | | - control("where it has one, is its test, and is left out."); |
| 446 | | - control(".Pp"); |
| 447 | | - control("The report's second volume says what the library promises, and which"); |
| 448 | | - control("of its modules every target has."); |
| 449 | | - control(".Sh MODULES"); |
| 453 | + groupStart := -1; |
| 450 | 454 | for i := 2 to ARGC() - 1 do document(Files.arg(i)); end; |
| 451 | 455 | close; |
| 452 | | - control(".Sh SEE ALSO"); |
| 453 | | - control(".Xr raz 1 ,"); |
| 454 | | - control(".Xr raz 7 ,"); |
| 455 | | - control(".Xr raz-tutorial 7 ;"); |
| 456 | | - control("the report,"); |
| 457 | | - control(".Pa doc/raz.md ,"); |
| 458 | | - control("and its second volume,"); |
| 459 | | - control(".Pa doc/raz-lib.md ,"); |
| 460 | | - control("in raz's sources."); |
| 461 | 456 | end; |
| 462 | 457 | |
| 463 | 458 | proc main*; |