(rapid syntax)

Syntax objects encapsulating Scheme datums together with source-location information.

Syntax objects

A syntax object consists of an unwrapped syntax object together with source location information about the unwrapped syntax object. An unwrapped syntax object is either a vector whose elements are syntax objects, a pair whose car is a syntax object and whose cdr is either a syntax object or the empty list, or any other Scheme value.

Syntax

(syntax <context> <datum>)

(syntax <datum>)

Converts the <datum> recursively into a syntax object by wrapping each piece that is not already a syntax object with the source location information of the syntax object that is the result of evaluating <context>. If <context> is missing, the current syntactic context (see below) is used. It is an error if the expansion of <datum> contains any cycles. Quasiquote (`), unquote (,), unquote-splicing (,@), and ... inside <datum> have the same meaning as if <datum> appeared at the top nesting level inside a quasiquotation. The meaning of ... is as in the quasiquotation syntax exported by (rapid quasiquote).

(syntax-match <expr> <clause> ...)

Equivalent to (match <expr> <clause> ...) from (rapid match) with the following exceptions: Firstly, the current syntactic context in the <clause>s is changed to that of the result of evaluating <expr> should it evaluate to a syntax object. Secondly, while matching the result of evaluating <expr> against the clauses, syntax objects are automatically unwrapped if needed.

Procedures

(make-source-location source start-line start-column end-line end-column)

Returns a source location with the fields (see below) as specified.

(source-location? obj)

Returns #t if obj is a source location, and #f otherwise.

(source-location-source source-location)

Returns the source (an arbitrary value, often a path) of the the source-location, identifying its source.

(source-location-start-line source-location)

Returns the line number (counting from 1) of the starting position of the source-location.

(source-location-start-column source-location)

Returns the column number (counting from 0) of the starting position of the source-location.

(source-location-end-line source-location)

Returns the line number (counting from 1) of the ending position of the source-location.

(source-location-end-column source-location)

Returns the column number (counting from 0) of the ending position of the source-location.

(source-location->string source-location)

Converts the source-location into a string for use in error messages. The format follows the GNU Coding Standards.

(source-location->prefix source-location)

Equivalent to (source-location->string source-location) except that the string ": " is added to the result if it is not the empty string.

(make-syntax datum source-location)

Returns a new syntax object consisting of the unwrapped syntax object datum and source-location.

(syntax? obj)

Returns #t if obj is a source location, and #f otherwise.

(unwrap-syntax syntax)

Returns the unwrapped syntax object inside the syntax object syntax. Returns syntax itself if it is not a syntax object,

(syntax->datum syntax strip)

(syntax->datum syntax)

Recursively apply unwrap-syntax to the syntax object syntax. Moreover, unwrapped syntax objects that are neither pairs, vectors, or lists are mapped by the procedure strip taking one argument and returning one value. If strip is not given, it defaults to a procedure returning its argument. syntax->datum is able to handle cycles in syntax.

(datum->syntax context datum)

Converts datum recursively into a syntax object by wrapping each piece that is not already a syntax object with the source location information of the syntax object <ontext. It is an error if datum contains cycles.

(syntax-error-object? obj)

Returns #t if obj is a syntax error object, and #f otherwise.

(syntax-error-object-type syntax-error-object)

Returns the type of syntax-error-object. Possible types are the symbols error, warning, note, and fatal-error.

(syntax-error-object-syntax syntax-error-object)

Returns the syntax object associated with syntax-error-object.

(syntax-error-object-message syntax-error-object)

Returns the error message associated with syntax-error-object.

(raise-syntax-error syntax format-string object ...)

Raises a syntax error object of type error associated with syntax where the error message is given by the (rapid format) format-string whose escape sequences are replaced by the objects. The exception is continuable. When the procedure returns, it returns #f.

(raise-syntax-warning syntax format-string object ...)

Raises a syntax error object of type warning associated with syntax where the error message is given by the (rapid format) format-string whose escape sequences are replaced by the objects. The exception is continuable. When the procedure returns, it returns #f.

(raise-syntax-note syntax format-string object ...)

Raises a syntax error object of type note associated with syntax where the error message is given by the (rapid format) format-string whose escape sequences are replaced by the objects. The exception is continuable. When the procedure returns, it returns #f.

(raise-syntax-fatal-error syntax format-string object ...)

Raises a syntax error object of type fatal-error associated with syntax where the error message is given by the (rapid format) format-string whose escape sequences are replaced by the objects.

(syntax-error-object->string syntax-error-object)

Converts the syntax-error-object into a string for use in error messages. The format follows the GNU Coding Standards.

(syntax-vicinity syntax-object)

(syntax->vicinity syntax)

Returns the vicinity of the source location of the syntax-object.

Parameter objects

current-syntax-context

Parameter object holding the current syntactic context, a syntax object.

Comparators

syntax-comparator

Comparator used to compare syntax objects. It provides both ordering and hash functions.