]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/ctm/reader.lisp
Support explicitly typed Topic Names with merge and CXTM evidence
[topic-maps.git] / src / ctm / reader.lisp
index f73c242e4909fcc3cbe53c80f5222811b65813c7..99f580842933f3b338086994cdf7a3b3b07e2908 100644 (file)
@@ -98,8 +98,9 @@
        (consume parser)
        (multiple-value-bind (value reason) (topic-maps.tmdm:canonical-datetime-lexical-form (token-value token))
          (unless value (problem 'ctm-unsupported
-                         (if (eq reason :unsupported-timezone) :datetime-timezone-canonicalization :datetime-leap-second-context)
-                         (token-position token) "DateTime value normalization requires an unsupported timezone/leap context."))
+                         (if (eq reason :unsupported-bce-timezone-rollover)
+                             :datetime-bce-timezone-rollover :datetime-leap-second-context)
+                         (token-position token) "DateTime normalization is outside the supported BCE/leap-second calendar context."))
          (values value (topic-maps.tmdm:datetime-datatype))))
       (:excluded-literal
        (problem 'ctm-unsupported :occurrence-literal-datatype (token-position token)
                            "Expected ':' after the Occurrence Type."))
               (topic-maps.tmdm:add-topic-identifier topic kind iri))))))
 
+(defun read-name (parser map topic)
+  "CTM 3.11: optional Topic reference plus ':' followed by a string.
+Use the existing identity resolver; embedded Topics remain unsupported."
+  (let* ((token (look parser))
+         (typed (or (member (token-kind token) '(:identifier :iri :qname))
+                    (and (eq :punctuation (token-kind token))
+                         (find (token-value token) "=^"))))
+         (type (when typed (identity-reference parser map))))
+    (when typed
+      (unless (punctuation-p parser #\:)
+        (problem 'ctm-rejection :expected-name-type-separator
+                 (token-position (look parser)) "Expected ':' after the name type."))
+      (consume parser))
+    (let ((value (consume parser)))
+      (unless (eq :string (token-kind value))
+        (problem 'ctm-rejection :expected-name-value (token-position value)
+                 "Expected a quoted name value after '-' or the name type separator."))
+      (if typed
+          (topic-maps.tmdm:add-name topic (token-value value) :type type)
+          (topic-maps.tmdm:add-name topic (token-value value))))
+    (topic-maps.tmdm:canonical-topic topic)))
+
 (defun read-topic (parser map &optional (topic (identity-reference parser map)))
   (let ((has-tail nil))
     (loop
          (when has-tail
            (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 the implemented subset (CTM 3.11)."))
-           (unless (eq :string (token-kind value))
-             (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 topic (read-name parser map topic))
          (setf has-tail t))
         ((and has-tail (punctuation-p parser #\;))
          (consume parser)