Commit 70ddc14f authored by Andrew Gibiansky's avatar Andrew Gibiansky

fixing comment removal within strings and such, closes #176

parent 62b063c0
...@@ -14,6 +14,16 @@ rm -f profile.tar ...@@ -14,6 +14,16 @@ rm -f profile.tar
tar -cvf profile.tar * tar -cvf profile.tar *
cd .. cd ..
if [ $# -gt 0 ]; then
if [ $1 = "all" ]; then
cd ghc-parser;
cabal install --force-reinstalls;
cd ../ghci-lib;
cabal install --force-reinstalls;
cd ..;
fi
fi
# Make ihaskell itself # Make ihaskell itself
cabal clean cabal clean
cabal install --force-reinstalls cabal install --force-reinstalls
......
...@@ -198,15 +198,35 @@ removeComments = removeOneLineComments . removeMultilineComments 0 ...@@ -198,15 +198,35 @@ removeComments = removeOneLineComments . removeMultilineComments 0
case str of case str of
-- Don't remove comments after cmd directives -- Don't remove comments after cmd directives
':':'!':remaining ->":!" ++ takeLine remaining ++ dropLine remaining ':':'!':remaining ->":!" ++ takeLine remaining ++ dropLine remaining
-- Handle strings.
'"':remaining ->
let quoted = takeString remaining
len = length quoted in
'"':quoted ++ removeOneLineComments (drop len remaining)
'-':'-':remaining -> dropLine remaining '-':'-':remaining -> dropLine remaining
x:xs -> x:removeOneLineComments xs x:xs -> x:removeOneLineComments xs
[] -> [] [] -> []
where where
dropLine = removeOneLineComments . dropWhile (/= '\n') dropLine = removeOneLineComments . dropWhile (/= '\n')
takeLine = takeWhile (/= '\n')
removeMultilineComments nesting str = removeMultilineComments nesting str =
case str of case str of
-- Don't remove comments after cmd directives
':':'!':remaining ->":!" ++ takeLine remaining ++
removeMultilineComments nesting (dropWhile (/= '\n') remaining)
-- Handle strings.
'"':remaining ->
if nesting == 0
then
let quoted = takeString remaining
len = length quoted in
'"':quoted ++ removeMultilineComments nesting (drop len remaining)
else
removeMultilineComments nesting remaining
'{':'-':remaining -> removeMultilineComments (nesting + 1) remaining '{':'-':remaining -> removeMultilineComments (nesting + 1) remaining
'-':'}':remaining -> '-':'}':remaining ->
if nesting > 0 if nesting > 0
...@@ -217,3 +237,12 @@ removeComments = removeOneLineComments . removeMultilineComments 0 ...@@ -217,3 +237,12 @@ removeComments = removeOneLineComments . removeMultilineComments 0
then removeMultilineComments nesting xs then removeMultilineComments nesting xs
else x:removeMultilineComments nesting xs else x:removeMultilineComments nesting xs
[] -> [] [] -> []
takeLine = takeWhile (/= '\n')
-- Take a part of a string that ends in an unescaped quote.
takeString str = case str of
escaped@('\\':'"':rest) -> escaped
'"':rest -> "\""
x:xs -> x:takeString xs
[] -> []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment