Skip to content

Commit

Permalink
Use fromString instead of explicit packs
Browse files Browse the repository at this point in the history
  • Loading branch information
norm2782 committed Oct 23, 2011
1 parent 7724fd6 commit bee243c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Application.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Data.ListLike (CharString(..))
import Data.Map (Map)
import qualified Data.Map as DM
import Data.Maybe
import Data.String
import Data.Text (Text)
import qualified Data.Text as DT
import qualified Data.Text.Encoding as DT
Expand Down Expand Up @@ -222,7 +223,7 @@ unifyH = restrict forbiddenH $ do
error500H :: ByteString -> AppHandler a
error500H msg = do
modifyResponse $ setResponseStatus 500 "Internal server error"
writeBS $ BS.append (BS.pack "500 internal server error: ") msg
writeBS $ BS.append (fromString "500 internal server error: ") msg
finishWith =<< getResponse

checkSyntaxH :: AppHandler ()
Expand Down
13 changes: 7 additions & 6 deletions src/JCU/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import qualified Data.Attoparsec.Lazy as AP
import qualified Data.ByteString.Lazy.Char8 as LBS
import qualified Data.ByteString.Char8 as BS
import Data.ListLike (CharStringLazy(..))
import Data.String
import Data.Tree (Tree(..))
import Language.Prolog.NanoProlog.NanoProlog
import Text.ParserCombinators.UU.BasicInstances (Parser(), Error, LineColPos)
Expand Down Expand Up @@ -109,21 +110,21 @@ processJSON f raw =
(AP.Done _ r) ->
case f r of
(AE.Success a) -> Right a
(AE.Error err) -> Left . BS.pack $ "Error converting ByteString to data type: " ++ err
(AP.Fail _ _ err) -> Left . BS.pack $ "Error parsing raw JSON: " ++ err
(AE.Error err) -> Left . fromString $ "Error converting ByteString to data type: " ++ err
(AP.Fail _ _ err) -> Left . fromString $ "Error parsing raw JSON: " ++ err

-- TODO: Try to get rid of the explicit annotations...
parseCheck :: Maybe BS.ByteString -> LBS.ByteString -> (Bool, [ErrorMsg])
parseCheck Nothing _ = checkErr [BS.pack "Unknown error."]
parseCheck Nothing _ = checkErr [fromString "Unknown error."]
parseCheck (Just x) body
| x == "rule" = parseMsg pRule body
| x == "term" = parseMsg pTerm body
| otherwise = checkErr [BS.pack "Invalid type specified"]
| otherwise = checkErr [fromString "Invalid type specified"]
where parseMsg :: Parser t -> LBS.ByteString -> (Bool, [ErrorMsg])
parseMsg p txt = writeRes $ startParse p (CSL txt)
writeRes :: (t, [Error LineColPos]) -> (Bool, [ErrorMsg])
writeRes (_, []) = (True, [BS.pack ""])
writeRes (_, rs) = checkErr (map (BS.pack . show) rs)
writeRes (_, []) = (True, [])
writeRes (_, rs) = checkErr (map (fromString . show) rs)

checkErr :: [ErrorMsg] -> (Bool, [ErrorMsg])
checkErr msg = (False, msg)

0 comments on commit bee243c

Please sign in to comment.