raz / commit bfb011ac

commit
bfb011ac1acf1021bba619f14450cffe3b912daf
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
947d70f3
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

patch · log

8 files changed, +152 -41

Makefile (history) modified +5 -3

@@ -95,15 +95,17 @@
9595 @rloc -c src/*.raz
9696
9797 # raz-lib(3), the library's manual page, made by tools/Doc.raz from
98-# its sources, in the order of doc/raz-lib.md
98+# its sources, in the order of doc/raz-lib.md, between the page's own
99+# head (with its date) and tail
99100 LIBDOC = Rt Mem Heap Arena Lock Thread.linux-x86_64 Out Sys.linux-x86_64 \
100101 Str Bytes.x86_64 Buf Fmt List Map Vec Sort Math Files Opt Width Rand Check Prop C
101102
102103 man: build/raz-lib.3
103104
104-build/raz-lib.3: raz tools/Doc.raz tools/Scan.raz lib/*.raz | build
105+build/raz-lib.3: raz tools/Doc.raz tools/Scan.raz lib/*.raz doc/raz-lib.head doc/raz-lib.tail | build
105106 ./raz -Werror -o build/Doc tools/Doc.raz
106- build/Doc man $(LIBDOC:%=lib/%.raz) > $@
107+ build/Doc man $(LIBDOC:%=lib/%.raz) > build/raz-lib.modules
108+ cat doc/raz-lib.head build/raz-lib.modules doc/raz-lib.tail > $@
107109
108110 # the two volumes of the report as PDFs, by pandoc and Chromium; not
109111 # part of check, as CI has neither

doc/raz-lib.head (history) added +20 -0

@@ -0,0 +1,20 @@
1+.\" raz-lib(3) - the library; made by tools/Doc.raz from lib/
2+.Dd October 22, 2026
3+.Dt RAZ-LIB 3
4+.Os
5+.Sh NAME
6+.Nm raz-lib
7+.Nd the library of the raz language
8+.Sh DESCRIPTION
9+The modules a raz program imports from
10+.Pa lib/ ,
11+beside the compiler, each as its source gives it: the module's own
12+comment, then every declaration it exports, as it is written, with
13+the comment just before it.
14+A module's
15+.Ic main ,
16+where it has one, is its test, and is left out.
17+.Pp
18+The report's second volume says what the library promises, and which
19+of its modules every target has.
20+.Sh MODULES

doc/raz-lib.tail (history) added +9 -0

@@ -0,0 +1,9 @@
1+.Sh SEE ALSO
2+.Xr raz 1 ,
3+.Xr raz 7 ,
4+.Xr raz-tutorial 7 ;
5+the report,
6+.Pa doc/raz.md ,
7+and its second volume,
8+.Pa doc/raz-lib.md ,
9+in raz's sources.

test/check.sh (history) modified +9 -1

@@ -169,7 +169,8 @@
169169 if ./raz --version | grep -qF "report $want"; then pass=$((pass + 1))
170170 else echo "FAIL raz --version: not report $want"; fail=$((fail + 1)); fi
171171
172-# tools/Doc.raz: on every library module, and as test/doc expects
172+# tools/Doc.raz: on every library module, and as test/doc expects (X.expect
173+# for Doc, X.man for Doc man)
173174 if ./raz -Werror -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then
174175 for f in lib/*.raz; do
175176 if ! $out/Doc $f > $out/doc.out; then echo "FAIL Doc $f"; fail=$((fail + 1)); fi
@@ -178,8 +179,15 @@
178179 name=$(basename $f .expect)
179180 m=lib/$name.raz
180181 [ -f $m ] || m=lib/$name.linux-x86_64.raz
182+ [ -f $m ] || m=test/doc/$name.raz
181183 if $out/Doc $m | cmp -s - $f; then pass=$((pass + 1))
182184 else echo "FAIL Doc $m: output differs"; fail=$((fail + 1)); fi
185+ done
186+ # Doc man, for the modules that have a test/doc/X.man
187+ for f in test/doc/*.man; do
188+ m=test/doc/$(basename $f .man).raz
189+ if $out/Doc man $m | cmp -s - $f; then pass=$((pass + 1))
190+ else echo "FAIL Doc man $m: output differs"; fail=$((fail + 1)); fi
183191 done
184192
185193 # the report's examples that are whole modules: each compiles, and

test/doc/Group.expect (history) added +21 -0

@@ -0,0 +1,21 @@
1+module Group;
2+ Group: a comment before const, type or var heads its group.
3+ Doc's test of it.
4+
5+ Colours, one bit each.
6+
7+const Red* = 1; (* the first *)
8+
9+const Green* = 2;
10+
11+const Blue* = 4; (* the last *)
12+
13+ Where it is.
14+
15+type Point* = record x*, y*: INT; end; (* one place *)
16+
17+ A comment that stands alone.
18+
19+var count*: INT;
20+
21+proc main*;

test/doc/Group.man (history) added +28 -0

@@ -0,0 +1,28 @@
1+.Ss Group
2+.Bd -literal
3+module Group;
4+.Ed
5+.Bd -filled -offset indent -compact
6+Group: a comment before const, type or var heads its group.
7+Doc's test of it.
8+.Ed
9+.Bd -filled -offset indent -compact
10+Colours, one bit each.
11+.Ed
12+.Bd -literal
13+const Red* = 1; (* the first *)
14+const Green* = 2;
15+const Blue* = 4; (* the last *)
16+.Ed
17+.Bd -filled -offset indent -compact
18+Where it is.
19+.Ed
20+.Bd -literal
21+type Point* = record x*, y*: INT; end; (* one place *)
22+.Ed
23+.Bd -filled -offset indent -compact
24+A comment that stands alone.
25+.Ed
26+.Bd -literal
27+var count*: INT;
28+.Ed

test/doc/Group.raz (history) added +28 -0

@@ -0,0 +1,28 @@
1+(* Group: a comment before const, type or var heads its group.
2+ Doc's test of it. *)
3+module Group;
4+
5+(* Colours, one bit each. *)
6+const
7+ Red* = 1; (* the first *)
8+ Green* = 2;
9+ Blue* = 4; (* the last *)
10+
11+(* A group of nothing exported, so no heading. *)
12+const hidden = 0;
13+
14+(* Where it is. *)
15+type
16+ Point* = record x*, y*: INT; end; (* one place *)
17+
18+(* A comment that stands alone. *)
19+
20+var
21+ count*: INT;
22+
23+proc main*;
24+begin
25+ count := Red + hidden;
26+end;
27+
28+end Group.

tools/Doc.raz (history) modified +32 -37

@@ -6,11 +6,18 @@
66 before it.
77
88 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.
1315
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+
1421 Doc examples report.md dir
1522 Doc examples page.7 dir
1623 writes each example of the report, or of a manual page, that is a
@@ -19,8 +26,6 @@
1926 module Doc;
2027 import Out, Rt, Str, Buf, Heap, Scan, Files;
2128
22-const Date = "October 22, 2026"; (* raz-lib(3)'s, when the library last changed *)
23-
2429 var
2530 sc: Scan.Scanner; (* the text being read, at the current symbol *)
2631 src: []U8;
@@ -28,6 +33,7 @@
2833 man: BOOL; (* writing mdoc *)
2934 atStart: BOOL; (* emit is at the start of a line *)
3035 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 *)
3137
3238 (* On to the next symbol that isn't a comment, keeping where the last
3339 comment that starts a line was: one after code on its line belongs
@@ -211,12 +217,24 @@
211217 if man then control(".Ed"); end;
212218 end;
213219
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+
214231 (* One declaration, from its first token, the comment before it kept.
215232 In mdoc a module's test, its main, is left out, and declarations
216233 with no comment share a display. *)
217234 proc declaration(prefix: []U8; exported: BOOL; start, ds, de, stop: INT);
218235 begin
219236 if not exported then return; end;
237+ if (groupStart >= 0) and (LEN(prefix) > 0) then heading; end;
220238 if not man then Out.ln;
221239 elsif Str.hasPrefix(src[start..stop], "proc main*") then return;
222240 elsif not shown then control(".Bd -literal"); shown := true;
@@ -279,6 +297,7 @@
279297 var word: []U8; start, ds, de, stop: INT; exp: BOOL;
280298 begin
281299 word := text();
300+ groupStart := docStart; groupEnd := docEnd;
282301 next;
283302 while (sc.kind = Scan.word) and not reserved() do
284303 start := sc.start; ds := docStart; de := docEnd;
@@ -288,6 +307,7 @@
288307 declaration(word, exp, start, ds, de, stop);
289308 next;
290309 end;
310+ groupStart := -1;
291311 end;
292312
293313 proc external;
@@ -304,6 +324,7 @@
304324 proc document(path: []U8);
305325 var b: Buf.Buf; start, ds, de: INT;
306326 begin
327+ groupStart := -1;
307328 Buf.init(b, Heap.heap);
308329 if not Files.read(path, b) then Rt.stop("Doc: can't read the file"); end;
309330 src := Buf.bytes(b);
@@ -420,44 +441,18 @@
420441 end;
421442 end;
422443
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. *)
425448 proc page;
426449 var i: INT;
427450 begin
428451 man := true;
429452 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;
450454 for i := 2 to ARGC() - 1 do document(Files.arg(i)); end;
451455 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.");
461456 end;
462457
463458 proc main*;