@@ -21,12 +21,10 @@ import Data.Either (partitionEithers)
21import Data.List (isPrefixOf, sortOn, dropWhileEnd)
21import Data.List (isPrefixOf, sortOn, dropWhileEnd)
22import Data.List.NonEmpty (NonEmpty (..))
22import Data.List.NonEmpty (NonEmpty (..))
23import Data.Maybe (mapMaybe)
23import Data.Maybe (mapMaybe)
25−import Ormolu.Parser.LanguagePragma
24+import Ormolu.Parser.Pragma
26import Ormolu.Utils (showOutputable)
25import Ormolu.Utils (showOutputable)
27import SrcLoc
26import SrcLoc
28import qualified Data.List.NonEmpty as NE
27import qualified Data.List.NonEmpty as NE
29−import qualified Data.Set as S
30import qualified GHC
28import qualified GHC
31import qualified Lexer as GHC
29import qualified Lexer as GHC
@@ -49,7 +47,7 @@ newtype Comment = Comment (NonEmpty String)
49mkCommentStream
47mkCommentStream
50 :: [Located String] -- ^ Extra comments to include
48 :: [Located String] -- ^ Extra comments to include
51 -> GHC.PState -- ^ Parser state to use for comment extraction
49 -> GHC.PState -- ^ Parser state to use for comment extraction
52− -> (CommentStream, Set String)
50+ -> (CommentStream, [Pragma])
53 -- ^ Comment stream and a set of extensions enabled
51 -- ^ Comment stream and a set of extensions enabled
54mkCommentStream extraComments pstate =
52mkCommentStream extraComments pstate =
55 ( CommentStream $
53 ( CommentStream $
@@ -57,10 +55,10 @@ mkCommentStream extraComments pstate =
57 -- streams. Because this way we need to do it only once and when we
55 -- streams. Because this way we need to do it only once and when we
58 -- perform checking later they'll automatically match.
56 -- perform checking later they'll automatically match.
59 mkComment <$> sortOn (realSrcSpanStart . getLoc) comments
57 mkComment <$> sortOn (realSrcSpanStart . getLoc) comments
60− , S.unions exts
58+ , pragma
63− (comments, exts) = partitionEithers (partitionComments <$> rawComments)
61+ (comments, pragma) = partitionEithers (partitionComments <$> rawComments)
64 rawComments = mapMaybe toRealSpan $
62 rawComments = mapMaybe toRealSpan $
65 extraComments ++
63 extraComments ++
66 (fmap unAnnotationComment <$> GHC.comment_q pstate) ++
64 (fmap unAnnotationComment <$> GHC.comment_q pstate) ++
@@ -121,13 +119,13 @@ toRealSpan :: Located a -> Maybe (RealLocated a)
121toRealSpan (L (RealSrcSpan l) a) = Just (L l a)
119toRealSpan (L (RealSrcSpan l) a) = Just (L l a)
122toRealSpan _ = Nothing
120toRealSpan _ = Nothing
124−-- | If a given comment is a LANGUAGE pragma, return the set of extensions
122+-- | If a given comment is a pragma, return the set of extensions
125-- it enables in 'Right'. Otherwise return the original comment unchanged.
123-- it enables in 'Right'. Otherwise return the original comment unchanged.
127partitionComments
125partitionComments
128 :: RealLocated String
126 :: RealLocated String
129− -> Either (RealLocated String) (Set String)
127+ -> Either (RealLocated String) Pragma
130partitionComments input =
128partitionComments input =
131− case parseLanguagePragma (unLoc input) of
129+ case parsePragma (unLoc input) of
132 Nothing -> Left input
130 Nothing -> Left input
133− Just exts -> Right exts
131+ Just pr -> Right pr