]> dreyeck.freedombox.rocks Git - topic-maps.git/blobdiff - src/ctm/lexer.lisp
Add source-preserving TMDM Map content import with atomic preflight
[topic-maps.git] / src / ctm / lexer.lisp
index fd6bc9c8c1e14b694963334b31fc3331ff4c9905..b4e56abe693eb25a9d4d8a0712eee862bdf64cce 100644 (file)
@@ -1,6 +1,6 @@
 (in-package #:topic-maps.ctm)
 
-(defstruct token kind value (position 0))
+(defstruct token kind value (position 0) end)
 (defstruct (lexer (:constructor make-lexer (text))) text (cursor 0))
 
 (defun peek-character (lexer &optional (delta 0))
@@ -167,7 +167,7 @@ A dot followed by a digit can belong to a decimal; a terminal dot stays punctuat
                 (loop while (name-part-p (peek-character lexer)) do (take-character 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 ".;-=^:(),@[]~") (make-token :kind :punctuation :value c :position start))
       ((char= c #\%)
        ;; Production [71] has a literal terminal followed by an identifier;
        ;; unlike Role separators it does not require intervening whitespace.
@@ -179,7 +179,9 @@ A dot followed by a digit can belong to a decimal; a terminal dot stays punctuat
              (problem 'ctm-unsupported :unsupported-directive start
                       (format nil "Directive %~A is outside the implemented subset."
                               (subseq text (1+ start) (lexer-cursor lexer)))))))
-      ((find c "$~")
-       (problem 'ctm-unsupported :unsupported-construct start
-                (format nil "Construct starting with ~S is outside the implemented subset." c)))
+      ((char= c #\$)
+       (unless (name-start-p (peek-character lexer))
+         (problem 'ctm-rejection :invalid-variable start "A variable requires an identifier."))
+       (take-character lexer) (scan-name lexer)
+       (make-token :kind :variable :value (subseq text (1+ start) (lexer-cursor lexer)) :position start))
       (t (problem 'ctm-rejection :unexpected-character start (format nil "Unexpected character ~S." c))))))