Skip to content

Instantly share code, notes, and snippets.

@florence
Last active December 24, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florence/6723605 to your computer and use it in GitHub Desktop.
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.
#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