Previous page Table of Contents Next page
As mentioned above, a token-stream keeps track of source locations. A source location is the file name and line number where a token appears. This is useful for error messages and debuggers.
Source location information is transferred from the token-stream to objects in the program model. A function invocation holds a source location, as does any other object that implements the source-locator protocol.
When the expression parser expands a macro, it remembers the source location of the macro name in the macro call, in such a way that any dynamically nested call to source-file or source-line with no arguments will return that source location. Any compound-expression object created during macro expansion is given the remembered source location.
The defparser and defsyntax macros expand into a parse function. These macros generate code which remembers the source location of the first token parsed. Any compound-expression object created during the parsing is given the remembered source location.
The template macro generates code to transfer source locations from the input token-stream to the output token sequence, using a source-location-marker where necessary. Then parsing from a token-stream wrapping the token sequence will recover the source location information.
The following macro and functions provide the dynamic binding of the current source location:
;; Dynamically bind the current source location ;; locator is an expression that evaluates to an object that ;; implements the source-locator protocol defmacro with-source-location ?locator ?:block => ... ;; With no arguments, source-file and source-line return the values stashed ;; by the innermost with-source-location defun source-file () is string ; file name defun source-line () is integer ; line number
Previous page Table of Contents Next page