@@ -14,6 +14,7 @@ import Control.Arrow ((<+>))
14import Control.Monad (forM, mzero)
14import Control.Monad (forM, mzero)
15import Control.Monad.State (StateT, evalStateT)
15import Control.Monad.State (StateT, evalStateT)
16import Control.PatternArrows
16import Control.PatternArrows
17+import Data.Char (isAscii)
17import Data.List ((\\))
18import Data.List ((\\))
18import qualified Control.Arrow as A
19import qualified Control.Arrow as A
@@ -43,7 +44,14 @@ literals = mkPattern' match'
44 match :: (Emit gen) => AST -> StateT PrinterState Maybe gen
45 match :: (Emit gen) => AST -> StateT PrinterState Maybe gen
45 match (NumericLiteral _ n) = return $ emit $ T.pack $ either show show n
46 match (NumericLiteral _ n) = return $ emit $ T.pack $ either show show n
46− match (StringLiteral _ s) = return $ emit $ prettyPrintString s
47+ match (StringLiteral _ s)
48+ | Just s' <- decodeString s = return $ emit $
50+ then stringLiteral s'
51+ else "u8" <> stringLiteral s'
52+ match (StringLiteral _ s)
53+ | Just s' <- decodeString s = return $ emit $ "u8" <> stringLiteral s'
54+ match (StringLiteral _ s) = error $ "Bad character in string literal " ++ show s
47 match (BooleanLiteral _ True) = return $ emit "true"
55 match (BooleanLiteral _ True) = return $ emit "true"
48 match (BooleanLiteral _ False) = return $ emit "false"
56 match (BooleanLiteral _ False) = return $ emit "false"
49 -- match (ArrayLiteral _ []) = return $ emit "std::initializer_list<boxed>{}"
57 -- match (ArrayLiteral _ []) = return $ emit "std::initializer_list<boxed>{}"
@@ -373,6 +381,9 @@ prettyPrintCpp' = A.runKleisli $ runPattern matchValue
373prettyPrintCpp1 :: AST -> Text
381prettyPrintCpp1 :: AST -> Text
374prettyPrintCpp1 = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyPrintCpp'
382prettyPrintCpp1 = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyPrintCpp'
384+stringLiteral :: Text -> Text
385+stringLiteral s = "\"" <> s <> "\""
376unbox :: Text -> AST -> Text
387unbox :: Text -> AST -> Text
377unbox _ v@(NumericLiteral{}) = prettyPrintCpp1 v
388unbox _ v@(NumericLiteral{}) = prettyPrintCpp1 v
378unbox _ v@(BooleanLiteral{}) = prettyPrintCpp1 v
389unbox _ v@(BooleanLiteral{}) = prettyPrintCpp1 v