Remove obsolete checks for Parser.{some,many}

This commit is contained in:
Kirill Andreev 2020-05-08 20:13:29 +04:00
parent 6dc1eb23cd
commit 7ff8226e1b
No known key found for this signature in database
GPG Key ID: CF7DA79DE4785A47

View File

@ -195,68 +195,25 @@ optional p = fmap Just p <|> return Nothing
-- | Custom `Alternative.many`. -- | Custom `Alternative.many`.
-- --
-- TODO: remove msg.
--
many :: Parser a -> Parser [a] many :: Parser a -> Parser [a]
many p = many' many p = many'
where where
many' = some' <|> pure [] many' = some' <|> pure []
some' = do some' = do
hasPossibleInput x <- p
(x, consumed) <- productive p xs <- many'
if consumed then do return (x : xs)
xs <- many'
return (x : xs)
else do
return [x]
-- | Custom `Alternative.some`. -- | Custom `Alternative.some`.
-- --
-- TODO: remove msg.
--
some :: Parser a -> Parser [a] some :: Parser a -> Parser [a]
some p = some' some p = some'
where where
many' = some' <|> pure [] many' = some' <|> pure []
some' = do some' = do
hasPossibleInput x <- p
(x, consumed) <- productive p xs <- many'
if consumed then do return (x : xs)
xs <- many'
return (x : xs)
else do
return [x]
-- | Get UID of current tree. Obsolete.
--
-- TODO: remove.
--
getTreeID :: Parser (Maybe Int)
getTreeID = Parser do
pfGrove <$> get >>= return . \case
[] -> Nothing
(_, tree) : _ -> Just (ptID tree)
-- | Assert the parser consumes input. Obsolete.
--
-- TODO: remove.
--
productive :: Parser a -> Parser (a, Bool)
productive p = do
was <- getTreeID
res <- p
now <- getTreeID
return (res, was /= now)
-- | The `not <$> eos`. Obsolete.
--
-- TODO: remove.
--
hasPossibleInput :: Parser ()
hasPossibleInput = do
yes <- gets (not . null . pfGrove)
unless yes do
die "something"
-- | The source of file being parsed. BS, because tree-sitter has offsets -- | The source of file being parsed. BS, because tree-sitter has offsets
-- in /bytes/. -- in /bytes/.