on master help sign in
Generate escape characters properly in strings
30c71b0Evan Czaplicki
compiler/src/Data/Utf8.hs+7−12
@@ -27,12 +27,12 @@ import GHC.Exts
27 , newByteArray#, unsafeFreezeByteArray#
27 , newByteArray#, unsafeFreezeByteArray#
28 , sizeofByteArray#
28 , sizeofByteArray#
29 , copyAddrToByteArray#, copyByteArrayToAddr#
29 , copyAddrToByteArray#, copyByteArrayToAddr#
30− , writeWord8Array#, writeWord16Array#
30+ , writeWord8Array#,
31 )
31 )
32import GHC.IO
32import GHC.IO
33import GHC.ST (ST(ST), runST)
33import GHC.ST (ST(ST), runST)
34import GHC.Prim
34import GHC.Prim
35−import GHC.Word (Word8(W8#), Word16(W16#))
35+import GHC.Word (Word8(W8#))
36
36
37
37
38
38
@@ -122,7 +122,7 @@ empty =
122
122
123data Chunk
123data Chunk
124 = Slice Int Int -- TODO try UNPACK
124 = Slice Int Int -- TODO try UNPACK
125− | Escape Word16
125+ | Escape Word8
126 | CodePoint Int
126 | CodePoint Int
127
127
128
128
@@ -165,7 +165,8 @@ writeChunks ptr mba offset chunks =
165 writeChunks ptr mba newOffset chunks
165 writeChunks ptr mba newOffset chunks
166
166
167 Escape word ->
167 Escape word ->
168− do writeWord16 mba offset word
168+ do writeWord8 mba offset 0x5C {- \ -}
169+ writeWord8 mba (offset + 1) word
169 let !newOffset = offset + 2
170 let !newOffset = offset + 2
170 writeChunks ptr mba newOffset chunks
171 writeChunks ptr mba newOffset chunks
171
172
@@ -185,7 +186,8 @@ writeChunks ptr mba offset chunks =
185-- TODO see if it is faster to writeWord32 a block of hex-as-ascii
186-- TODO see if it is faster to writeWord32 a block of hex-as-ascii
186writeCode :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
187writeCode :: MBA RealWorld -> Int -> Int -> ST RealWorld ()
187writeCode mba offset code =
188writeCode mba offset code =
188− do writeWord16 mba offset 0x5C75 {- \u -}
189+ do writeWord8 mba offset 0x5C {- \ -}
190+ writeWord8 mba offset 0x75 {- u -}
189 writeHex mba (offset + 2) (shiftR code 12)
191 writeHex mba (offset + 2) (shiftR code 12)
190 writeHex mba (offset + 3) (shiftR code 8)
192 writeHex mba (offset + 3) (shiftR code 8)
191 writeHex mba (offset + 4) (shiftR code 4)
193 writeHex mba (offset + 4) (shiftR code 4)
@@ -341,10 +343,3 @@ writeWord8 (MBA# mba#) (I# i#) (W8# w#) =
341 ST $ \s ->
343 ST $ \s ->
342 case writeWord8Array# mba# i# w# s of
344 case writeWord8Array# mba# i# w# s of
343 s -> (# s, () #)
345 s -> (# s, () #)
344−
345−
346−writeWord16 :: MBA s -> Int -> Word16 -> ST s ()
347−writeWord16 (MBA# mba#) (I# i#) (W16# w#) =
348− ST $ \s ->
349− case writeWord16Array# mba# i# w# s of
350− s -> (# s, () #)
compiler/src/Parse/Primitives/Utf8.hs+4−4
@@ -296,25 +296,25 @@ eatUnicode fp offset terminal =
296{-# NOINLINE singleQuote #-}
296{-# NOINLINE singleQuote #-}
297singleQuote :: Utf8.Chunk
297singleQuote :: Utf8.Chunk
298singleQuote =
298singleQuote =
299− Utf8.Escape 0x5C27 {- \' -}
299+ Utf8.Escape 0x27 {- ' -}
300
300
301
301
302{-# NOINLINE doubleQuote #-}
302{-# NOINLINE doubleQuote #-}
303doubleQuote :: Utf8.Chunk
303doubleQuote :: Utf8.Chunk
304doubleQuote =
304doubleQuote =
305− Utf8.Escape 0x5C22 {- \" -}
305+ Utf8.Escape 0x22 {- " -}
306
306
307
307
308{-# NOINLINE newline #-}
308{-# NOINLINE newline #-}
309newline :: Utf8.Chunk
309newline :: Utf8.Chunk
310newline =
310newline =
311− Utf8.Escape 0x5C6E {- \n -}
311+ Utf8.Escape 0x6E {- n -}
312
312
313
313
314{-# NOINLINE carriageReturn #-}
314{-# NOINLINE carriageReturn #-}
315carriageReturn :: Utf8.Chunk
315carriageReturn :: Utf8.Chunk
316carriageReturn =
316carriageReturn =
317− Utf8.Escape 0x5C72 {- \r -}
317+ Utf8.Escape 0x72 {- \r -}
318
318
319
319
320{-# NOINLINE placeholder #-}
320{-# NOINLINE placeholder #-}