Skip to content

Commit

Permalink
define-extension -> define-dsl-syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelballantyne committed Jul 16, 2024
1 parent 5381049 commit 26791ba
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions private/syntax/interface.rkt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#lang racket/base

(provide syntax-spec
define-extension
define-dsl-syntax
(for-syntax racket-expr
racket-var
racket-macro
Expand Down Expand Up @@ -349,7 +349,7 @@



(define-syntax define-extension
(define-syntax define-dsl-syntax
(syntax-parser
[(_ name eclass rhs)
(define space (eval-transformer #'(extension-class-space eclass)))
Expand Down
4 changes: 2 additions & 2 deletions scribblings/tutorial/basic-tutorial.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ syntax-spec allows us to make our DSLs macro-extensible. For example, let's allo

(define-syntax-rule
(define-state-syntax name trans)
(define-extension name state-macro trans))
(define-dsl-syntax name state-macro trans))
]

By adding an extension class called @racket[state-macro] and allowing @racket[state-spec] to be extended by these state macros, transformers wrapped with @racket[state-macro] can be used in @racket[state-spec] positions. syntax-spec provides @racket[define-extension] for defining these wrapped transformers. These macros will be hygienic in our DSL. Since only certain nonterminals are extensible by certain extension classes, we can control what kinds of macros can be used where.
By adding an extension class called @racket[state-macro] and allowing @racket[state-spec] to be extended by these state macros, transformers wrapped with @racket[state-macro] can be used in @racket[state-spec] positions. syntax-spec provides @racket[define-dsl-syntax] for defining these wrapped transformers. These macros will be hygienic in our DSL. Since only certain nonterminals are extensible by certain extension classes, we can control what kinds of macros can be used where.

Now let's create a macro in our language!

Expand Down
2 changes: 1 addition & 1 deletion scribblings/tutorial/stlc-tutorial.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Finally, we can write macros for @racket[let] and @racket[lambda]:
(define-syntax define-stlc-syntax
(syntax-parser
[(_ name:id trans:expr)
#'(define-extension name typed-macro trans)]))
#'(define-dsl-syntax name typed-macro trans)]))

(define-stlc-syntax let
(syntax-parser
Expand Down
2 changes: 1 addition & 1 deletion tests/dsls/match.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
(define-syntax define-match-expander
(syntax-parser
[(_ name:id trans:expr)
#`(define-extension name pat-macro trans)]))
#`(define-dsl-syntax name pat-macro trans)]))

(define-match-expander _
(syntax-parser
Expand Down
8 changes: 4 additions & 4 deletions tests/dsls/minikanren-binding-space.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@


; Surface syntax
(define-extension conj goal-macro
(define-dsl-syntax conj goal-macro
(syntax-parser
[(_ g) #'g]
[(_ g1 g2 g* ...) #'(conj (conj2 g1 g2) g* ...)]))

(define-extension disj goal-macro
(define-dsl-syntax disj goal-macro
(syntax-parser
[(_ g) #'g]
[(_ g1 g* ...) #'(disj2 g1 (disj g* ...))]))

(define-extension fresh goal-macro
(define-dsl-syntax fresh goal-macro
(syntax-parser
[(_ (x:id ...+) b ...+)
#'(fresh1 (x ...) (conj b ...))]))

(define-extension conde goal-macro
(define-dsl-syntax conde goal-macro
(syntax-parser
[(_ [g ...+] ...+)
#'(disj
Expand Down
14 changes: 7 additions & 7 deletions tests/dsls/minikanren-rs2e/mk.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

;; TODO: use syntax-parse and syntax classes for better errors.

(define-extension quasiquote term-macro
(define-dsl-syntax quasiquote term-macro
(syntax-parser
[(~describe
"`<datum>"
Expand All @@ -85,38 +85,38 @@
[(~or* v:identifier v:number) #'(quote v)]
[() #'(quote ())]))]))

(define-extension disj goal-macro
(define-dsl-syntax disj goal-macro
(syntax-rules ()
((disj) fail)
((disj g) g)
((disj g0 g ...) (disj2 g0 (disj g ...)))))

(define-extension conj goal-macro
(define-dsl-syntax conj goal-macro
(syntax-rules ()
((conj) succeed)
((conj g) g)
((conj g0 g ...) (conj2 g0 (conj g ...)))))

(define-extension fresh goal-macro
(define-dsl-syntax fresh goal-macro
(syntax-rules ()
((fresh () g ...) (conj g ...))
((fresh (x0 x ...) g ...)
(fresh1 (x0)
(fresh (x ...)
g ...)))))

(define-extension conde goal-macro
(define-dsl-syntax conde goal-macro
(syntax-rules ()
((conde (g ...) ...)
(disj (conj g ...) ...))))

(define-extension conda goal-macro
(define-dsl-syntax conda goal-macro
(syntax-rules ()
((conda (g0 g ...)) (conj g0 g ...))
((conda (g0 g ...) ln ...)
(ifte g0 (conj g ...) (conda ln ...)))))

(define-extension condu goal-macro
(define-dsl-syntax condu goal-macro
(syntax-rules ()
((condu (g0 g ...) ...)
(conda ((once g0) g ...) ...))))
Expand Down
2 changes: 1 addition & 1 deletion tests/dsls/simply-typed-lambda-calculus.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
(define-syntax define-stlc-syntax
(syntax-parser
[(_ name:id trans:expr)
#'(define-extension name typed-macro trans)]))
#'(define-dsl-syntax name typed-macro trans)]))

(define-stlc-syntax let
(syntax-parser
Expand Down
2 changes: 1 addition & 1 deletion tests/dsls/state-machine-for-tutorial.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

(define-syntax-rule
(define-state-syntax name trans)
(define-extension name state-macro trans))
(define-dsl-syntax name state-macro trans))

(module+ test
(define mchn
Expand Down

0 comments on commit 26791ba

Please sign in to comment.