Language creation
define-lang-syntax
8.12

Language creation🔗ℹ

 (require syntax/lang) package: syntax-lang

This module provides forms for creating new #lang languages. It abstracts over several language-creation components such as syntax/module-reader, reader submodules, and #%module-begin. This library makes it easy to create simple one-off languages driven by a single macro.

syntax

(define-lang-syntax lang-collection-name module-body-syntax maybe-module-begin)

 
maybe-module-begin = 
  | #:module-begin
  | base-module-begin
Defines a reader submodule that implements a #lang that is equivalent to racket/base, except that module-body-syntax wraps all forms in the module. This must be used in the main.rkt file of the collection directory lang-collection-name. For example, assuming this is in the main file of a collection directory named display-syntax:
(define-syntax display-each-body-stx
  (syntax-parser
    [(_ body ...)
     #'(begin (displayln #'body) ...)]))
Then the following creates a #lang display-syntax that prints each syntax object of the language when run:

(define-lang-syntax display-syntax display-each-body-stx)

If base-module-begin is provided, it is used as the #%module-begin of the new language instead of the #%module-begin from racket/base.