Skip to content

Commit 2b658fb

Browse files
committed
Parser: parseFromText: (=<< -> <$>)
1 parent d5d853d commit 2b658fb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/Nix/Parser.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ reservedNames = HashSet.fromList
528528

529529
type Parser = ParsecT Void Text (State SourcePos)
530530

531+
-- This is just a @Either (Doc Void) a@
531532
data Result a = Success a | Failure (Doc Void) deriving (Show, Functor)
532533

533534
parseFromFileEx :: MonadFile m => Parser a -> FilePath -> m (Result a)
@@ -540,10 +541,11 @@ parseFromFileEx p path = do
540541

541542
parseFromText :: Parser a -> Text -> Result a
542543
parseFromText p txt =
543-
let file = "<string>"
544-
in either (Failure . pretty . errorBundlePretty) Success
545-
. flip evalState (initialPos file)
546-
$ runParserT p file txt
544+
let file = "<string>" in
545+
either
546+
(Failure . pretty . errorBundlePretty)
547+
Success
548+
$ (`evalState` initialPos file) $ (`runParserT` file) p txt
547549

548550
{- Parser.Operators -}
549551

@@ -560,11 +562,12 @@ data NOperatorDef
560562
deriving (Eq, Ord, Generic, Typeable, Data, Show, NFData)
561563

562564
annotateLocation :: Parser a -> Parser (Ann SrcSpan a)
563-
annotateLocation p = do
564-
begin <- getSourcePos
565-
res <- p
566-
end <- get -- The state set before the last whitespace
567-
pure $ Ann (SrcSpan begin end) res
565+
annotateLocation p =
566+
do
567+
begin <- getSourcePos
568+
end <- get -- The state set before the last whitespace
569+
570+
Ann (SrcSpan begin end) <$> p
568571

569572
annotateLocation1 :: Parser (NExprF NExprLoc) -> Parser NExprLoc
570573
annotateLocation1 = fmap annToAnnF . annotateLocation

0 commit comments

Comments
 (0)