]> dreyeck.freedombox.rocks Git - topic-maps.git/commitdiff
fix(ctm): distinguish malformed names from unsupported typed names
authorrgb <ralf.barkow@me.com>
Wed, 14 Oct 2026 05:22:09 +0000 (07:22 +0200)
committerrgb <ralf.barkow@me.com>
Wed, 14 Oct 2026 05:22:09 +0000 (07:22 +0200)
docs/slice-1a-validation.md [new file with mode: 0644]
src/ctm/lexer.lisp
src/ctm/reader.lisp
tests/ctm-identity.lisp

diff --git a/docs/slice-1a-validation.md b/docs/slice-1a-validation.md
new file mode 100644 (file)
index 0000000..fce1c02
--- /dev/null
@@ -0,0 +1,67 @@
+# Slice 1a: name error classification
+
+Base: `1805023b5c5690f224a2bb556af46a4af7c36687`, observed clean on
+`codex/ctm-slice-1`. This correction does not begin Slice 2.
+
+CTM 3.11 requires a string after the optional name type and colon. CTM 3.3.1
+allows whitespace between tokens. Both `a - type:"Name".` and
+`a - type: "Name".` are valid typed-name syntax, whose deserialization remains
+unsupported. References: ISO/IEC 13250-6:2010,
+<https://www.isotopicmaps.org/ctm/ctm.html>, clauses 3.3.1, 3.3.4 and 3.11.
+
+The lexer forms a QName only when a local part immediately follows its colon;
+otherwise the colon remains a separate token. The reader checks for a name
+string, or a type followed by colon and string, before classifying typed names
+as unsupported. It does not resolve name types or add typed-name semantics.
+
+Before/after observations were reproduced in fresh SBCL processes, loading
+source from the base Git commit and the corrected checkout respectively:
+
+| Source | Before | After | Character offset / line / column |
+| --- | --- | --- | --- |
+| `a - .` | CTM-UNSUPPORTED / :TYPED-NAME | CTM-REJECTION / :EXPECTED-NAME-VALUE | 4 / 1 / 5 |
+| `a -` | CTM-UNSUPPORTED / :TYPED-NAME | CTM-REJECTION / :EXPECTED-NAME-VALUE | 3 / 1 / 4 |
+| `a - type:"Name".` | CTM-UNSUPPORTED / :TYPED-NAME | CTM-UNSUPPORTED / :TYPED-NAME | 4 / 1 / 5 |
+| `a - type: "Name".` | CTM-REJECTION / :INVALID-QNAME | CTM-UNSUPPORTED / :TYPED-NAME | 4 / 1 / 5 |
+
+The regression suite asserts exact classes, codes, offsets, line/column,
+character position units, source labels and meaningful diagnostics for all
+four inputs. Further checks cover a missing type separator, a missing typed
+name value, and newline/comment layout. All original 100 semantic check labels
+remain; 23 checks were added.
+
+## Validation executed
+
+Both complete runs passed: **123 semantic checks, 54 foundation checks and 2
+Python integrity tests**, zero failures. Each used a fresh SBCL process with
+OS-denied networking. The second used a relocated copy excluding `.git` and
+Python caches. Exact commands:
+
+```sh
+# Working directory: /Users/rgb/workspace/topic-maps
+/usr/bin/sandbox-exec -p '(version 1)(allow default)(deny network*)' /usr/bin/env PYTHONDONTWRITEBYTECODE=1 SBCL=/nix/store/hlsiblxpxr1hax3dw9x8znd6zy097ddj-sbcl-2.5.4/bin/sbcl TOPIC_MAPS_REPORT=/private/tmp/ctm-slice-1a-2.5.4.json scripts/test.sh
+
+# Working directory: /private/tmp/ctm-slice-1a-relocated-yfcaz7au/checkout
+/usr/bin/sandbox-exec -p '(version 1)(allow default)(deny network*)' /usr/bin/env PYTHONDONTWRITEBYTECODE=1 SBCL=/nix/store/y96nx8571mpdvjd40krkdim2av0in972-sbcl-2.4.10/bin/sbcl TOPIC_MAPS_REPORT=/private/tmp/ctm-slice-1a-2.4.10.json /private/tmp/ctm-slice-1a-relocated-yfcaz7au/checkout/scripts/test.sh
+
+cmp /private/tmp/ctm-slice-1a-2.5.4.json /private/tmp/ctm-slice-1a-2.4.10.json
+cmp /private/tmp/ctm-slice-1a-2.5.4.json.semantics.json /private/tmp/ctm-slice-1a-2.4.10.json.semantics.json
+```
+
+All commands exited zero. Both report pairs are byte-identical. The five
+positive semantic case records, including actual object properties and
+parent/type reference observations, are unchanged from the committed Slice 1
+semantic report. The selected frozen-baseline property checker also passes.
+
+Imported statuses remain PASS 1, FAIL 0, UNSUPPORTED 0, NOT-RUN 272. All five
+positive CXTM-EQUAL contracts remain NOT-RUN; only the specific undefined-prefix
+rejection is PASS. No canonical output was produced.
+
+All 2,006 pinned corpus files still match their original sizes and hashes;
+inputs, baselines and pin files are unchanged. No TMDM source was changed.
+
+No remaining discrepancy was observed for the four requested inputs. Existing
+Slice 1 boundaries remain, including unsupported typed-name deserialization,
+full IRI validation and general merging, and absent CXTM canonicalization.
+The pinned corpus targets draft 2010-03-31 and does not establish full ISO
+conformity. No HyperDoc integration, server, SSH or deployment was performed.
index f53654bfa0c248ec3b941c81a1cfdffea3d849c7..6331cde1dc9449229f02e7ab1c6d55115be15a69 100644 (file)
                              (find (char text (1- (lexer-cursor lexer))) ";.)"))
                   do (decf (lexer-cursor lexer)))
             (make-token :kind :iri :value (subseq text start (lexer-cursor lexer)) :position start))
                              (find (char text (1- (lexer-cursor lexer))) ";.)"))
                   do (decf (lexer-cursor lexer)))
             (make-token :kind :iri :value (subseq text start (lexer-cursor lexer)) :position start))
