-Wall clean
This commit is contained in:
parent
581b53a4f4
commit
63fab93755
1 changed files with 80 additions and 79 deletions
|
@ -34,13 +34,14 @@ import Text.Parsec
|
||||||
import Text.Parsec.String
|
import Text.Parsec.String
|
||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
import Data.Either
|
import Data.Either
|
||||||
import Data.List
|
import Data.List hiding (find)
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Prelude hiding (log)
|
||||||
|
|
||||||
import Utility.Monad
|
import Utility.Monad
|
||||||
import Utility.Misc
|
import Utility.Misc
|
||||||
|
@ -85,27 +86,27 @@ coordsParser = (try singleline <|> try weird <|> multiline) <?> "Coords"
|
||||||
where
|
where
|
||||||
singleline = do
|
singleline = do
|
||||||
line <- number
|
line <- number
|
||||||
char ':'
|
void $ char ':'
|
||||||
startcol <- number
|
startcol <- number
|
||||||
char '-'
|
void $ char '-'
|
||||||
endcol <- number
|
endcol <- number
|
||||||
return $ (Coord line startcol, Coord line endcol)
|
return $ (Coord line startcol, Coord line endcol)
|
||||||
|
|
||||||
weird = do
|
weird = do
|
||||||
line <- number
|
line <- number
|
||||||
char ':'
|
void $ char ':'
|
||||||
col <- number
|
col <- number
|
||||||
return $ (Coord line col, Coord line col)
|
return $ (Coord line col, Coord line col)
|
||||||
|
|
||||||
multiline = do
|
multiline = do
|
||||||
start <- fromparens
|
start <- fromparens
|
||||||
char '-'
|
void $ char '-'
|
||||||
end <- fromparens
|
end <- fromparens
|
||||||
return $ (start, end)
|
return $ (start, end)
|
||||||
|
|
||||||
fromparens = between (char '(') (char ')') $ do
|
fromparens = between (char '(') (char ')') $ do
|
||||||
line <- number
|
line <- number
|
||||||
char ','
|
void $ char ','
|
||||||
col <- number
|
col <- number
|
||||||
return $ Coord line col
|
return $ Coord line col
|
||||||
|
|
||||||
|
@ -121,19 +122,19 @@ indentedLine = indent >> restOfLine
|
||||||
spliceParser :: Parser Splice
|
spliceParser :: Parser Splice
|
||||||
spliceParser = do
|
spliceParser = do
|
||||||
file <- many1 (noneOf ":\n")
|
file <- many1 (noneOf ":\n")
|
||||||
char ':'
|
void $ char ':'
|
||||||
(start, end) <- coordsParser
|
(start, end) <- coordsParser
|
||||||
string ": Splicing "
|
void $ string ": Splicing "
|
||||||
splicetype <- tosplicetype
|
splicetype <- tosplicetype
|
||||||
<$> (string "expression" <|> string "declarations")
|
<$> (string "expression" <|> string "declarations")
|
||||||
newline
|
void newline
|
||||||
|
|
||||||
getthline <- expressionextractor
|
getthline <- expressionextractor
|
||||||
expression <- unlines <$> many1 getthline
|
expression <- unlines <$> many1 getthline
|
||||||
|
|
||||||
indent
|
void indent
|
||||||
string "======>"
|
void $ string "======>"
|
||||||
newline
|
void newline
|
||||||
|
|
||||||
getcodeline <- expressionextractor
|
getcodeline <- expressionextractor
|
||||||
realcoords <- try (Right <$> getrealcoords file) <|> (Left <$> getcodeline)
|
realcoords <- try (Right <$> getrealcoords file) <|> (Left <$> getcodeline)
|
||||||
|
@ -157,7 +158,7 @@ spliceParser = do
|
||||||
expressionextractor = do
|
expressionextractor = do
|
||||||
i <- lookAhead indent
|
i <- lookAhead indent
|
||||||
return $ try $ do
|
return $ try $ do
|
||||||
string i
|
void $ string i
|
||||||
restOfLine
|
restOfLine
|
||||||
|
|
||||||
{- When splicing declarations, GHC will output a splice
|
{- When splicing declarations, GHC will output a splice
|
||||||
|
@ -165,9 +166,9 @@ spliceParser = do
|
||||||
- the first line will give the actual coordinates of the
|
- the first line will give the actual coordinates of the
|
||||||
- line that was spliced. -}
|
- line that was spliced. -}
|
||||||
getrealcoords file = do
|
getrealcoords file = do
|
||||||
indent
|
void indent
|
||||||
string file
|
void $ string file
|
||||||
char ':'
|
void $ char ':'
|
||||||
char '\n' `after` coordsParser
|
char '\n' `after` coordsParser
|
||||||
|
|
||||||
{- Extracts the splices, ignoring the rest of the compiler output. -}
|
{- Extracts the splices, ignoring the rest of the compiler output. -}
|
||||||
|
@ -196,6 +197,7 @@ splicesExtractor = rights <$> many extract
|
||||||
- starts with "import "
|
- starts with "import "
|
||||||
-}
|
-}
|
||||||
applySplices :: FilePath -> Maybe String -> [Splice] -> IO ()
|
applySplices :: FilePath -> Maybe String -> [Splice] -> IO ()
|
||||||
|
applySplices _ _ [] = noop
|
||||||
applySplices destdir imports splices@(first:_) = do
|
applySplices destdir imports splices@(first:_) = do
|
||||||
let f = splicedFile first
|
let f = splicedFile first
|
||||||
let dest = (destdir </> f)
|
let dest = (destdir </> f)
|
||||||
|
@ -237,10 +239,10 @@ expandDeclarationSplice s lls = concat [before, [splice], end]
|
||||||
|
|
||||||
{- Expression splices are expanded within their line. -}
|
{- Expression splices are expanded within their line. -}
|
||||||
expandExpressionSplice :: Splice -> [String] -> [String]
|
expandExpressionSplice :: Splice -> [String] -> [String]
|
||||||
expandExpressionSplice s lls = concat [before, spliced:padding, end]
|
expandExpressionSplice sp lls = concat [before, spliced:padding, end]
|
||||||
where
|
where
|
||||||
cs = spliceStart s
|
cs = spliceStart sp
|
||||||
ce = spliceEnd s
|
ce = spliceEnd sp
|
||||||
|
|
||||||
(before, rest) = splitAt (coordLine cs - 1) lls
|
(before, rest) = splitAt (coordLine cs - 1) lls
|
||||||
(oldlines, end) = splitAt (1 + coordLine (offsetCoord ce cs)) rest
|
(oldlines, end) = splitAt (1 + coordLine (offsetCoord ce cs)) rest
|
||||||
|
@ -251,7 +253,7 @@ expandExpressionSplice s lls = concat [before, spliced:padding, end]
|
||||||
_ -> ([], [], [])
|
_ -> ([], [], [])
|
||||||
spliced = concat
|
spliced = concat
|
||||||
[ joinsplice $ deqqstart $ take (coordColumn cs - 1) splicestart
|
[ joinsplice $ deqqstart $ take (coordColumn cs - 1) splicestart
|
||||||
, addindent (findindent splicestart) (mangleCode $ splicedCode s)
|
, addindent (findindent splicestart) (mangleCode $ splicedCode sp)
|
||||||
, deqqend $ drop (coordColumn ce) spliceend
|
, deqqend $ drop (coordColumn ce) spliceend
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -260,7 +262,7 @@ expandExpressionSplice s lls = concat [before, spliced:padding, end]
|
||||||
|
|
||||||
{- splicing leaves $() quasiquote behind; remove it -}
|
{- splicing leaves $() quasiquote behind; remove it -}
|
||||||
deqqstart s = case reverse s of
|
deqqstart s = case reverse s of
|
||||||
('(':'$':rest) -> reverse rest
|
('(':'$':restq) -> reverse restq
|
||||||
_ -> s
|
_ -> s
|
||||||
deqqend (')':s) = s
|
deqqend (')':s) = s
|
||||||
deqqend s = s
|
deqqend s = s
|
||||||
|
@ -331,27 +333,27 @@ mangleCode = flip_colon
|
||||||
-- skip lambdas inside tuples or parens
|
-- skip lambdas inside tuples or parens
|
||||||
prefix <- noneOf "(, \n"
|
prefix <- noneOf "(, \n"
|
||||||
preindent <- many1 $ oneOf " \n"
|
preindent <- many1 $ oneOf " \n"
|
||||||
string "\\ "
|
void $ string "\\ "
|
||||||
lambdaparams <- restofline
|
lambdaparams <- restofline
|
||||||
continuedlambdaparams <- many $ try $ do
|
continuedlambdaparams <- many $ try $ do
|
||||||
indent <- many1 $ char ' '
|
indent1 <- many1 $ char ' '
|
||||||
p <- satisfy isLetter
|
p <- satisfy isLetter
|
||||||
aram <- many $ satisfy isAlphaNum <|> oneOf "_"
|
aram <- many $ satisfy isAlphaNum <|> oneOf "_"
|
||||||
newline
|
void newline
|
||||||
return $ indent ++ p:aram ++ "\n"
|
return $ indent1 ++ p:aram ++ "\n"
|
||||||
indent <- many1 $ char ' '
|
indent1 <- many1 $ char ' '
|
||||||
string "-> "
|
void $ string "-> "
|
||||||
firstline <- restofline
|
firstline <- restofline
|
||||||
lambdalines <- many $ try $ do
|
lambdalines <- many $ try $ do
|
||||||
string indent
|
void $ string indent1
|
||||||
char ' '
|
void $ char ' '
|
||||||
l <- restofline
|
l <- restofline
|
||||||
return $ indent ++ " " ++ l
|
return $ indent1 ++ " " ++ l
|
||||||
return $ concat
|
return $ concat
|
||||||
[ prefix:preindent
|
[ prefix:preindent
|
||||||
, "(\\ " ++ lambdaparams ++ "\n"
|
, "(\\ " ++ lambdaparams ++ "\n"
|
||||||
, concat continuedlambdaparams
|
, concat continuedlambdaparams
|
||||||
, indent ++ "-> "
|
, indent1 ++ "-> "
|
||||||
, lambdaparens $ intercalate "\n" (firstline:lambdalines)
|
, lambdaparens $ intercalate "\n" (firstline:lambdalines)
|
||||||
, ")\n"
|
, ")\n"
|
||||||
]
|
]
|
||||||
|
@ -376,27 +378,27 @@ mangleCode = flip_colon
|
||||||
- layer of parens even when a lambda seems to be in parent.
|
- layer of parens even when a lambda seems to be in parent.
|
||||||
-}
|
-}
|
||||||
lambdaparenhack = parsecAndReplace $ do
|
lambdaparenhack = parsecAndReplace $ do
|
||||||
indent <- many1 $ char ' '
|
indent1 <- many1 $ char ' '
|
||||||
staticr <- string "StaticR"
|
staticr <- string "StaticR"
|
||||||
newline
|
void newline
|
||||||
string indent
|
void $ string indent1
|
||||||
yesod_dispatch_env <- restofline
|
yesod_dispatch_env <- restofline
|
||||||
string indent
|
void $ string indent1
|
||||||
lambdaprefix <- string "(\\ "
|
lambdaprefix <- string "(\\ "
|
||||||
l1 <- restofline
|
l1 <- restofline
|
||||||
string indent
|
void $ string indent1
|
||||||
lambdaarrow <- string " ->"
|
lambdaarrow <- string " ->"
|
||||||
l2 <- restofline
|
l2 <- restofline
|
||||||
l3 <- if '{' `elem` l2 && '}' `elem` l2
|
l3 <- if '{' `elem` l2 && '}' `elem` l2
|
||||||
then return ""
|
then return ""
|
||||||
else do
|
else do
|
||||||
string indent
|
void $ string indent1
|
||||||
restofline
|
restofline
|
||||||
return $ unlines
|
return $ unlines
|
||||||
[ indent ++ staticr
|
[ indent1 ++ staticr
|
||||||
, indent ++ yesod_dispatch_env
|
, indent1 ++ yesod_dispatch_env
|
||||||
, indent ++ "(" ++ lambdaprefix ++ l1
|
, indent1 ++ "(" ++ lambdaprefix ++ l1
|
||||||
, indent ++ lambdaarrow ++ l2 ++ l3 ++ ")"
|
, indent1 ++ lambdaarrow ++ l2 ++ l3 ++ ")"
|
||||||
]
|
]
|
||||||
|
|
||||||
restofline = manyTill (noneOf "\n") newline
|
restofline = manyTill (noneOf "\n") newline
|
||||||
|
@ -408,9 +410,9 @@ mangleCode = flip_colon
|
||||||
- To work around what is likely a GHC bug, just collapse
|
- To work around what is likely a GHC bug, just collapse
|
||||||
- multiline strings. -}
|
- multiline strings. -}
|
||||||
collapse_multiline_strings = parsecAndReplace $ do
|
collapse_multiline_strings = parsecAndReplace $ do
|
||||||
string "\\\n"
|
void $ string "\\\n"
|
||||||
many1 $ oneOf " \t"
|
void $ many1 $ oneOf " \t"
|
||||||
string "\\"
|
void $ string "\\"
|
||||||
return "\\n"
|
return "\\n"
|
||||||
|
|
||||||
{- GHC outputs splices using explicit braces rather than layout.
|
{- GHC outputs splices using explicit braces rather than layout.
|
||||||
|
@ -439,8 +441,8 @@ mangleCode = flip_colon
|
||||||
- all whitespace up until it.
|
- all whitespace up until it.
|
||||||
-}
|
-}
|
||||||
case_layout = parsecAndReplace $ do
|
case_layout = parsecAndReplace $ do
|
||||||
newline
|
void newline
|
||||||
indent <- many1 $ char ' '
|
indent1 <- many1 $ char ' '
|
||||||
prefix <- manyTill (noneOf "\n") (try (string "-> "))
|
prefix <- manyTill (noneOf "\n") (try (string "-> "))
|
||||||
if length prefix > 10
|
if length prefix > 10
|
||||||
then unexpected "too long a prefix"
|
then unexpected "too long a prefix"
|
||||||
|
@ -448,24 +450,24 @@ mangleCode = flip_colon
|
||||||
then unexpected "lambda expression"
|
then unexpected "lambda expression"
|
||||||
else if null prefix
|
else if null prefix
|
||||||
then unexpected "second line of lambda"
|
then unexpected "second line of lambda"
|
||||||
else return $ "\n" ++ indent ++ "; " ++ prefix ++ " -> "
|
else return $ "\n" ++ indent1 ++ "; " ++ prefix ++ " -> "
|
||||||
{- Sometimes cases themselves span multiple lines:
|
{- Sometimes cases themselves span multiple lines:
|
||||||
-
|
-
|
||||||
- Nothing
|
- Nothing
|
||||||
- -> foo
|
- -> foo
|
||||||
-}
|
-}
|
||||||
case_layout_multiline = parsecAndReplace $ do
|
case_layout_multiline = parsecAndReplace $ do
|
||||||
newline
|
void newline
|
||||||
indent <- many1 $ char ' '
|
indent1 <- many1 $ char ' '
|
||||||
firstline <- restofline
|
firstline <- restofline
|
||||||
|
|
||||||
string indent
|
void $ string indent1
|
||||||
indent2 <- many1 $ char ' '
|
indent2 <- many1 $ char ' '
|
||||||
string "-> "
|
void $ string "-> "
|
||||||
if "\\ " `isInfixOf` firstline
|
if "\\ " `isInfixOf` firstline
|
||||||
then unexpected "lambda expression"
|
then unexpected "lambda expression"
|
||||||
else return $ "\n" ++ indent ++ "; " ++ firstline ++ "\n"
|
else return $ "\n" ++ indent1 ++ "; " ++ firstline ++ "\n"
|
||||||
++ indent ++ indent2 ++ "-> "
|
++ indent1 ++ indent2 ++ "-> "
|
||||||
|
|
||||||
{- (foo, \ -> bar) is not valid haskell, GHC.
|
{- (foo, \ -> bar) is not valid haskell, GHC.
|
||||||
- Change to (foo, bar)
|
- Change to (foo, bar)
|
||||||
|
@ -497,11 +499,11 @@ mangleCode = flip_colon
|
||||||
- signature is easily inferred, so is just removed.
|
- signature is easily inferred, so is just removed.
|
||||||
-}
|
-}
|
||||||
remove_unnecessary_type_signatures = parsecAndReplace $ do
|
remove_unnecessary_type_signatures = parsecAndReplace $ do
|
||||||
string " ::"
|
void $ string " ::"
|
||||||
newline
|
void newline
|
||||||
many1 $ char ' '
|
void $ many1 $ char ' '
|
||||||
string "Text.Css.Block Text.Css.Resolved"
|
void $ string "Text.Css.Block Text.Css.Resolved"
|
||||||
newline
|
void newline
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
{- GHC may add full package and version qualifications for
|
{- GHC may add full package and version qualifications for
|
||||||
|
@ -520,15 +522,14 @@ mangleCode = flip_colon
|
||||||
|
|
||||||
qualifiedSymbol :: Parser String
|
qualifiedSymbol :: Parser String
|
||||||
qualifiedSymbol = do
|
qualifiedSymbol = do
|
||||||
s <- token
|
s <- hstoken
|
||||||
char ':'
|
void $ char ':'
|
||||||
if length s < 5
|
if length s < 5
|
||||||
then unexpected "too short to be a namespace"
|
then unexpected "too short to be a namespace"
|
||||||
else do
|
else hstoken
|
||||||
token
|
|
||||||
|
|
||||||
token :: Parser String
|
hstoken :: Parser String
|
||||||
token = do
|
hstoken = do
|
||||||
t <- satisfy isLetter
|
t <- satisfy isLetter
|
||||||
oken <- many $ satisfy isAlphaNum <|> oneOf "-.'"
|
oken <- many $ satisfy isAlphaNum <|> oneOf "-.'"
|
||||||
return $ t:oken
|
return $ t:oken
|
||||||
|
@ -561,25 +562,25 @@ mangleCode = flip_colon
|
||||||
-}
|
-}
|
||||||
yesod_url_render_hack :: String -> String
|
yesod_url_render_hack :: String -> String
|
||||||
yesod_url_render_hack = parsecAndReplace $ do
|
yesod_url_render_hack = parsecAndReplace $ do
|
||||||
string "(toHtml"
|
void $ string "(toHtml"
|
||||||
whitespace
|
void whitespace
|
||||||
string "(\\"
|
void $ string "(\\"
|
||||||
whitespace
|
void whitespace
|
||||||
wtf <- token
|
wtf <- hstoken
|
||||||
whitespace
|
void whitespace
|
||||||
string "->"
|
void $ string "->"
|
||||||
whitespace
|
void whitespace
|
||||||
renderer <- token
|
renderer <- hstoken
|
||||||
whitespace
|
void whitespace
|
||||||
string wtf
|
void $ string wtf
|
||||||
whitespace
|
void whitespace
|
||||||
return $ "(toHtml (flip " ++ renderer ++ " "
|
return $ "(toHtml (flip " ++ renderer ++ " "
|
||||||
where
|
where
|
||||||
whitespace :: Parser String
|
whitespace :: Parser String
|
||||||
whitespace = many $ oneOf " \t\r\n"
|
whitespace = many $ oneOf " \t\r\n"
|
||||||
|
|
||||||
token :: Parser String
|
hstoken :: Parser String
|
||||||
token = many1 $ satisfy isAlphaNum <|> oneOf "_"
|
hstoken = many1 $ satisfy isAlphaNum <|> oneOf "_"
|
||||||
|
|
||||||
{- Use exported symbol. -}
|
{- Use exported symbol. -}
|
||||||
text_builder_hack :: String -> String
|
text_builder_hack :: String -> String
|
||||||
|
@ -591,7 +592,7 @@ text_builder_hack = replace "Data.Text.Lazy.Builder.Internal.fromText" "Data.Tex
|
||||||
- Rather slow, but crazy powerful. -}
|
- Rather slow, but crazy powerful. -}
|
||||||
parsecAndReplace :: Parser String -> String -> String
|
parsecAndReplace :: Parser String -> String -> String
|
||||||
parsecAndReplace p s = case parse find "" s of
|
parsecAndReplace p s = case parse find "" s of
|
||||||
Left e -> s
|
Left _e -> s
|
||||||
Right l -> concatMap (either return id) l
|
Right l -> concatMap (either return id) l
|
||||||
where
|
where
|
||||||
find :: Parser [Either Char String]
|
find :: Parser [Either Char String]
|
||||||
|
|
Loading…
Add table
Reference in a new issue