purescript-contrib/purescript-parsing

Implementation of `string` is not ideal

natefaubion opened this issue · 0 comments

string :: forall s m. StringLike s => Monad m => String -> ParserT s m String
string str = do
input <- gets \(ParseState input _ _) -> input
case indexOf (wrap str) input of
Just 0 -> do
modify_ \(ParseState _ position _) ->
ParseState (drop (length str) input)
(updatePosString position str)
true
pure str
_ -> fail ("Expected " <> show str)

This will perform a linear scan to find a match anywhere, before checking if that match is at index 0. It should probably just take whatever the length of the desired token is and check for eq.