[honu] fix escapes in string literals
This commit is contained in:
parent
7532515110
commit
cd5d0ee9a3
|
@ -37,6 +37,15 @@
|
||||||
;; we might hit eof before a \n
|
;; we might hit eof before a \n
|
||||||
(:? "\n")))
|
(:? "\n")))
|
||||||
|
|
||||||
|
(define (replace-escapes string)
|
||||||
|
(define replacements '([#px"\\\\n" "\n"]
|
||||||
|
[#px"\\\\t" "\t"]))
|
||||||
|
(for/fold ([string string])
|
||||||
|
([replace replacements])
|
||||||
|
(define pattern (car replace))
|
||||||
|
(define with (cadr replace))
|
||||||
|
(regexp-replace* pattern string with)))
|
||||||
|
|
||||||
(define honu-lexer
|
(define honu-lexer
|
||||||
(lexer-src-pos
|
(lexer-src-pos
|
||||||
[(eof) (token-eof)]
|
[(eof) (token-eof)]
|
||||||
|
@ -58,11 +67,10 @@
|
||||||
[";" (token-identifier '|;|)]
|
[";" (token-identifier '|;|)]
|
||||||
;; strip the quotes from the resulting string
|
;; strip the quotes from the resulting string
|
||||||
;; TODO: find a more optimal way
|
;; TODO: find a more optimal way
|
||||||
[string (begin
|
[string (let ()
|
||||||
#;
|
(define raw (substring (substring lexeme 1)
|
||||||
(printf "Parsed string '~a'\n" lexeme)
|
0 (- (string-length lexeme) 2)))
|
||||||
(token-string (substring (substring lexeme 1)
|
(token-string (replace-escapes raw)))]
|
||||||
0 (- (string-length lexeme) 2))))]
|
|
||||||
["(" (token-left-parens)] [")" (token-right-parens)]
|
["(" (token-left-parens)] [")" (token-right-parens)]
|
||||||
["[" (token-left-bracket)] ["]" (token-right-bracket)]
|
["[" (token-left-bracket)] ["]" (token-right-bracket)]
|
||||||
["{" (token-left-brace)] ["}" (token-right-brace)]
|
["{" (token-left-brace)] ["}" (token-right-brace)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user