Compare commits

..

No commits in common. "6cd83c9d39e7845f3b6917e1b0a117e3ad31c7ef" and "2a0465ce61e822636ec1eae930e05e70bfcf617d" have entirely different histories.

10 changed files with 42 additions and 97 deletions

View File

@ -15,12 +15,3 @@ func = do
func = do
let x = 13
stmt x
#test do empty lines
func = do
<BLANKLINE>
let x = 13
<BLANKLINE>
y <- monadic
<BLANKLINE>
stmt (x + y)

View File

@ -306,14 +306,15 @@ parserCompactLocation =
[ try
$ [ ParseRelAbs (Text.Read.read digits) _ _
| digits <- many1 digit
, rel1 :: Maybe (Either Int (Ratio Int)) <- optionMaybe
[ case divPart of
Nothing -> Left $ Text.Read.read digits
Just ddigits ->
Right $ Text.Read.read digits % Text.Read.read ddigits
| digits <- many1 digit
, divPart <- optionMaybe (string "/" *> many1 digit)
]
, rel1 :: Maybe (Either Int (Ratio Int)) <-
optionMaybe
[ case divPart of
Nothing -> Left $ Text.Read.read digits
Just ddigits ->
Right $ Text.Read.read digits % Text.Read.read ddigits
| digits <- many1 digit
, divPart <- optionMaybe (string "/" *> many1 digit)
]
]
]
@ -937,22 +938,3 @@ tzejubuVxairoy
-- foo bar
=> CUR.Ozuzcak zub
-> m ()
#test allow par-spacing for HsApp HsDo
func = other $ meep
do
abc
def
(some other very long linnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnne)
#test allow par-spacing for HsApp HsDo
func = other $ meep
[ x | x <- myList ]
(some other very long linnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnne)
#test allow par-spacing for HsApp HsSpliceE
{-# LANGUAGE QuasiQuotes #-}
func = other $ meep
[q|hello
world|]
(some other very long linnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnne)

View File

@ -1252,14 +1252,15 @@ parserCompactLocation =
[ try
$ [ ParseRelAbs (Text.Read.read digits) _ _
| digits <- many1 digit
, rel1 :: Maybe (Either Int (Ratio Int)) <- optionMaybe
[ case divPart of
Nothing -> Left $ Text.Read.read digits
Just ddigits ->
Right $ Text.Read.read digits % Text.Read.read ddigits
| digits <- many1 digit
, divPart <- optionMaybe (string "/" *> many1 digit)
]
, rel1 :: Maybe (Either Int (Ratio Int)) <-
optionMaybe
[ case divPart of
Nothing -> Left $ Text.Read.read digits
Just ddigits ->
Right $ Text.Read.read digits % Text.Read.read ddigits
| digits <- many1 digit
, divPart <- optionMaybe (string "/" *> many1 digit)
]
]
]

View File

@ -226,28 +226,21 @@ hasAnyCommentsBelow =
hasCommentsBetween
:: Data ast
=> ast
-> Maybe GHC.RealSrcSpan
-> Maybe GHC.RealSrcSpan
-> Maybe GHC.RealSrcLoc
-> Maybe GHC.RealSrcLoc
-> Bool
hasCommentsBetween ast left right = do
getAny
$ SYB.everything
(<>)
(SYB.mkQ
(Any False)
(\(L (GHC.Anchor pos _) _ :: LEpaComment) -> Any
( ( maybe True
(\l -> GHC.realSrcSpanStart pos >= GHC.realSrcSpanEnd l)
left
)
&& (maybe True
(\l -> GHC.realSrcSpanEnd pos <= GHC.realSrcSpanStart l)
right
)
)
getAny $ SYB.everything
(<>)
(SYB.mkQ
(Any False)
(\(L (GHC.Anchor pos _) _ :: LEpaComment) -> Any
( (maybe True (GHC.realSrcSpanStart pos >=) left)
&& (maybe True (GHC.realSrcSpanEnd pos <=) right)
)
)
ast
)
ast
startsWithComments :: EpAnn a -> Bool
startsWithComments = \case
@ -634,11 +627,11 @@ instance DocHandleComms GHC.SrcSpan (ToBriDocM BriDocNumbered) where
-- CLASS ObtainAnnPos ----------------------------------------------------------
class ObtainAnnPos key ann where
obtainAnnPos :: ann -> key -> Maybe GHC.RealSrcSpan
obtainAnnPos :: ann -> key -> Maybe GHC.RealSrcLoc
instance ObtainAnnPos AnnKeywordId GHC.AddEpAnn where
obtainAnnPos (GHC.AddEpAnn eKW loc) kw = if eKW == kw
then Just (GHC.epaLocationRealSrcSpan loc)
then Just (epaLocationRealSrcSpanStart loc)
else Nothing
instance ObtainAnnPos AnnKeywordId (EpAnn GHC.AnnsModule) where
@ -655,7 +648,7 @@ instance ObtainAnnPos AnnKeywordId [GHC.AddEpAnn] where
obtainAnnPos list kw =
case [ loc | GHC.AddEpAnn eKW loc <- list, eKW == kw ] of
[] -> Nothing
locs -> Just (GHC.epaLocationRealSrcSpan $ minimum locs)
locs -> Just (epaLocationRealSrcSpanStart $ minimum locs)
instance ObtainAnnPos AnnKeywordId (EpAnn [GHC.AddEpAnn]) where
obtainAnnPos EpAnnNotUsed _kw = Nothing
@ -686,8 +679,7 @@ instance ObtainAnnDeltaPos (EpAnn GHC.AnnsModule) where
obtainAnnDeltaPos = \case
EpAnnNotUsed -> \_kw -> Nothing
EpAnn _ (GHC.AnnsModule l annList) epaComms -> \kw -> do
loc <- GHC.realSrcSpanStart
<$> (obtainAnnPos l kw <|> obtainAnnPos annList kw)
loc <- obtainAnnPos l kw <|> obtainAnnPos annList kw
let pos = (GHC.srcLocLine loc, GHC.srcLocCol loc)
pure $ ExactPrint.pos2delta
(maximum $ (1, 1) :
@ -712,14 +704,6 @@ instance DocFlushCommsPost (Maybe GHC.RealSrcLoc) (ToBriDocM BriDocNumbered) whe
bd <- bdm
pure (i1, BDFlushCommentsPost loc shouldMark bd)
instance DocFlushCommsPost (Maybe GHC.RealSrcSpan) (ToBriDocM BriDocNumbered) where
docFlushCommsPost shouldMark = \case
Nothing -> id
Just loc -> \bdm -> do
i1 <- allocNodeIndex
bd <- bdm
pure (i1, BDFlushCommentsPost (GHC.realSrcSpanEnd loc) shouldMark bd)
instance DocFlushCommsPost ann (ToBriDocM BriDocNumbered)
=> DocFlushCommsPost ann (ToBriDocM [BriDocNumbered]) where
docFlushCommsPost shouldMark loc bdm = do

View File

@ -291,7 +291,7 @@ layoutBriDocM = \case
PlannedNone -> PlannedNone
PlannedSameline i -> PlannedDelta n (_lstate_curY s + i)
PlannedNewline{} -> PlannedNewline n
PlannedDelta _ i -> PlannedDelta n i
PlannedDelta{} -> PlannedNewline n
}
layoutBriDocM bd
BDFlushCommentsPost loc shouldMark bd -> do

View File

@ -25,7 +25,6 @@ import GHC ( EpaCommentTok
, LHsDecl
, SrcSpanAnn'(SrcSpanAnn)
)
import qualified GHC.Types.SrcLoc as GHC
import qualified GHC.OldList as List
import GHC.Types.SrcLoc ( srcSpanFileName_maybe )
import qualified Language.Haskell.GHC.ExactPrint
@ -69,7 +68,7 @@ processModule traceFunc conf inlineConf parsedModule = do
FinalList moduleElementsStream = splitModule
shouldReformatHead
parsedModule
(fmap GHC.realSrcSpanStart $ obtainAnnPos (GHC.hsmodAnn $ GHC.unLoc parsedModule) GHC.AnnWhere)
(obtainAnnPos (GHC.hsmodAnn $ GHC.unLoc parsedModule) GHC.AnnWhere)
((out, errs), debugStrings) =
runIdentity
$ MultiRWSS.runMultiRWSTNil

View File

@ -904,12 +904,7 @@ layoutClsInst (L declLoc _) cid = do
layoutInstanceHead = case cid_ext cid of
(EpAnn annAnchor addEpAnns (EpaComments comms), sortKey) -> do
let posWhere = obtainAnnPos addEpAnns AnnWhere
let (commsBefore, commsAfter) =
partition
(\(L anch _) ->
(Just $ GHC.realSrcSpanStart $ anchor anch)
< fmap GHC.realSrcSpanStart posWhere)
comms
let (commsBefore, commsAfter) = partition (\(L anch _) -> (Just $ GHC.realSrcSpanStart $ anchor anch) < posWhere) comms
docHandleComms (reverse commsAfter)
$ briDocByExactNoComment
$ L declLoc

View File

@ -194,8 +194,6 @@ layoutExpr lexpr@(L _ expr) = do
(_, L _ ExplicitTuple{}) -> True
(_, L _ ExplicitList{}) -> True
(_, L _ HsPar{}) -> True
(_, L _ HsDo{}) -> True
(_, L _ HsSpliceE{}) -> True
_ -> False
let wrap = if all checkAllowPar paramEs then docSetParSpacing else id
wrap $ docAddBaseY BrIndentRegular $ docPar
@ -651,11 +649,7 @@ layoutExpr lexpr@(L _ expr) = do
stmtDocs <- docHandleComms stmtEpAnn $ do
stmts `forM` docHandleListElemComms (callLayouter layout_stmt)
docSetParSpacing $ docAddBaseY BrIndentRegularForce $ docPar
( docFlushCommsPost True locDo
$ docHandleComms locDo
$ docLit
$ Text.pack "do"
)
(docHandleComms locDo $ docLit $ Text.pack "do")
( docSetBaseAndIndent
$ docNonBottomSpacing
$ docLines

View File

@ -20,7 +20,7 @@ layoutStmt lstmt@(L _ stmt) = do
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
indentAmount :: Int <-
mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack
docFlushCommsPost True lstmt $ case stmt of
case stmt of
LastStmt NoExtField body Nothing _ -> do
-- at least the "|" of a monadcomprehension for _some_ reason
-- is connected to the _body_ of the "result" stmt. So we need

View File

@ -245,17 +245,16 @@ main = do
| _ <- Parsec.try $ Parsec.string "#expected"
, _ <- Parsec.eof
]
, [ NormalLine mempty
| _ <- Parsec.many $ Parsec.oneOf " \t"
, _ <- Parsec.try $ Parsec.string "<BLANKLINE>"
, _ <- Parsec.eof
]
, [ CommentLine
| _ <- Parsec.many $ Parsec.oneOf " \t"
, _ <- Parsec.optional $ Parsec.string "##" <* many
(Parsec.noneOf "\r\n")
, _ <- Parsec.eof
]
, [ NormalLine mempty
| _ <- Parsec.try $ Parsec.string "<BLANKLINE>"
, _ <- Parsec.eof
]
]
lineMapper :: Text -> InputLine
lineMapper line = case Parsec.runParser specialLineParser () "" line of