Skip to content

Instantly share code, notes, and snippets.

@LeifAndersen
Last active June 24, 2020 19:29
Show Gist options
  • Save LeifAndersen/3f8c3c02631cbc5d7e3ad21333de6f66 to your computer and use it in GitHub Desktop.
Save LeifAndersen/3f8c3c02631cbc5d7e3ad21333de6f66 to your computer and use it in GitHub Desktop.
#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")
#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