;; 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-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)
- "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)))
"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)