-           ((and (eql #\: (peek-character lexer)) (eql #\" (peek-character lexer 1)))
-            ;; A typed name has a separate colon before its quoted string.
-            (make-token :kind :identifier :value head :position start))
-           ((eql #\: (peek-character lexer))
+           ((and (eql #\: (peek-character lexer))
+                 (or (name-start-p (peek-character lexer 1))
+                     (and (peek-character lexer 1)
+                          (find (peek-character lexer 1) "0123456789"))))
+            ;; Only an immediate local part forms a QName (CTM 3.3.4).
+            ;; Otherwise ':' remains a separate token, including name types
+            ;; followed by a string with or without intervening layout.
             (take-character lexer)
             (take-character lexer)
-            (unless (or (name-start-p (peek-character lexer))
-                        (and (peek-character lexer) (find (peek-character lexer) "0123456789")))
-              (problem 'ctm-rejection :invalid-qname start "QName requires a local part."))
             (scan-name lexer)
             (make-token :kind :qname :value (subseq text start (lexer-cursor lexer)) :position start))
            (t (make-token :kind :identifier :value head :position start)))))
             (scan-name lexer)
             (make-token :kind :qname :value (subseq text start (lexer-cursor lexer)) :position start))
            (t (make-token :kind :identifier :value head :position start)))))
