From 49ea4f053ecc0bc01c6f7e6f23be851a0d853ed5 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 28 Jan 2009 23:40:14 +0000 Subject: [PATCH] Fixed the occam parser to allow comments after pragmas on the same line One of the more recent cgtests has a comment after a pragma --- frontends/ParseOccam.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index c997ccb..a8001df 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -1248,17 +1248,27 @@ pragma = do Pragma p <- genToken isPragma m <- getPosition >>* sourcePosToMeta case matchRegex (mkRegex "^SHARED +(.*)") p of Just [varsRaw] -> + let varsRawNoComment = if "--" `isInfixOf` varsRaw + then chopTrailingSpaces $ chopComment [] varsRaw + else chopTrailingSpaces varsRaw + in mapM_ (\var -> do st <- get A.Name _ n <- case lookup var (csLocalNames st) of Nothing -> dieP m $ "name " ++ var ++ " not defined" Just def -> return $ fst def modify $ \st -> st {csNameAttr = Map.insert n NameShared (csNameAttr st)}) - (splitRegex (mkRegex ",") varsRaw) + (splitRegex (mkRegex ",") varsRawNoComment) Nothing -> warnP m WarnUnknownPreprocessorDirective $ "Unknown PRAGMA: " ++ p eol where + chopComment prev ('-':'-':_) = prev + chopComment prev (x:xs) = chopComment (prev++[x]) xs + chopComment prev [] = prev + + chopTrailingSpaces = reverse . dropWhile (`elem` " \t") . reverse + isPragma (Token _ p@(Pragma {})) = Just p isPragma _ = Nothing --}}}