Fix string/character literal escaping

This commit is contained in:
Adam Sampson 2007-04-19 17:57:35 +00:00
parent ec8c4a1c48
commit 618ded6afd
3 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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.

View File

@ -0,0 +1,4 @@
PROC P ()
VAL []BYTE s IS "*c*n*t*s*X*#00*#A0\now":
SKIP
: