Skip to content

Implementation of string is not ideal #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
natefaubion opened this issue Apr 10, 2020 · 0 comments · Fixed by #93
Closed

Implementation of string is not ideal #92

natefaubion opened this issue Apr 10, 2020 · 0 comments · Fixed by #93
Labels
type: enhancement A new feature or addition.

Comments

@natefaubion
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A new feature or addition.
Development

Successfully merging a pull request may close this issue.

2 participants