Fix string/character literal escaping
This commit is contained in:
parent
ec8c4a1c48
commit
618ded6afd
|
@ -38,6 +38,8 @@ import Data.Maybe
|
|||
import Control.Monad.Writer
|
||||
import Control.Monad.Error
|
||||
import Control.Monad.State
|
||||
import Numeric
|
||||
import Text.Printf
|
||||
|
||||
import qualified AST as A
|
||||
import Metadata
|
||||
|
@ -195,9 +197,14 @@ genLiteralRepr (A.ArrayLiteral m es)
|
|||
sequence_ $ intersperse genComma (map genExpression es)
|
||||
tell ["}"]
|
||||
|
||||
hexToOct :: String -> String
|
||||
hexToOct h = printf "%03o" (fst $ head $ readHex h)
|
||||
|
||||
convStringLiteral :: String -> String
|
||||
convStringLiteral [] = []
|
||||
convStringLiteral ('*':'#':a:b:s) = "\\x" ++ [a, b] ++ convStringLiteral s
|
||||
convStringLiteral ('\\':s) = "\\\\" ++ convStringLiteral s
|
||||
convStringLiteral ('*':'#':'0':'0':s) = "\\0" ++ convStringLiteral s
|
||||
convStringLiteral ('*':'#':a:b:s) = "\\" ++ hexToOct [a, b] ++ convStringLiteral s
|
||||
convStringLiteral ('*':c:s) = convStringStar c ++ convStringLiteral s
|
||||
convStringLiteral (c:s) = c : convStringLiteral s
|
||||
|
||||
|
|
|
@ -15,5 +15,3 @@ handles different types.)
|
|||
Have a final pass that checks all the mangling has been done -- i.e. function
|
||||
calls have been removed, and so on.
|
||||
|
||||
String conversion is broken -- it needs to escape backslashes.
|
||||
|
||||
|
|
4
fco2/testcases/stringlit.occ
Normal file
4
fco2/testcases/stringlit.occ
Normal file
|
@ -0,0 +1,4 @@
|
|||
PROC P ()
|
||||
VAL []BYTE s IS "*c*n*t*s*X*#00*#A0\now":
|
||||
SKIP
|
||||
:
|
Loading…
Reference in New Issue
Block a user