On this page:
8.1 Check Syntax Button
syncheck-drracket-button
syncheck:  button-callback
syncheck-bitmap
8.2 Syntax Properties that Check Syntax Looks For

8 Check Syntax

Check Syntax is a part of the DrRacket collection, but is implemented via the plugin API. See also drracket/check-syntax.

8.1 Check Syntax Button

 (require drracket/syncheck-drracket-button)
  package: drracket

This is meant to be used with the 'drracket:toolbar-buttons argument to the info proc returned from read-language.

This is defined with define-local-member-name and is bound to a method of no arguments of the DrRacket frame that runs Check Syntax.

The bitmap in the Check Syntax button on the DrRacket frame.

8.2 Syntax Properties that Check Syntax Looks For

Check Syntax collects the values of the syntax-propertys named 'disappeared-use, 'disappeared-binding, 'sub-range-binders, and 'mouse-over-tooltips and uses them to add additional arrows to the program text. These properties are intended for use when a macro discards or manufactures identifiers that, from the programmers perspective, should be binding each other.

For example, here is a macro that discards its arguments, but adds properties to the result syntax object so the arguments are treated as a binding/bound pair by Check Syntax.

(define-syntax (m stx)
  (syntax-case stx ()
    [(_ id1 id2)
     (and (identifier? #'id1) (identifier? #'id2))
     (syntax-property
      (syntax-property
       #'1
       'disappeared-use (list (syntax-local-introduce #'id1)))
      'disappeared-binding (list (syntax-local-introduce #'id2)))]))

See also current-recorded-disappeared-uses.

The value of the 'sub-range-binders property is expected to be a tree of cons pairs (in any configuration) whose leaves are either ignored or are vectors of the shape
If the leaf is a vector, the first syntax object is expected to be an identifier whose bound occurrences should have arrows that point to the syntax object in the fourth position in the vector. The numbers indicate the starting point and the range inside the corresponding identifier to consider as the location of the end of the arrow. Here’s an example:

#lang racket/base
(require (for-syntax racket/base))
(define-syntax (define/hyphen stx)
  (syntax-case stx ()
    [(_ id1 id2 rhs-expr)
     (let ()
       (define first-part (symbol->string (syntax-e #'id1)))
       (define second-part (symbol->string (syntax-e #'id2)))
       (define first-len (string-length first-part))
       (define second-len (string-length second-part))
       (define hyphenated-id
         (datum->syntax
          #'id1
          (string->symbol (string-append first-part "-" second-part))))
       (syntax-property
        #`(define #,hyphenated-id rhs-expr)
        'sub-range-binders
        (list
         (vector (syntax-local-introduce hyphenated-id)
                 0 first-len
                 (syntax-local-introduce #'id1)
                 0 first-len)
         (vector (syntax-local-introduce hyphenated-id)
                 (+ first-len 1) second-len
                 (syntax-local-introduce #'id2)
                 0 second-len))))]))
 
(define/hyphen big generator
  11)
 
(+ big-generator big-generator)

After putting this code in the DrRacket window, mouse over the words “big” and “generator” to see arrows pointing to the individual pieces of the identifier big-generator.

The value of the 'mouse-over-tooltips property is expected to be to be a tree of cons pairs (in any configuration) whose leaves are either ignored or are vectors of the shape
Each vector’s content indicates where to show a tooltip. The first three components are a syntax object whose syntax-source field indicates which file the tooltip goes in, the start and end position in the editor where mouseovers will show the tooltip, and the content of the tooltip. For example, here’s a macro that shows the span of itself in a tooltip on mouseover:
#lang racket
(define-syntax (char-span stx)
  (syntax-case stx ()
    [(_ a)
     (syntax-property
      #'a
      'mouse-over-tooltips
      (vector
       stx
       (syntax-position stx)
       (+ (syntax-position stx)
          (syntax-span stx))
       (format "this expression\nspans ~a chars"
               (syntax-span stx))))]))
 
(char-span (+ 1 2))

Finally, Check Syntax only draws arrows between identifiers that are syntax-original? or that have the syntax-property 'original-for-check-syntax set to #t.