- (loop until (eq :eof (token-kind (look parser))) do
- (if (eq :directive (token-kind (look parser)))
- (read-prefix-directive parser)
- (let ((topic (identity-reference parser map)))
- (if (punctuation-p parser #\()
- (read-association parser map topic)
- (read-topic parser map topic)))))
- map)))
+ (setf (parser-resource-resolver parser) resource-resolver (parser-max-resource-depth parser) max-resource-depth)
+ (handler-bind ((topic-maps.tmdm:variant-error
+ (lambda (c) (problem 'ctm-rejection (topic-maps.tmdm:variant-error-code c)
+ (lexer-cursor (parser-lexer parser)) (princ-to-string c))))
+ (topic-maps.tmdm:reification-error
+ (lambda (c) (problem 'ctm-rejection (topic-maps.tmdm:reification-error-code c)
+ (lexer-cursor (parser-lexer parser)) (princ-to-string c))))
+ (topic-maps.tmdm:core-subject-error
+ (lambda (c) (problem 'ctm-rejection (topic-maps.tmdm:core-subject-error-code c)
+ (lexer-cursor (parser-lexer parser)) (princ-to-string c)))))
+ (read-prolog parser)
+ (loop while (eq :directive (token-kind (look parser))) do (read-directive parser map))
+ (multiple-value-bind (r position) (read-reifier parser map) (attach-reifier map r position))
+ (loop until (eq :eof (token-kind (look parser))) do
+ (when (punctuation-p parser #\~)
+ (problem 'ctm-rejection :topic-map-reifier-position (token-position (look parser))
+ "Topic Map Reifier must precede all body declarations."))
+ (cond ((eq :directive (token-kind (look parser))) (read-directive parser map))
+ ((identifier-p (look parser) "def") (read-template-definition parser))
+ (t (read-statement parser map)))))
+ (values map (parser-wildcard-counter parser) parser))))
+
+(defun deserialize-string (text &key document-iri source-name (wildcard-iri document-iri) (wildcard-counter 0)
+ resource-resolver (max-resource-depth 32))
+ "Deserialize CTM using explicit Document IRI and optional controlled resources.
+Return the Topic Map and final Wildcard Counter. Includes import Templates and
+Topic aliases; Mergemap imports Map content only. No implicit I/O is performed.
+The resolver receives :PURPOSE (:INCLUDE or :MERGEMAP), :FROM-DOCUMENT-IRI and
+:NOTATION (NIL for Include). Source keys are diagnostic, never identity bases."
+ (multiple-value-bind (map counter)
+ (deserialize-context text :document-iri document-iri :source-name source-name
+ :wildcard-iri wildcard-iri :wildcard-counter wildcard-counter
+ :resource-resolver resource-resolver :max-resource-depth max-resource-depth)
+ (values map counter)))