Skip to content

Instantly share code, notes, and snippets.

@dys-bigwig
Last active November 26, 2019 21:57
Show Gist options
  • Save dys-bigwig/76d0e87805bfc34ad8fce1a4cae85330 to your computer and use it in GitHub Desktop.
Save dys-bigwig/76d0e87805bfc34ad8fce1a4cae85330 to your computer and use it in GitHub Desktop.
#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