]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/ctm/reader.lisp
Support DateTime occurrences and expose normative baseline conflicts
[topic-maps.git] / src / ctm / reader.lisp
index 7433b1d9258c7b2d3d520586c443a578b0c53663..f73c242e4909fcc3cbe53c80f5222811b65813c7 100644 (file)
        ;; canonically; qualified quoted strings retain their lexical value.
        (values (topic-maps.tmdm:canonical-integer-lexical-form (token-value token))
                (topic-maps.tmdm:integer-datatype)))
+      (:decimal
+       (consume parser)
+       ;; Same value-representation policy as bare integers; token spelling is
+       ;; retained by the lexer, qualified strings remain lexical model data.
+       (values (topic-maps.tmdm:canonical-decimal-lexical-form (token-value token))
+               (topic-maps.tmdm:decimal-datatype)))
+      (:date
+       (consume parser)
+       (values (topic-maps.tmdm:canonical-date-lexical-form (token-value token)) (topic-maps.tmdm:date-datatype)))
+      (:datetime
+       (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."))
+         (values value (topic-maps.tmdm:datetime-datatype))))
       (:excluded-literal
        (problem 'ctm-unsupported :occurrence-literal-datatype (token-position token)
-                "Decimal/date/dateTime and the separate CTM '*' literal are outside this slice."))
+                "The separate CTM '*' literal is outside this slice."))
       (:string
        (consume parser)
        (if (punctuation-p parser #\^)
                         (not (topic-maps.tmdm:integer-lexical-p (token-value token))))
                (problem 'ctm-rejection :invalid-integer-value (token-position token)
                         "Quoted value is not an xsd:integer lexical form."))
+             (when (and (string= datatype (topic-maps.tmdm:decimal-datatype))
+                        (not (topic-maps.tmdm:decimal-lexical-p (token-value token))))
+               (problem 'ctm-rejection :invalid-decimal-value (token-position token)
+                        "Quoted value is not an xsd:decimal lexical form."))
+             (when (and (string= datatype (topic-maps.tmdm:date-datatype))
+                        (not (topic-maps.tmdm:date-lexical-p (token-value token))))
+               (problem 'ctm-rejection :invalid-date-value (token-position token)
+                        "Quoted value is not a valid XSD 1.0 date lexical form."))
+             (when (and (string= datatype (topic-maps.tmdm:datetime-datatype))
+                        (not (topic-maps.tmdm:datetime-lexical-p (token-value token))))
+               (problem 'ctm-rejection :invalid-datetime-value (token-position token)
+                        "Quoted value is not a valid XSD 1.0 dateTime."))
              ;; TMDM 4.4 requires absolute anyURI content; quoted content is
              ;; lexical data, never an IRI reference to resolve against the document.
              (when (and (string= datatype (topic-maps.tmdm:iri-datatype))
            (values (token-value token) (topic-maps.tmdm:string-datatype))))
       ((:iri :qname) (values (literal-iri-reference parser) (topic-maps.tmdm:iri-datatype)))
       (otherwise (problem 'ctm-rejection :expected-occurrence-value (token-position token)
-                          "Expected an integer, quoted string or IRI-form Occurrence value.")))))
+                          "Expected an integer, decimal, date, dateTime, quoted string or IRI-form Occurrence value.")))))
 
 (defun read-identity-tail (parser map topic)
   (let ((start (look parser)))