-
-
Save dys-bigwig/76d0e87805bfc34ad8fce1a4cae85330 to your computer and use it in GitHub Desktop.
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 | |
(define (whitespace? c) | |
(or (eqv? c #\space) | |
(eqv? c #\newline))) | |
(define (open-quote? c) | |
(eqv? c #\")) | |
(define (open-paren? c) | |
(eqv? c #\()) | |
(define (close-paren? c) | |
(eqv? c #\))) | |
(define (backspace? c) | |
(eqv? c #\backspace)) | |
(define (skip-char) | |
(read-char)) | |
(define (open-quote) | |
(let loop ([str '()]) | |
(define c (peek-char)) | |
(cond | |
[(backspace? c) (skip-char) | |
(loop (cons (read-char) | |
str))] | |
[(open-quote? c) (reverse str)] | |
[else (loop (cons (read-char) | |
str))]))) | |
(define (parse-exp) | |
(define c (peek-char)) | |
(cond | |
[(open-quote? c) (skip-char) | |
(open-quote)])) | |
(define (parse input) | |
(with-input-from-string input | |
(λ () | |
(parse-exp)))) | |
(parse (list->string '(#\" #\H #\I #\"))) | |
(parse (list->string '(#\" #\H #\E #\SPACE | |
#\S #\A #\I #\D #\SPACE | |
#\BACKSPACE #\" #\H #\I | |
#\BACKSPACE #\" | |
#\"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment