@@ -16,6 +16,7 @@ import Control.Monad.IO.Class
1616import qualified Data.List as L
1717import qualified Data.List.NonEmpty as NE
1818import Data.Ord (Down (Down))
19+import qualified Data.Text as T
1920import DynFlags as GHC
2021import ErrUtils (Severity (..), errMsgSeverity, errMsgSpan)
2122import qualified FastString as GHC
@@ -31,6 +32,7 @@ import Ormolu.Parser.Anns
3132import Ormolu.Parser.CommentStream
3233import Ormolu.Parser.Result
3334import Ormolu.Processing.Preprocess (preprocess)
35+import Ormolu.Utils (incSpanLine)
3436import qualified Panic as GHC
3537import qualified Parser as GHC
3638import qualified StringBuffer as GHC
@@ -39,7 +41,7 @@ import qualified StringBuffer as GHC
3941parseModule ::
4042 MonadIO m =>
4143 -- | Ormolu configuration
42− Config ->
44+ Config RegionDeltas ->
4345 -- | File name (only for source location annotations)
4446 FilePath ->
4547 -- | Input for parser
@@ -48,8 +50,9 @@ parseModule ::
4850 ( [GHC.Warn],
4951 Either (SrcSpan, String) ParseResult
5052 )
51−parseModule Config {..} path input' = liftIO $ do
52− let (input, extraComments) = preprocess path input'
53+parseModule Config {..} path rawInput = liftIO $ do
54+ let (literalPrefix, input, literalSuffix, extraComments) =
55+ preprocess path rawInput cfgRegion
5356 -- It's important that 'setDefaultExts' is done before
5457 -- 'parsePragmasIntoDynFlags', because otherwise we might enable an
5558 -- extension that was explicitly disabled in the file.
@@ -59,7 +62,7 @@ parseModule Config {..} path input' = liftIO $ do
5962 (setDefaultExts baseDynFlags)
6063 extraOpts = dynOptionToLocatedStr <$> cfgDynOptions
6164 (warnings, dynFlags) <-
62− parsePragmasIntoDynFlags baseFlags extraOpts path input' >>= \case
65+ parsePragmasIntoDynFlags baseFlags extraOpts path rawInput >>= \case
6366 Right res -> pure res
6467 Left err ->
6568 let loc =
@@ -74,14 +77,17 @@ parseModule Config {..} path input' = liftIO $ do
7477 (pluginModNames dynFlags)
7578 pStateErrors = \pstate ->
7679 let errs = bagToList $ GHC.getErrorMessages pstate dynFlags
80+ fixupErrSpan = incSpanLine (regionPrefixLength cfgRegion)
7781 in case L.sortOn (Down . SeverityOrd . errMsgSeverity) errs of
7882 [] -> Nothing
79− err : _ -> Just (errMsgSpan err, show err) -- Show instance returns a short error message
83+ err : _ ->
84+ -- Show instance returns a short error message
85+ Just (fixupErrSpan (errMsgSpan err), show err)
8086 r = case runParser GHC.parseModule dynFlags path input of
8187 GHC.PFailed pstate ->
8288 case pStateErrors pstate of
8389 Just err -> Left err
84− Nothing -> error "invariant violation: PFailed does not have an error"
90+ Nothing -> error "PFailed does not have an error"
8591 GHC.POk pstate pmod ->
8692 case pStateErrors pstate of
8793 -- Some parse errors (pattern/arrow syntax in expr context)
@@ -102,7 +108,9 @@ parseModule Config {..} path input' = liftIO $ do
102108 prCommentStream = comments,
103109 prUseRecordDot = useRecordDot,
104110 prImportQualifiedPost =
105− GHC.xopt ImportQualifiedPost dynFlags
111+ GHC.xopt ImportQualifiedPost dynFlags,
112+ prLiteralPrefix = T.pack literalPrefix,
113+ prLiteralSuffix = T.pack literalSuffix
106114 }
107115 return (warnings, r)
108116