From fb60afd548d679d83fd8ec76bc5ff384c1e23e5f Mon Sep 17 00:00:00 2001 From: rgb Date: Wed, 14 Oct 2026 07:22:09 +0200 Subject: [PATCH] fix(ctm): distinguish malformed names from unsupported typed names --- docs/slice-1a-validation.md | 67 +++++++++++++++++++++++++++++++++++++ src/ctm/lexer.lisp | 14 ++++---- src/ctm/reader.lisp | 16 ++++++++- tests/ctm-identity.lisp | 30 +++++++++++++++++ 4 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 docs/slice-1a-validation.md diff --git a/docs/slice-1a-validation.md b/docs/slice-1a-validation.md new file mode 100644 index 0000000..fce1c02 --- /dev/null +++ b/docs/slice-1a-validation.md @@ -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, +, 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. diff --git a/src/ctm/lexer.lisp b/src/ctm/lexer.lisp index f53654b..6331cde 100644 --- a/src/ctm/lexer.lisp +++ b/src/ctm/lexer.lisp @@ -109,14 +109,14 @@ (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) - (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))))) diff --git a/src/ctm/reader.lisp b/src/ctm/reader.lisp index 687a7ff..cdf5d5a 100644 --- a/src/ctm/reader.lisp +++ b/src/ctm/reader.lisp @@ -50,8 +50,22 @@ (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)) - (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 #\;)) diff --git a/tests/ctm-identity.lisp b/tests/ctm-identity.lisp index cf7b3f8..2d8b98c 100644 --- a/tests/ctm-identity.lisp +++ b/tests/ctm-identity.lisp @@ -202,6 +202,36 @@ (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 .")) (dolist (ending (list (string #\Return) (format nil "~C~C" #\Return #\Newline))) (let ((condition (rejection (concatenate 'string "a." ending "ex:fake.")))) -- 2.39.5