+ (let ((position (token-position (look parser))))
+ (multiple-value-bind (kind iri) (identity-value parser)
+ (handler-case (topic-maps.tmdm:intern-topic map kind iri)
+ (topic-maps.tmdm:core-subject-error (c)
+ (problem 'ctm-rejection (topic-maps.tmdm:core-subject-error-code c) position (princ-to-string c)))))))
+
+(defun topic-reference (parser map)
+ "CTM 3.3.7: one recursive reference path for Types, Players and Scope themes."
+ (if (punctuation-p parser #\[)
+ (progn
+ (consume parser)
+ (let ((topic (topic-maps.tmdm:intern-topic map :item-identifier (wildcard-locator parser))))
+ (read-topic-tail parser map topic #\] :required t)))
+ (identity-reference parser map)))
+
+(defun read-scope (parser map)
+ "CTM 3.3.9: optional @ followed by a nonempty comma-separated Topic set.
+Use the shared Topic reference resolver, including Embedded Topics and Wildcards.
+The owning information item is not constructed until this function finishes."
+ (when (punctuation-p parser #\@)
+ (consume parser)
+ (let ((themes nil))
+ (loop
+ ;; A reifier marker where a Theme is required is malformed Scope,
+ ;; while a reifier after a complete Scope belongs to its statement.
+ (unless (parser-lookahead parser)
+ (skip-layout (parser-lexer parser))
+ (when (eql #\~ (peek-character (parser-lexer parser)))
+ (problem 'ctm-rejection :expected-scope-theme (lexer-cursor (parser-lexer parser))
+ "Expected a Theme, not a reifier marker.")))
+ (let ((token (look parser)))
+ (unless (topic-reference-start-p token)
+ (problem 'ctm-rejection :expected-scope-theme (token-position token)
+ "Expected a Topic reference after '@' or the scope comma."))
+ (push (topic-reference parser map) themes))
+ (if (punctuation-p parser #\,) (consume parser) (return (nreverse themes)))))))