Last active
June 24, 2020 19:29
-
-
Save LeifAndersen/3f8c3c02631cbc5d7e3ad21333de6f66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require syntax/parse/define | |
(for-syntax syntax/parse)) | |
(begin-for-syntax | |
(writeln "Now Compiling")) | |
(writeln "Now Running") | |
(define-syntax (caps stx) | |
(raise-syntax-error 'caps "Can't use here")) | |
(define-syntax (happy stx) | |
(raise-syntax-error 'happy "Can't use here")) | |
(begin-for-syntax | |
(define-syntax-class options | |
#:literals (caps happy) | |
(pattern ((~or (~optional (~and caps cps)) | |
(~optional (~and happy hpy))) ...)))) | |
(define-syntax-parser hi | |
[(_ opts:options name) | |
(define hi (if (attribute opts.cps) "HI" "hi")) | |
(define end (if (attribute opts.hpy) ", I'm happy" "")) | |
#`(format "~a ~a~a" #,hi name #,end)]) | |
(hi (caps) | |
"Leif") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require syntax/parse/define | |
(for-syntax syntax/parse)) | |
(begin-for-syntax | |
(writeln "Now Compiling")) | |
(writeln "Now Running") | |
(define-syntax-parser hi | |
[(_ ((~or (~optional (~and #:caps caps)) | |
(~optional (~and #:happy happy))) ...) | |
name) | |
(define hi (if (attribute caps) "HI" "hi")) | |
(define end (if (attribute happy) ", I'm happy" "")) | |
#`(format "~a ~a~a" #,hi name #,end)]) | |
(hi (#:caps #:happy) | |
"Leif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment