Created
January 21, 2013 21:28
-
-
Save dyoo/4589601 to your computer and use it in GitHub Desktop.
Example of ragg output being parsed with syntax-parse and literal sets
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/base | |
(require ragg/examples/simple-line-drawing/lexer | |
ragg/examples/simple-line-drawing/grammar | |
syntax/strip-context | |
syntax/parse | |
(for-syntax racket/base)) | |
(define-syntax (drawing stx) (raise-syntax-error #f "Don't look at me; I'm shy" stx)) | |
(define-syntax (rows stx) (raise-syntax-error #f "Don't look at me; I'm shy" stx)) | |
(define-syntax (repeat stx) (raise-syntax-error #f "Don't look at me; I'm shy" stx)) | |
(define-syntax (chunk stx) (raise-syntax-error #f "Don't look at me; I'm shy" stx)) | |
(define an-stx | |
(parse (tokenize (open-input-string "3 9 X; | |
6 3 b 3 X 3 b; | |
3 9 X;")))) | |
(define-literal-set drawing-keywords (drawing rows repeat chunk)) | |
(syntax-parse (replace-context #'here an-stx) | |
#:literal-sets (drawing-keywords) | |
[(drawing row ...) | |
(printf "I see: ~s\n" #'(row ...))]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment