fixing comment removal within strings and such, closes #176

This commit is contained in:
Andrew Gibiansky 2014-02-06 22:34:39 -08:00
parent 62b063c0bf
commit 70ddc14f77
2 changed files with 40 additions and 1 deletions

View File

@ -14,6 +14,16 @@ rm -f profile.tar
tar -cvf profile.tar *
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
cabal clean
cabal install --force-reinstalls

View File

@ -198,15 +198,35 @@ removeComments = removeOneLineComments . removeMultilineComments 0
case str of
-- Don't remove comments after cmd directives
':':'!':remaining ->":!" ++ takeLine remaining ++ dropLine remaining
-- Handle strings.
'"':remaining ->
let quoted = takeString remaining
len = length quoted in
'"':quoted ++ removeOneLineComments (drop len remaining)
'-':'-':remaining -> dropLine remaining
x:xs -> x:removeOneLineComments xs
[] -> []
where
dropLine = removeOneLineComments . dropWhile (/= '\n')
takeLine = takeWhile (/= '\n')
removeMultilineComments nesting str =
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 ->
if nesting > 0
@ -217,3 +237,12 @@ removeComments = removeOneLineComments . removeMultilineComments 0
then 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
[] -> []