From ce61a7c2f5c1348e32d4ed8b466465a33c0e5e35 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sun, 29 Apr 2007 00:05:44 +0000 Subject: [PATCH] Fix string and char literal handling in finishLine --- fco2/Indentation.hs | 31 ++++++++++++++++++------------- fco2/testcases/stringlit.occ | 9 ++++++++- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/fco2/Indentation.hs b/fco2/Indentation.hs index 21d991f..224b98d 100644 --- a/fco2/Indentation.hs +++ b/fco2/Indentation.hs @@ -66,16 +66,21 @@ removeIndentation filename orig case psIndentLinesOut ps of (l:ls) -> ((l ++ s):ls) }) -- | Given a line, read the rest of it, then return the complete thing. - finishLine :: String -> String -> Bool -> String -> PassM String - finishLine left soFar inStr afterStr - = case (left, inStr) of - ([], False) -> plainEOL - ('-':'-':cs, False) -> plainEOL - ([], True) -> die "end of line in string without continuation" - (['*'], True) -> stringEOL - ('"':cs, iS) -> finishLine cs (afterStr ++ ('"':soFar)) (not iS) "" - ('*':'"':cs, True) -> finishLine cs ('"':'*':soFar) True afterStr - (c:cs, iS) -> finishLine cs (c:soFar) iS afterStr + finishLine :: String -> String -> Bool -> Bool -> String -> PassM String + finishLine left soFar inStr isChar afterStr + = case (left, inStr, isChar) of + ([], False, _) -> plainEOL + ('-':'-':cs, False, _) -> plainEOL + ([], True, _) -> die "end of line in string without continuation" + (['*'], True, _) -> stringEOL + ('\'':cs, False, _) -> finishLine cs (afterStr ++ ('\'':soFar)) True True "" + ('\'':cs, True, True) -> finishLine cs (afterStr ++ ('\'':soFar)) False False "" + ('"':cs, False, _) -> finishLine cs (afterStr ++ ('"':soFar)) True False "" + ('"':cs, True, False) -> finishLine cs (afterStr ++ ('"':soFar)) False False "" + ('*':'*':cs, True, _) -> finishLine cs ('*':'*':soFar) True isChar afterStr + ('*':'"':cs, True, _) -> finishLine cs ('"':'*':soFar) True isChar afterStr + ('*':'\'':cs, True, _) -> finishLine cs ('\'':'*':soFar) True isChar afterStr + (c:cs, _, _) -> finishLine cs (c:soFar) inStr isChar afterStr where -- | Finish a regular line. plainEOL :: PassM String @@ -83,7 +88,7 @@ removeIndentation filename orig = do let s = reverse soFar if hasContinuation s then do l <- getLine >>= checkJust "no continuation line" - finishLine l ('\n':soFar) False "" + finishLine l ('\n':soFar) False False "" else return s -- | Finish a line where we're in the middle of a string. @@ -93,7 +98,7 @@ removeIndentation filename orig l' <- contStringStart l -- When we hit the end of the string, add a \n after it to -- make the line numbers match up again. - finishLine l' soFar True ('\n':afterStr) + finishLine l' soFar True isChar ('\n':afterStr) -- | Does a line have a continuation line following it? hasContinuation :: String -> Bool @@ -119,7 +124,7 @@ removeIndentation filename orig = do line <- getLine case line of Just s -> - do r <- finishLine s "" False "" + do r <- finishLine s "" False False "" return $ Just r Nothing -> return Nothing diff --git a/fco2/testcases/stringlit.occ b/fco2/testcases/stringlit.occ index f45aa87..5f60584 100644 --- a/fco2/testcases/stringlit.occ +++ b/fco2/testcases/stringlit.occ @@ -1,4 +1,11 @@ PROC P () - VAL []BYTE s IS "*c*n*t*s*X*#00*#A0\now": + VAL []BYTE s IS "***c*n*t*s*X*#00*#A0\now": + VAL []BYTE ss IS "'": + VAL []BYTE ssx IS "*'": + VAL []BYTE sss IS "foo**": + VAL BYTE c IS 'x': + VAL BYTE cc IS '"': + VAL BYTE ccx IS '*"': + VAL BYTE ccc IS '*'': SKIP :