From bfb011ac1acf1021bba619f14450cffe3b912daf Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 23 Oct 2026 12:47:01 +0100 Subject: [PATCH] Doc: a comment before const, type or var heads its group; Doc man writes the modules only, raz-lib(3)'s head and tail (and date) are doc/raz-lib.head and .tail, put around it by make --- diff --git a/Makefile b/Makefile index 010be27..f0553ef 100644 --- a/Makefile +++ b/Makefile @@ -95,15 +95,17 @@ @rloc -c src/*.raz # raz-lib(3), the library's manual page, made by tools/Doc.raz from -# its sources, in the order of doc/raz-lib.md +# its sources, in the order of doc/raz-lib.md, between the page's own +# head (with its date) and tail LIBDOC = Rt Mem Heap Arena Lock Thread.linux-x86_64 Out Sys.linux-x86_64 \ Str Bytes.x86_64 Buf Fmt List Map Vec Sort Math Files Opt Width Rand Check Prop C man: build/raz-lib.3 -build/raz-lib.3: raz tools/Doc.raz tools/Scan.raz lib/*.raz | build +build/raz-lib.3: raz tools/Doc.raz tools/Scan.raz lib/*.raz doc/raz-lib.head doc/raz-lib.tail | build ./raz -Werror -o build/Doc tools/Doc.raz - build/Doc man $(LIBDOC:%=lib/%.raz) > $@ + build/Doc man $(LIBDOC:%=lib/%.raz) > build/raz-lib.modules + cat doc/raz-lib.head build/raz-lib.modules doc/raz-lib.tail > $@ # the two volumes of the report as PDFs, by pandoc and Chromium; not # part of check, as CI has neither diff --git a/doc/raz-lib.head b/doc/raz-lib.head new file mode 100644 index 0000000..76a4163 --- /dev/null +++ b/doc/raz-lib.head @@ -0,0 +1,20 @@ +.\" raz-lib(3) - the library; made by tools/Doc.raz from lib/ +.Dd October 22, 2026 +.Dt RAZ-LIB 3 +.Os +.Sh NAME +.Nm raz-lib +.Nd the library of the raz language +.Sh DESCRIPTION +The modules a raz program imports from +.Pa lib/ , +beside the compiler, each as its source gives it: the module's own +comment, then every declaration it exports, as it is written, with +the comment just before it. +A module's +.Ic main , +where it has one, is its test, and is left out. +.Pp +The report's second volume says what the library promises, and which +of its modules every target has. +.Sh MODULES diff --git a/doc/raz-lib.tail b/doc/raz-lib.tail new file mode 100644 index 0000000..601b0d4 --- /dev/null +++ b/doc/raz-lib.tail @@ -0,0 +1,9 @@ +.Sh SEE ALSO +.Xr raz 1 , +.Xr raz 7 , +.Xr raz-tutorial 7 ; +the report, +.Pa doc/raz.md , +and its second volume, +.Pa doc/raz-lib.md , +in raz's sources. diff --git a/test/check.sh b/test/check.sh index bb72973..e55aa94 100755 --- a/test/check.sh +++ b/test/check.sh @@ -169,7 +169,8 @@ if ./raz --version | grep -qF "report $want"; then pass=$((pass + 1)) else echo "FAIL raz --version: not report $want"; fail=$((fail + 1)); fi -# tools/Doc.raz: on every library module, and as test/doc expects +# tools/Doc.raz: on every library module, and as test/doc expects (X.expect +# for Doc, X.man for Doc man) if ./raz -Werror -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then for f in lib/*.raz; do if ! $out/Doc $f > $out/doc.out; then echo "FAIL Doc $f"; fail=$((fail + 1)); fi @@ -178,8 +179,15 @@ name=$(basename $f .expect) m=lib/$name.raz [ -f $m ] || m=lib/$name.linux-x86_64.raz + [ -f $m ] || m=test/doc/$name.raz if $out/Doc $m | cmp -s - $f; then pass=$((pass + 1)) else echo "FAIL Doc $m: output differs"; fail=$((fail + 1)); fi + done + # Doc man, for the modules that have a test/doc/X.man + for f in test/doc/*.man; do + m=test/doc/$(basename $f .man).raz + if $out/Doc man $m | cmp -s - $f; then pass=$((pass + 1)) + else echo "FAIL Doc man $m: output differs"; fail=$((fail + 1)); fi done # the report's examples that are whole modules: each compiles, and diff --git a/test/doc/Group.expect b/test/doc/Group.expect new file mode 100644 index 0000000..43ea1be --- /dev/null +++ b/test/doc/Group.expect @@ -0,0 +1,21 @@ +module Group; + Group: a comment before const, type or var heads its group. + Doc's test of it. + + Colours, one bit each. + +const Red* = 1; (* the first *) + +const Green* = 2; + +const Blue* = 4; (* the last *) + + Where it is. + +type Point* = record x*, y*: INT; end; (* one place *) + + A comment that stands alone. + +var count*: INT; + +proc main*; diff --git a/test/doc/Group.man b/test/doc/Group.man new file mode 100644 index 0000000..49a51bb --- /dev/null +++ b/test/doc/Group.man @@ -0,0 +1,28 @@ +.Ss Group +.Bd -literal +module Group; +.Ed +.Bd -filled -offset indent -compact +Group: a comment before const, type or var heads its group. +Doc's test of it. +.Ed +.Bd -filled -offset indent -compact +Colours, one bit each. +.Ed +.Bd -literal +const Red* = 1; (* the first *) +const Green* = 2; +const Blue* = 4; (* the last *) +.Ed +.Bd -filled -offset indent -compact +Where it is. +.Ed +.Bd -literal +type Point* = record x*, y*: INT; end; (* one place *) +.Ed +.Bd -filled -offset indent -compact +A comment that stands alone. +.Ed +.Bd -literal +var count*: INT; +.Ed diff --git a/test/doc/Group.raz b/test/doc/Group.raz new file mode 100644 index 0000000..da7dca5 --- /dev/null +++ b/test/doc/Group.raz @@ -0,0 +1,28 @@ +(* Group: a comment before const, type or var heads its group. + Doc's test of it. *) +module Group; + +(* Colours, one bit each. *) +const + Red* = 1; (* the first *) + Green* = 2; + Blue* = 4; (* the last *) + +(* A group of nothing exported, so no heading. *) +const hidden = 0; + +(* Where it is. *) +type + Point* = record x*, y*: INT; end; (* one place *) + +(* A comment that stands alone. *) + +var + count*: INT; + +proc main*; +begin + count := Red + hidden; +end; + +end Group. diff --git a/tools/Doc.raz b/tools/Doc.raz index f316034..20fdfb0 100644 --- a/tools/Doc.raz +++ b/tools/Doc.raz @@ -6,11 +6,18 @@ before it. Doc man Module.raz ... - prints the same of each module, as the manual page raz-lib(3), in - mdoc: the module's name a heading, each declaration a literal - display, each comment filled text, indented, but for its lines - indented further, which are code. + prints the same of each module, in mdoc, for a library's manual page: + the module's name a heading, each declaration a literal display, + each comment filled text, indented, but for its lines indented + further, which are code. It writes the modules only; the page's + head (its date, name and description, up to .Sh MODULES) and tail + are files of the library's own, put around it by its Makefile. + A comment on lines of its own just before const, type or var heads + that group: it is written once, before the group's declarations, + as a module's own comment is, and each declaration keeps the comment + just before it. + Doc examples report.md dir Doc examples page.7 dir writes each example of the report, or of a manual page, that is a @@ -19,8 +26,6 @@ module Doc; import Out, Rt, Str, Buf, Heap, Scan, Files; -const Date = "October 22, 2026"; (* raz-lib(3)'s, when the library last changed *) - var sc: Scan.Scanner; (* the text being read, at the current symbol *) src: []U8; @@ -28,6 +33,7 @@ man: BOOL; (* writing mdoc *) atStart: BOOL; (* emit is at the start of a line *) shown: BOOL; (* a literal display of mdoc's is open *) + groupStart, groupEnd: INT; (* the comment that heads the group being read, not yet written, or -1 *) (* On to the next symbol that isn't a comment, keeping where the last comment that starts a line was: one after code on its line belongs @@ -211,12 +217,24 @@ if man then control(".Ed"); end; end; +(* The comment that heads a group of constants, types or variables, + written once, before the group's first exported declaration. *) +proc heading; +begin + if not man then Out.ln; + else close; + end; + comment(groupStart, groupEnd); + groupStart := -1; +end; + (* One declaration, from its first token, the comment before it kept. In mdoc a module's test, its main, is left out, and declarations with no comment share a display. *) proc declaration(prefix: []U8; exported: BOOL; start, ds, de, stop: INT); begin if not exported then return; end; + if (groupStart >= 0) and (LEN(prefix) > 0) then heading; end; if not man then Out.ln; elsif Str.hasPrefix(src[start..stop], "proc main*") then return; elsif not shown then control(".Bd -literal"); shown := true; @@ -279,6 +297,7 @@ var word: []U8; start, ds, de, stop: INT; exp: BOOL; begin word := text(); + groupStart := docStart; groupEnd := docEnd; next; while (sc.kind = Scan.word) and not reserved() do start := sc.start; ds := docStart; de := docEnd; @@ -288,6 +307,7 @@ declaration(word, exp, start, ds, de, stop); next; end; + groupStart := -1; end; proc external; @@ -304,6 +324,7 @@ proc document(path: []U8); var b: Buf.Buf; start, ds, de: INT; begin + groupStart := -1; Buf.init(b, Heap.heap); if not Files.read(path, b) then Rt.stop("Doc: can't read the file"); end; src := Buf.bytes(b); @@ -420,44 +441,18 @@ end; end; -(* raz-lib(3): the modules named from argument 2 on, under a head and - above a tail of the page's own. *) +(* The modules named from argument 2 on, as mdoc: what goes between a + manual page's .Sh MODULES and its next heading. The page's head and + tail, and its date, belong to the page, not to this tool: raz's + Makefile puts doc/raz-lib.head and doc/raz-lib.tail around it. *) proc page; var i: INT; begin man := true; atStart := true; - control(".\\\" raz-lib(3) - the library; made by tools/Doc.raz from lib/"); - Out.str(".Dd "); Out.str(Date); emit(10); - control(".Dt RAZ-LIB 3"); - control(".Os"); - control(".Sh NAME"); - control(".Nm raz-lib"); - control(".Nd the library of the raz language"); - control(".Sh DESCRIPTION"); - control("The modules a raz program imports from"); - control(".Pa lib/ ,"); - control("beside the compiler, each as its source gives it: the module's own"); - control("comment, then every declaration it exports, as it is written, with"); - control("the comment just before it."); - control("A module's"); - control(".Ic main ,"); - control("where it has one, is its test, and is left out."); - control(".Pp"); - control("The report's second volume says what the library promises, and which"); - control("of its modules every target has."); - control(".Sh MODULES"); + groupStart := -1; for i := 2 to ARGC() - 1 do document(Files.arg(i)); end; close; - control(".Sh SEE ALSO"); - control(".Xr raz 1 ,"); - control(".Xr raz 7 ,"); - control(".Xr raz-tutorial 7 ;"); - control("the report,"); - control(".Pa doc/raz.md ,"); - control("and its second volume,"); - control(".Pa doc/raz-lib.md ,"); - control("in raz's sources."); end; proc main*;