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-location 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 function provide the dynamic binding of the current source location:
;; Dynamically bind the current source location ;; location is an expression that returns two values, file and line defmacro with-source-location ?location ?:block => ... ;; With no arguments, source-location returns the values stashed ;; by the innermost with-source-location def source-location (result: file, line) ...
Previous page Table of Contents Next page