+(defun excluded-literal-p (text)
+ (string= text "*"))
+
+(defun read-number-token (lexer start)
+ "One token path for Integer, Decimal, Date and DateTime; * remains excluded.
+A dot followed by a digit can belong to a decimal; a terminal dot stays punctuation."
+ (setf (lexer-cursor lexer) start)
+ (loop for c = (peek-character lexer)
+ while (and c (not (whitespace-p c)) (not (find c ";@~()#^<>\"[]"))
+ (or (not (char= c #\.))
+ (and (peek-character lexer 1) (find (peek-character lexer 1) "0123456789"))))
+ do (take-character lexer))
+ (let ((value (subseq (lexer-text lexer) start (lexer-cursor lexer))))
+ (cond ((topic-maps.tmdm:integer-lexical-p value)
+ (make-token :kind :integer :value value :position start))
+ ((and (find #\. value) (topic-maps.tmdm:decimal-lexical-p value))
+ (make-token :kind :decimal :value value :position start))
+ ((position #\T value)
+ (multiple-value-bind (parts reason) (topic-maps.tmdm::datetime-parts value)
+ (unless parts (problem 'ctm-rejection reason start "Expected a valid XSD 1.0 dateTime."))
+ (make-token :kind :datetime :value value :position start)))
+ ((excluded-literal-p value) (make-token :kind :excluded-literal :value value :position start))
+ ((position #\- value :start (if (and (plusp (length value)) (find (char value 0) "+-")) 1 0))
+ (multiple-value-bind (a date-end end reason) (topic-maps.tmdm::date-lexical-bounds value)
+ (unless (and a (= date-end end))
+ (problem 'ctm-rejection (or reason :invalid-date-syntax) start
+ "Expected a valid timezone-free XSD 1.0 date: nonzero year, valid month/day and no leading plus or extended-year zeroes."))
+ (make-token :kind :date :value value :position start)))
+ (t (problem 'ctm-rejection :invalid-occurrence-literal start "Malformed numeric/date literal.")))))
+