X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/topic-maps.git/blobdiff_plain/0573c4f710982dab1c3f2c9284adf459caaf73e9..refs/heads/codex/xtm-slice-22r:/src/ctm/templates.lisp?ds=sidebyside diff --git a/src/ctm/templates.lisp b/src/ctm/templates.lisp index 3fd493d..e2a3d71 100644 --- a/src/ctm/templates.lisp +++ b/src/ctm/templates.lisp @@ -94,7 +94,7 @@ already inside one lexer token. Embedded syntax is skipped with balanced depth." ;; Topic. In particular an unused QName still needs a bound prefix, and ;; a resolved prefix must not be percent-decoded again at variable use. (make-template-argument :kind :iri :token token :value (literal-iri-reference parser))) - ((:string :integer :decimal :date :datetime :excluded-literal) + ((:string :integer :decimal :date :datetime :ctm-integer) (let ((plain (and (eq :string (token-kind token)) (not (next-punctuation-p parser #\^))))) (multiple-value-bind (value datatype) (read-literal parser) (make-template-argument :kind :literal :token token :value value :datatype datatype :plain-string-p plain)))) @@ -131,15 +131,24 @@ already inside one lexer token. Embedded syntax is skipped with balanced depth." (old-bindings (parser-bindings parser)) (old-wildcards (parser-wildcards parser)) (*template-context* (cons (list :name (template-definition-name definition) :definition-position (template-definition-position definition) - :invocation-position (token-position name)) *template-context*))) + :invocation-position (token-position name) + :definition-source (template-definition-source-name definition) + :definition-document-iri (template-definition-document-iri definition) + :invocation-source *source-name* + :invocation-document-iri (parser-document-iri parser)) *template-context*))) (loop for parameter in (template-definition-parameters definition) for argument in arguments do (setf (gethash parameter bindings) argument)) (unwind-protect (progn (setf (parser-bindings parser) bindings (parser-wildcards parser) (make-hash-table :test #'equal)) - (dolist (statement (template-definition-body definition)) - (call-with-tokens parser (ctm-statement-tokens statement) - (lambda () (read-statement parser map))))) + ;; The parser's Document IRI, Prefixes, registry and Counter stay + ;; in the caller. Only lexical source coordinates switch to the + ;; definition; nested invocations preserve both source frames. + (let ((*source-name* (template-definition-source-name definition)) + (*source-text* (template-definition-source-text definition))) + (dolist (statement (template-definition-body definition)) + (call-with-tokens parser (ctm-statement-tokens statement) + (lambda () (read-statement parser map)))))) (setf (parser-bindings parser) old-bindings (parser-wildcards parser) old-wildcards)))))) (defun read-statement (parser map) @@ -185,8 +194,7 @@ already inside one lexer token. Embedded syntax is skipped with balanced depth." (let ((token (look parser))) (cond ((eq :variable (token-kind token)) (syntax-variable parser parameters)) ((member (token-kind token) '(:iri :qname :integer :decimal :date :datetime)) (consume parser)) - ((eq :excluded-literal (token-kind token)) - (problem 'ctm-unsupported :occurrence-literal-datatype (token-position token) "The separate '*' literal remains unsupported.")) + ((eq :ctm-integer (token-kind token)) (consume parser)) ((eq :string (token-kind token)) (consume parser) (when (punctuation-p parser #\^) @@ -225,7 +233,7 @@ already inside one lexer token. Embedded syntax is skipped with balanced depth." (consume parser) (syntax-expect parser #\() (unless (punctuation-p parser #\)) (loop - (if (member (token-kind (look parser)) '(:string :integer :decimal :date :datetime :excluded-literal)) + (if (member (token-kind (look parser)) '(:string :integer :decimal :date :datetime :ctm-integer)) (syntax-literal parser parameters) (syntax-reference parser parameters)) (unless (punctuation-p parser #\,) (return)) (consume parser))) (syntax-expect parser #\))) @@ -306,4 +314,6 @@ already inside one lexer token. Embedded syntax is skipped with balanced depth." (consume parser) (setf (gethash key (parser-templates parser)) (make-template-definition :name (token-value name) :parameters parameters - :position (token-position start) :body (nreverse body)))))) + :position (token-position start) :body (nreverse body) + :source-name *source-name* :source-text *source-text* + :document-iri (parser-document-iri parser))))))