+(defun require-wildcard-environment (iri counter)
+ (handler-case (require-document-iri iri)
+ (ctm-rejection () (problem 'ctm-rejection :invalid-wildcard-iri 0 "Wildcard IRI must be an absolute, fragment-free IRI.")))
+ (unless (and (integerp counter) (>= counter 0))
+ (problem 'ctm-rejection :invalid-wildcard-counter 0 "Wildcard counter must be a non-negative integer.")))
+
+(defun wildcard-locator (parser &optional name)
+ "CTM 3.3.8: cache locators, not Lisp object handles; identity uses INTERN-TOPIC."
+ (or (and name (gethash name (parser-wildcards parser)))
+ (let ((iri (format nil "~A#$__~D~@[.~A~]" (parser-wildcard-iri parser)
+ (incf (parser-wildcard-counter parser)) name)))
+ (when name (setf (gethash name (parser-wildcards parser)) iri)) iri)))
+
+(defun topic-reference-start-p (token)
+ (or (member (token-kind token) '(:identifier :iri :qname :wildcard))
+ (and (eq :punctuation (token-kind token)) (find (token-value token) "=^["))))
+