Newest at the top
2025-02-26 00:28:14 +0100 | alfiee | (~alfiee@user/alfiee) (Ping timeout: 252 seconds) |
2025-02-26 00:23:46 +0100 | alfiee | (~alfiee@user/alfiee) alfiee |
2025-02-26 00:21:03 +0100 | merijn | (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 244 seconds) |
2025-02-26 00:20:18 +0100 | rvalue | (~rvalue@user/rvalue) (Quit: ZNC - https://znc.in) |
2025-02-26 00:16:46 +0100 | merijn | (~merijn@host-vr.cgnat-g.v4.dfn.nl) merijn |
2025-02-26 00:12:53 +0100 | <tomsmeding> | but yes, a splitting function is perhaps nicer here |
2025-02-26 00:12:43 +0100 | <monochrom> | Although, I confess that I want 0 dependencies so I wrote my own recursion :) |
2025-02-26 00:12:40 +0100 | <tomsmeding> | hololeap: https://paste.tomsmeding.com/QHaiHEVF |
2025-02-26 00:12:12 +0100 | <monochrom> | You can write your own recursion over span. But the split package does that for you. |
2025-02-26 00:11:39 +0100 | <monochrom> | Oh, the split package has tools for that too. |
2025-02-26 00:11:37 +0100 | <tomsmeding> | if you write out that <$> <*> sequence as a do-block, it gets much more readable |
2025-02-26 00:10:57 +0100 | <hololeap> | although I wonder if it would be more readable to just do this with span from Data.List |
2025-02-26 00:10:44 +0100 | <monochrom> | BTW the "convenience" of regex allowing that is avenged by the fact that such high non-determinism causes exp-time or exp-space. |
2025-02-26 00:10:43 +0100 | <tomsmeding> | monochrom: thanks, it's been too long since I parsec'd, this is also nicer to write |
2025-02-26 00:10:32 +0100 | <hololeap> | cool, thanks :) |
2025-02-26 00:10:29 +0100 | foul_owl | (~kerry@174-21-138-88.tukw.qwest.net) foul_owl |
2025-02-26 00:10:20 +0100 | <tomsmeding> | hololeap: there |
2025-02-26 00:10:09 +0100 | <yahb2> | Right [("this","that"),("black","white")] |
2025-02-26 00:10:09 +0100 | <tomsmeding> | % parse (sepBy ((,) <$> (many (satisfy (/= ':')) <* char ':') <*> many (satisfy (`notElem` ":,"))) (char ',')) "<stdin>" "this:that,black:white" |
2025-02-26 00:09:49 +0100 | <monochrom> | What you should really lament, if you like, is that parsec is not regex, so whereas in regex you just have to say ".*,.*", you simply can't do that in parsec. |
2025-02-26 00:08:59 +0100 | <tomsmeding> | I guess |
2025-02-26 00:08:50 +0100 | <monochrom> | many (satisfy (/= ',')) pretty please |
2025-02-26 00:08:26 +0100 | <monochrom> | Yikes, abuse of lookAhead again. |
2025-02-26 00:08:23 +0100 | <yahb2> | <interactive>:289:99: error: [GHC-83865] ; • Couldn't match type ‘()’ with ‘Char’ ; Expected: ParsecT ; String () GHC.Internal.Data.Functor.Identity.Identity Char ; ... |
2025-02-26 00:08:23 +0100 | <tomsmeding> | % parse (sepBy ((,) <$> manyTill anyChar (char ':') <*> manyTill anyChar (lookAhead (oneOf ":," <|> eof))) (char ',')) "<stdin>" "this:that,black:white" |
2025-02-26 00:08:07 +0100 | <tomsmeding> | evidently not! |
2025-02-26 00:07:56 +0100 | <yahb2> | <interactive>:287:23: error: [GHC-83865] ; • Couldn't match expected type: ParsecT ; String () GHC.Internal.Data.Functor.Identity.Identity a1 ; ... |
2025-02-26 00:07:56 +0100 | <tomsmeding> | % parse (sepBy ((,) <$> manyTill (char ':') <*> manyTill (lookAhead (oneOf ":," <|> eof))) (char ',')) "<stdin>" "this:that,black:white" |
2025-02-26 00:07:41 +0100 | <tomsmeding> | hm, let's see if I can whiteboard code |
2025-02-26 00:07:24 +0100 | <yahb2> | Right ["abc,def,ghi"] |
2025-02-26 00:07:24 +0100 | <tomsmeding> | % parse (sepBy (many anyChar) (char ',')) "<stdin>" "abc,def,ghi" |
2025-02-26 00:07:16 +0100 | <yahb2> | <no output> |
2025-02-26 00:07:16 +0100 | <tomsmeding> | % import Text.Parsec |
2025-02-26 00:06:24 +0100 | <tomsmeding> | hololeap: also, that "sepBy (many anyChar) (char ',')" wouldn't even work: the `many anyChar` would consume the entire input from here, and because it consumed input, it would count as "succeeded" which means it doesn't backtrack |
2025-02-26 00:05:52 +0100 | merijn | (~merijn@host-vr.cgnat-g.v4.dfn.nl) (Ping timeout: 252 seconds) |
2025-02-26 00:05:03 +0100 | <tomsmeding> | of course you technically can just start a new parser for that string, and you can also `setInput`, but typically both are a bad idea |
2025-02-26 00:04:22 +0100 | <hololeap> | I see |
2025-02-26 00:03:56 +0100 | <tomsmeding> | you can't "re-inject" some arbitrary string into the source to be parsed |
2025-02-26 00:03:13 +0100 | ljdarj1 | ljdarj |
2025-02-26 00:03:13 +0100 | ljdarj | (~Thunderbi@user/ljdarj) (Ping timeout: 248 seconds) |
2025-02-26 00:03:04 +0100 | <tomsmeding> | also, while you can process the result of parsing later using (>>=), parsec always parses _from_ the input string |
2025-02-26 00:02:55 +0100 | <hololeap> | right, s/anyChar/(many anyChar)/ |
2025-02-26 00:02:28 +0100 | <tomsmeding> | anyChar parses _one_ character |
2025-02-26 00:02:18 +0100 | <hololeap> | hm, you would think with Parsec being a monad, it could be done with: sepBy anyChar (char ',') >>= mapM (...) |
2025-02-26 00:01:26 +0100 | ljdarj1 | (~Thunderbi@user/ljdarj) ljdarj |
2025-02-26 00:01:24 +0100 | merijn | (~merijn@host-vr.cgnat-g.v4.dfn.nl) merijn |
2025-02-26 00:00:53 +0100 | <tomsmeding> | hololeap: sepBy ((,) <$> manyTill (char ':') <*> manyTill (lookAhead (oneOf ":," <|> eof))) (char ',') ? |
2025-02-25 23:59:32 +0100 | <hololeap> | and I'm not sure how to then split the substrings on (char ':') |
2025-02-25 23:59:12 +0100 | <hololeap> | I started with: sepBy anyChar (char ',') |
2025-02-25 23:58:49 +0100 | <hololeap> | I'm trying to parse a string with parsec that looks like "this:that,black:white" into [(String,String)] |