An output policy for the three commands, and @cond as a true special form

A snapshot of the development tree.  The substantial changes since the last one:

COMMAND OUTPUT POLICY.  The three commands display text in exactly three cases,
and each owns a stream: LOGGING under "-v" greater than 0 and an ERROR before
termination go to STDERR; OUTPUT THE USER ASKED FOR goes to STDOUT.  For ktext
that output is a document, so "ktext doc.kt -d | ..." is now safe -- logging
used to share the stream and land inside the document.  A bare command prints
its usage and succeeds rather than failing.  Colour is emitted only to a
terminal, per stream, and NO_COLOR is honoured.

"-v 1" reports every decision whose outcome you could not have read off your own
input: the klammerset that was loaded and from which file, a font's directory, a
":files" name's file, how "-o" was expanded.  Higher levels are the trace.

The commands no longer warn and continue: an anomaly is an error, described with
its location.  Two exceptions remain, each for a stated reason -- a condition
that is expected and temporary by design, and a judgment that is a heuristic
rather than exact.

@cond IS NOW A TRUE SPECIAL FORM, resolved at APPLICATION time rather than when
the file is read.  Two consequences for a writer:

  * a state variable reaches the predicate.  "@@@state Flag :value true @@@
    @cond *Flag* | T | F @" renders "T"; it used to see the literal "*Flag*" and
    silently take the false branch.  The document now behaves like a klammer
    body, whose arguments are bound before its conditionals are decided.
  * nothing in a discarded branch happens -- it is not read, not evaluated, not
    expanded.  An @eval in the branch not taken used to run anyway.

Its predicate relation is total and strict: true, True, 1; false, False, 0, and
empty; anything else is an error at the @cond rather than silently false.

@eval REACHING OUTSIDE.  ":shell" and ":haskell" now keep the command's standard
error out of the document (it appears under "-v 1") and treat a nonzero exit as
an error naming what the command reported.  A command that exits nonzero on
purpose -- "grep" finding no match -- says so with "|| true".

KLAMMER SETS.  Several combine: "--klammersets a b c" loads all three in the
order given, sharing one namespace, with the definition modes deciding
collisions.  "none" means none and may not be combined with other symbols.  A
klammerset with symbol X is declared in a file X/X.k, which is what lets two
sets require the same third set without loading it twice.

TESTS.  Four new suites: the kdiag command's interface, the @eval primitive's
contract with the outside world, and verbosity at both tiers.  Three suites
that could not run on macOS at all now do.

Assembled from dev commit 6c8ee6c22fca.
This commit is contained in:
2026-08-16 01:37:59 +02:00
parent 59c1599bc9
commit 240cff4278
84 changed files with 2523 additions and 494 deletions

View File

@@ -0,0 +1,12 @@
# Engine-tier fixture: the base of the klammerset COMBINING tests. It owns the
# target and the ".k" declaration that the two "house" sets override, so each
# of them can require it and neither has to be loaded first on the command
# line -- which is what makes command-line ORDER the only thing under test.
#
# The definitions sit in a :files entry rather than in this declaring file,
# which is NOT a style choice: the already-loaded guard skips a repeated
# declaration's :files, but the declaring file itself is read again every time
# a :requires names it. With the "@@@target fx" written here, requiring
# "base" from two sets reads it twice and the second read is a fatal "Target
# fx is already defined". See case 21c, which pins that.
@@@klammerset base | Base set for combining tests :date 2026-08-15 :files defs.k @@@

View File

@@ -0,0 +1,4 @@
# The base set's definitions. See base.k for why they are not in it.
@@@target fx | Combining fixture target @@@
@@who.k : Which klammerset supplied this definition @@
@@who.fx :: BASE @@

View File

@@ -1,11 +0,0 @@
# Engine-tier fixture: a klammerset with metadata, a dependency, an ordered
# file list (klammers.k uses the target defined in base.k), and a trailing
# definition that must load after the files (program order).
@@@klammerset kit | Engine-test klammerset
:name Klammerset Integration Test
:author Klammertext tests
:date 2026-07-30
:requires util.k
:files base.k / klammers.k
@@@
@@after : AFTER @@

View File

