- (if (eq :directive (token-kind (look parser)))
- (read-prefix-directive parser)
- (let* ((embedded (punctuation-p parser #\[)) (topic (topic-reference parser map)))
- (if (punctuation-p parser #\()
- (read-association parser map topic)
- (if embedded
- (problem 'ctm-rejection :embedded-topic-at-top-level (token-position (look parser))
- "An Embedded Topic at top level must be an Association Type, not a standalone declaration.")
- (read-topic-tail parser map topic #\.)))))))
- (values map (parser-wildcard-counter parser)))))
+ (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)))