Last active
December 24, 2015 01:29
-
-
Save florence/6723605 to your computer and use it in GitHub Desktop.
The parse function takes in a string. space, tabs, and newlines are ignored.
This file contains hidden or 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 parser-tools/lex | |
(prefix-in : parser-tools/lex-sre)) | |
(define-lex-trans ::? | |
(lambda (stx) | |
(syntax-case stx () | |
[(_ v b) | |
#'(:: v (:? " ") b)]))) | |
(define progl | |
(lexer | |
[(eof) #f] | |
[(:or #\space #\tab) (progl input-port)] | |
[(::? "so" "dood") ">"] | |
[(::? "yeah" "dood") "<"] | |
[(::? "so" "um") "+"] | |
[(::? "yeah" "um") "-"] | |
[(::? "so" "...") "."] | |
[(::? "yeah" "...") ","] | |
[(::? "so" "?") "["] | |
[(::? "yeah" "?") "]"])) | |
(define (parse s) | |
(define o (open-input-string s)) | |
(let loop () | |
(define t (progl o)) | |
(if (not t) | |
"" | |
(string-append t (loop))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment