Remove obsolete checks for Parser.{some,many}
This commit is contained in:
parent
6dc1eb23cd
commit
7ff8226e1b
@ -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
|
|
||||||
if consumed then do
|
|
||||||
xs <- many'
|
xs <- many'
|
||||||
return (x : xs)
|
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
|
|
||||||
if consumed then do
|
|
||||||
xs <- many'
|
xs <- many'
|
||||||
return (x : xs)
|
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/.
|
||||||
|
Loading…
Reference in New Issue
Block a user