Skip to content

Instantly share code, notes, and snippets.

@yamasushi
Created March 13, 2013 04:57
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 yamasushi/5149485 to your computer and use it in GitHub Desktop.
Save yamasushi/5149485 to your computer and use it in GitHub Desktop.
(define (make-string q)
(let* ([%quote ($char q)]
[%escape ($char #\\)]
[%hex4 ($fmap (^s (string->number (list->string s) 16))
($many hexdigit 4 4))]
[%special-char
($do %escape
($or ($char q)
($char #\\)
($char #\/)
($do [($char #\b)] ($return #\x08))
($do [($char #\f)] ($return #\page))
($do [($char #\n)] ($return #\newline))
($do [($char #\r)] ($return #\return))
($do [($char #\t)] ($return #\tab))
($do [($char #\u)] (c %hex4) ($return (ucs->char c)))))]
[%unescaped ($none-of (char-set q) )]
[%body-char ($or %special-char %unescaped)]
[%string-body ($->rope ($many %body-char))])
($between %quote %string-body %quote)))
; 文字列はシングルクオートとダブルクオート
(define %string ($or (make-string #\') (make-string #\") ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment