+(defun read-prolog (parser)
+ "CTM 3.5: one initial encoding header, then one optional version 1.0."
+ (when (and (eq :directive (token-kind (look parser)))
+ (string= "encoding" (token-value (look parser))))
+ (let ((token (consume parser)))
+ (unless (zerop (token-position token))
+ (problem 'ctm-rejection :misplaced-encoding (token-position token)
+ "Encoding declaration must be the first characters of the CTM stream."))
+ (multiple-value-bind (name end position)
+ (ctm-encoding-name *source-text* (token-position token) :character)
+ (unless (ctm-encoding-kind name)
+ (problem 'ctm-unsupported :unsupported-encoding position "Only UTF-8 and ISO-8859-5 CTM input are implemented."))
+ (setf (lexer-cursor (parser-lexer parser)) end))))
+ (when (and (eq :directive (token-kind (look parser)))
+ (string= "version" (token-value (look parser))))
+ (consume parser)
+ (let ((lexer (parser-lexer parser)))
+ (skip-layout lexer)
+ (let ((start (lexer-cursor lexer)))
+ ;; Match the fixed terminal before the numeric-literal lexer. A Topic
+ ;; can follow immediately; extra numeric spelling is not version 1.0.
+ (unless (and (ctm-ascii-prefix-p *source-text* start "1.0")
+ (let ((end (+ start 3)))
+ (not (and (< end (length *source-text*))
+ (find (char *source-text* end) "0123456789.+-")))))
+ (problem 'ctm-rejection :invalid-version start "The only CTM version is the exact spelling 1.0."))
+ (setf (lexer-cursor lexer) (+ start 3))))))
+