index 687a7ffe58790475775d831b171c32bd12728ed4..cdf5d5ae61114f2e192ed176824ab02aeef2ac23 100644 (file)
            (problem 'ctm-rejection :expected-separator (token-position (look parser)) "Topic-tail statements need a semicolon separator."))
          (consume parser)
          (let ((value (consume parser)))
            (problem 'ctm-rejection :expected-separator (token-position (look parser)) "Topic-tail statements need a semicolon separator."))
          (consume parser)
          (let ((value (consume parser)))
+           (when (member (token-kind value) '(:identifier :iri :qname))
+             ;; Recognize the typed-name syntax, without resolving its type
+             ;; or creating information items for unsupported name semantics.
+             (unless (punctuation-p parser #\:)
+               (problem 'ctm-rejection :expected-name-type-separator
+                        (token-position (look parser)) "Expected ':' after the name type."))
+             (consume parser)
+             (let ((literal (consume parser)))
+               (unless (eq :string (token-kind literal))
+                 (problem 'ctm-rejection :expected-name-value (token-position literal)
+                          "Expected a quoted name value after the name type separator.")))
+             (problem 'ctm-unsupported :typed-name (token-position value)
+                      "Typed names are outside Slice 1 (CTM 3.11)."))
            (unless (eq :string (token-kind value))
            (unless (eq :string (token-kind value))
-             (problem 'ctm-unsupported :typed-name (token-position value) "Only untyped quoted names are implemented."))
+             (problem 'ctm-rejection :expected-name-value (token-position value)
+                      "Expected a quoted name value after '-'."))
            (topic-maps.tmdm:add-default-name topic (token-value value)))
          (setf has-tail t))
         ((and has-tail (punctuation-p parser #\;))
            (topic-maps.tmdm:add-default-name topic (token-value value)))
          (setf has-tail t))
         ((and has-tail (punctuation-p parser #\;))
index cf7b3f8615d759dd001c565df8ac31b2fc5febbb..2d8b98c72e0eb3da6346c01213c8aa9d057bfb71 100644 (file)
              (ctm-rejection () nil)
              (file-error () t)))
     (check "typed-name-explicitly-unsupported" (unsupported-p "a - fullname:\"Name\"."))
              (ctm-rejection () nil)
              (file-error () t)))
     (check "typed-name-explicitly-unsupported" (unsupported-p "a - fullname:\"Name\"."))
+    ;; CTM 3.11 requires a string, even when the optional type is unsupported.
+    ;; CTM 3.3.1 permits layout between the type separator and that string.
+    (dolist (fixture '(("a - ." ctm-rejection :expected-name-value 4)
+                       ("a -" ctm-rejection :expected-name-value 3)
+                       ("a - type:\"Name\"." ctm-unsupported :typed-name 4)
+                       ("a - type: \"Name\"." ctm-unsupported :typed-name 4)))
+      (destructuring-bind (text class code position) fixture
+        (let ((condition (handler-case (progn (read-text text) nil)
+                           (ctm-error (e) e))))
+          (check (concatenate 'string "name-classification-class:" text)
+                 (and condition (eq class (type-of condition))))
+          (check (concatenate 'string "name-classification-code:" text)
+                 (eq code (error-code condition)))
+          (check (concatenate 'string "name-classification-position:" text)
+                 (= position (error-position condition)))
+          (check (concatenate 'string "name-classification-source:" text)
+                 (and (= 1 (error-line condition))
+                      (= (1+ position) (error-column condition))
+                      (eq :character (topic-maps.ctm:error-position-unit condition))
+                      (string= "independent-fixture" (topic-maps.ctm:error-source condition))))
+          (check (concatenate 'string "name-classification-diagnostic:" text)
+                 (search (if (eq class 'ctm-rejection) "quoted name value" "Typed names")
+                         (princ-to-string condition))))))
+    ;; A type-like token alone must not turn a malformed name into UNSUPPORTED.
+    (check "name-type-without-separator-is-rejected"
+           (eq :expected-name-type-separator (error-code (rejection "a - type \"Name\"."))))
+    (check "typed-name-without-value-is-rejected"
+           (eq :expected-name-value (error-code (rejection "a - type:."))))
+    (check "typed-name-layout-remains-unsupported"
+           (unsupported-p (format nil "a - type:~%#( layout )# \"Name\".")))
     (check "additional-identity-explicitly-unsupported" (unsupported-p "a <https://example.invalid/alias>."))
     (dolist (ending (list (string #\Return) (format nil "~C~C" #\Return #\Newline)))
       (let ((condition (rejection (concatenate 'string "a." ending "ex:fake."))))
     (check "additional-identity-explicitly-unsupported" (unsupported-p "a <https://example.invalid/alias>."))
     (dolist (ending (list (string #\Return) (format nil "~C~C" #\Return #\Newline)))
       (let ((condition (rejection (concatenate 'string "a." ending "ex:fake."))))