]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/ctm/lexer.lisp
feat(ctm): read associations and roles with merge-safe topic references
[topic-maps.git] / src / ctm / lexer.lisp
index f53654bfa0c248ec3b941c81a1cfdffea3d849c7..116b55c6d4c8abf7d24a3e2a9f0f1624e13a45d2 100644 (file)
                  (eql #\/ (peek-character lexer 1)) (eql #\/ (peek-character lexer 2)))
             (incf (lexer-cursor lexer) 3)
             (loop while (and (peek-character lexer) (not (whitespace-p (peek-character lexer)))
-                             (not (find (peek-character lexer) "<>\"{}|^`\\[](")))
+                             (not (find (peek-character lexer) "<>\"{}|^`\\[]()")))
                   do (take-character lexer))
             (loop while (and (> (lexer-cursor lexer) start)
                              (find (char text (1- (lexer-cursor lexer))) ";.)"))
                   do (decf (lexer-cursor lexer)))
             (make-token :kind :iri :value (subseq text start (lexer-cursor lexer)) :position start))
-           ((and (eql #\: (peek-character lexer)) (eql #\" (peek-character lexer 1)))
-            ;; A typed name has a separate colon before its quoted string.
-            (make-token :kind :identifier :value head :position start))
-           ((eql #\: (peek-character lexer))
+           ((and (eql #\: (peek-character lexer))
+                 (or (name-start-p (peek-character lexer 1))
+                     (and (peek-character lexer 1)
+                          (find (peek-character lexer 1) "0123456789"))))
+            ;; Only an immediate local part forms a QName (CTM 3.3.4).
+            ;; Otherwise ':' remains a separate token, including name types
+            ;; followed by a string with or without intervening layout.
             (take-character lexer)
-            (unless (or (name-start-p (peek-character lexer))
-                        (and (peek-character lexer) (find (peek-character lexer) "0123456789")))
-              (problem 'ctm-rejection :invalid-qname start "QName requires a local part."))
             (scan-name lexer)
             (make-token :kind :qname :value (subseq text start (lexer-cursor lexer)) :position start))
            (t (make-token :kind :identifier :value head :position start)))))
-      ((find c ".;-=^:") (make-token :kind :punctuation :value c :position start))
-      ((find c "%?[$@~()")
+      ((find c ".;-=^:(),") (make-token :kind :punctuation :value c :position start))
+      ((find c "%?[$@~")
        (problem 'ctm-unsupported :unsupported-construct start
-                (format nil "Construct starting with ~S is outside Slice 1." c)))
+                (format nil "Construct starting with ~S is outside the implemented subset." c)))
       (t (problem 'ctm-rejection :unexpected-character start (format nil "Unexpected character ~S." c))))))