You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-demo/tacopocalypse-demo/main.rkt

41 lines
992 B
Racket

#lang br/quicklang
6 years ago
(require brag/support)
(module+ reader
(provide read-syntax))
(define lex
(lexer
["#$" null]
["%" 'taco]
[any-char (lex input-port)]))
(define (tokenize ip)
(for/list ([tok (in-port lex ip)])
tok))
6 years ago
(define (parse src toks)
5 years ago
(define heptatoks
(let loop ([toks toks][acc null])
(if (empty? toks)
(reverse acc)
(loop (drop toks 7) (cons (take toks 7) acc)))))
(for/list ([heptatok (in-list heptatoks)])
6 years ago
(integer->char
(for/sum ([val (in-list heptatok)]
6 years ago
[power (in-naturals)]
#:when (eq? val 'taco))
(expt 2 power)))))
(define (read-syntax src ip)
(define toks (tokenize ip))
6 years ago
(define parse-tree (parse src toks))
(strip-context
(with-syntax ([PT parse-tree])
6 years ago
#'(module taco-mod tacopocalypse-demo
PT))))
(define-macro (my-module-begin PT)
6 years ago
#'(#%module-begin
(display (list->string 'PT))))
(provide (rename-out [my-module-begin #%module-begin]))