Skip to content
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

Support maximum repetition count #38

Open
josephcsible opened this issue Oct 31, 2019 · 6 comments
Open

Support maximum repetition count #38

josephcsible opened this issue Oct 31, 2019 · 6 comments

Comments

@josephcsible
Copy link

Consider the regex \d{,6}. I'd like this library to contain a function replicateAlt that lets me implement this regex as replicateAlt 6 digit. One possible implementation would be a duplicate of replicateM, but with <|> pure [] on the end of the recursive case.

If you like this idea, I can PR it, but I'm not sure which module you want it in.

@UnkindPartition
Copy link
Owner

Does this do what you want?

I'd accept a PR explaining (in the haddocks) how to do this for others who may be looking for the same thing.

@josephcsible
Copy link
Author

josephcsible commented Oct 31, 2019

Yes, that's what I need for now. Although it looks like they only have a greedy one, so if I instead needed the non-greedy \d{,6}?, I'd be right back to needing to roll my own.

@UnkindPartition
Copy link
Owner

Ah, good point. In that case it may be worth defining our own function.

@stuart-little
Copy link

I dropped in intending to ask this in a separate issue, but this seems like a good spot:

What is the best way to quantify numerically? I know you can cobble something together out of what's already there. For instance, to match exactly n digits I can do

ghci> dig :: RE Char String; dig = pure <$> psym isDigit
ghci> <string> =~ (foldr1 (<>) $ replicate n dig)

But is this more or less it? Or is there some count-style combinator already built in, that I'm missing in the docs?

@UnkindPartition
Copy link
Owner

Have you seen the count combinator linked above?

@stuart-little
Copy link

Have you seen the count combinator linked above?

My apologies: I did see it, but did not understand the context..

I hadn't realized it applies to all instances of alternative. I thought it was more like the count I linked to, which was specific to ReadP.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants