tools/pas2c.hs
changeset 6921 e6033fe39b7f
parent 6902 7d4e5ce73b98
child 6923 d2405a6a86f5
equal deleted inserted replaced
6920:b1d0d26d41fa 6921:e6033fe39b7f
    44     modify(\s -> s{uniqCounter = uniqCounter s + 1})
    44     modify(\s -> s{uniqCounter = uniqCounter s + 1})
    45     return i
    45     return i
    46     
    46     
    47 addStringConst :: String -> State RenderState Doc
    47 addStringConst :: String -> State RenderState Doc
    48 addStringConst str = do
    48 addStringConst str = do
    49     i <- getUniq
    49     strs <- gets stringConsts
    50     let sn = "__str" ++ show i
    50     let a = find ((==) str . snd) strs
    51     modify (\s -> s{lastType = BTString, stringConsts = (sn, str) : stringConsts s})
    51     if isJust a then
    52     return $ text sn
    52         return . text . fst . fromJust $ a
       
    53     else
       
    54         do
       
    55         i <- getUniq
       
    56         let sn = "__str" ++ show i
       
    57         modify (\s -> s{lastType = BTString, stringConsts = (sn, str) : strs})
       
    58         return $ text sn
    53     
    59     
    54 escapeStr :: String -> String
    60 escapeStr :: String -> String
    55 escapeStr = foldr escapeChar []
    61 escapeStr = foldr escapeChar []
    56 
    62 
    57 escapeChar :: Char -> ShowS
    63 escapeChar :: Char -> ShowS