@@ -1 +0,0 @@
@@@klammerset kit | Duplicate declaration of kit :files dup_only.k @@@

View File

@@ -0,0 +1,9 @@
# One of two independent sets of house overrides. Both require "base" (loaded
# once, whichever asks first) and both override the same klammer with ":::", so
# the one written LAST on the command line is the one that wins. Its own
# klammer @a_only shows that the sets share one flat namespace rather than
# each keeping its klammers to itself.
@@@klammerset housea | House overrides A :requires base :date 2026-08-15 @@@
@@who.fx ::: HOUSE-A @@
@@a_only.k : A klammer only set A defines @@
@@a_only.fx :: ONLY-A @@

View File

@@ -0,0 +1,5 @@
# The mirror image of housea; see the comment there.
@@@klammerset houseb | House overrides B :requires base :date 2026-08-15 @@@
@@who.fx ::: HOUSE-B @@
@@b_only.k : A klammer only set B defines @@
@@b_only.fx :: ONLY-B @@

18
tst/klammerset/kit/kit.k Normal file
View File

@@ -0,0 +1,18 @@
# Engine-tier fixture: a klammerset with metadata, a dependency, an ordered
# file list (klammers.k uses the target defined in base.k), and a trailing
# definition that must load after the files (program order).
#
# Laid out as <symbol>/<symbol>.k, which is what a symbol names: since
# 2026-08-14 the command line takes symbols only, so a klammerset that
# cannot be named by one cannot be loaded at all. ":requires util" is a
# SYMBOL, resolved on the search path (this directory is not util's parent,
# so it is found at stage 2, KLAMMERTEXT_KLAMMERSETS); ":files" entries are
# filenames, resolved against this file's directory.
@@@klammerset kit | Engine-test klammerset
:name Klammerset Integration Test
:author Klammertext tests
:date 2026-07-30
:requires util
:files base.k / klammers.k
@@@
@@after : AFTER @@

View File

@@ -0,0 +1,2 @@
# Requires selfdef; paired with needs_b to make the diamond of case 21c.
@@@klammerset needs_a | Requires selfdef :requires selfdef :date 2026-08-15 @@@

View File

@@ -0,0 +1,2 @@
# Requires selfdef; paired with needs_a to make the diamond of case 21c.
@@@klammerset needs_b | Requires selfdef :requires selfdef :date 2026-08-15 @@@

View File

@@ -0,0 +1,8 @@
# A klammerset whose declaring file carries its own definitions (the
# documented alternative to a :text option: program order plays that role).
# Requiring it from two different sets reads this file twice, and the second
# read of the @@@target is fatal. Case 21c pins that defect; when it is
# fixed, that case fails and must be rewritten.
@@@klammerset selfdef | Definitions in the declaring file :date 2026-08-15 @@@
@@@target fy | Self-defining fixture target @@@
@@sd.fy : SELFDEF @@

6
tst/klammerset/sp/sp.k Normal file
View File

@@ -0,0 +1,6 @@
# The target and @greet come from kit, required by symbol; this set adds
# only the file whose name contains a space (standalone "/" separator).
@@@klammerset sp | Spacey filename in the list
:requires kit
:files space name.k
@@@

View File

@@ -1 +0,0 @@
@@@klammerset sp | Spacey filename in the list :files base.k / space name.k @@@

View File

@@ -0,0 +1,6 @@
# A declaration of the symbol "kit" from a file that is NOT kit/kit.k.
# Since 2026-08-15 that is an ERROR: a klammerset that can be named is
# identified by where it is, so a symbol names one file and one file declares
# one symbol. This fixture exists to prove the error; it formerly proved that
# such a duplicate was tolerated and skipped.
@@@klammerset kit | Duplicate declaration of kit :files dup_only.k @@@

View File

@@ -0,0 +1,3 @@
# Requires "kit" twice over: once by symbol, once through dup.k, which
# re-declares it. Loading "wrap" is therefore an error now -- see dup.k.
@@@klammerset wrap | Wrapper requiring kit twice :requires kit / dup.k @@@

View File

@@ -1 +0,0 @@
@@@klammerset wrap | Wrapper requiring kit twice :requires decl.k / decl2.k @@@