]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/ctm/lexer.lisp
feat(ctm): validate prologs and register three Slice 20C contracts
[topic-maps.git] / src / ctm / lexer.lisp
index b4e56abe693eb25a9d4d8a0712eee862bdf64cce..100aca4d0e49f03421db124379fadb1237cf9b2f 100644 (file)
@@ -171,14 +171,16 @@ A dot followed by a digit can belong to a decimal; a terminal dot stays punctuat
       ((char= c #\%)
        ;; Production [71] has a literal terminal followed by an identifier;
        ;; unlike Role separators it does not require intervening whitespace.
-       (if (starts-with "%prefix" (subseq text start))
-           (progn (setf (lexer-cursor lexer) (+ start 7))
-                  (make-token :kind :directive :value "prefix" :position start))
-           (progn
-             (scan-name lexer)
-             (problem 'ctm-unsupported :unsupported-directive start
-                      (format nil "Directive %~A is outside the implemented subset."
-                              (subseq text (1+ start) (lexer-cursor lexer)))))))
+       (let ((name (find-if (lambda (name) (starts-with (concatenate 'string "%" name) (subseq text start)))
+                            '("prefix" "mergemap" "include" "encoding" "version"))))
+         (if name
+             (progn (setf (lexer-cursor lexer) (+ start 1 (length name)))
+                    (make-token :kind :directive :value name :position start))
+             (progn
+               (scan-name lexer)
+               (problem 'ctm-rejection :unknown-directive start
+                        (format nil "Unknown CTM directive %~A."
+                                (subseq text (1+ start) (lexer-cursor lexer))))))))
       ((char= c #\$)
        (unless (name-start-p (peek-character lexer))
          (problem 'ctm-rejection :invalid-variable start "A variable requires an identifier."))