-
Notifications
You must be signed in to change notification settings - Fork 24
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
Parsing into a list delimited by a token #46
Comments
Hey! Several parser combinator libraries define a function called Your approach might work as well. If you e.g. want to parse qualified names, you could first parse a list of allowed characters including Hope this helps! |
The sepBy :: Alternative m => m a -> m sep -> m [a]
sepBy p sep = sepBy1 p sep <|> pure []
sepBy1 :: Alternative m => m a -> m sep -> m [a]
sepBy1 p sep = liftA2 (:) p (many (sep *> p))
dparse :: (String -> Bool) -> Prod r String String [String]
dparse f = sepBy (satisfy f) (token ".") |
Maybe you meant for your parser to work on |
Probably? Right now I'm trying to get it to parse
into
So what you're saying is I shouldn't feed |
Yeah, I got it to work with sepBy :: Alternative m => m a -> m sep -> m [a]
sepBy p sep = sepBy1 p sep <|> pure []
sepBy1 :: Alternative m => m a -> m sep -> m [a]
sepBy1 p sep = liftA2 (:) p (many (sep *> p))
someBy :: Eq a => a -> Prod r e a [[a]]
someBy s = sepBy (some $ satisfy $ (/=) s) (token s) I just have to properly handle whitespace now. Thank you! |
I'm a very novice Haskell programmer and I wanted to write something with parsers. My current solution for parsing
abc.def.ghi
uses thesplit
package like so:I feel like, from my Scala+cats knowledge, that this is a very poor way to do this. How should I properly implement it?
The text was updated successfully, but these errors were encountered: