Skip to content

Some stack-safe sequence combinators #130

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

Merged
merged 4 commits into from
Jan 7, 2022

Conversation

fsoikin
Copy link
Contributor

@fsoikin fsoikin commented Jan 6, 2022

Description of the change

Combinators dealing with sequences, such as many1, manyTill, sepBy, etc. are stack-unsafe. When given a long enough input, they will overflow the stack.

Data.List offers similar general combinators many and some, and provides a patch for this problem in the form of stack-safe counterparts - manyRec and someRec respectively, - which are made stack-safe at the expense of an additional MonadRec constraint.

Following this pattern, this PR adds stack-safe counterparts for some of the parser combinators - specifically, sepEndByRec, sepEndBy1Rec, manyTillRec, and many1TillRec.

These are not all the sequence combinators exported from Text.Parsing.Parser.Combinators, but only those that we needed for our purposes at my slave dungeoun day job. I figured I'd contribute them back to the library since it's very low effort to do so.

If the High Counsil pleases, I can take it upon myself to develop similar counterparts for the other sequence combinators.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

@jamesdbrock
Copy link
Member

Thanks! I will check this and merge.

I can take it upon myself to develop similar counterparts for the other sequence combinators.

Yes please. I'm familiar with your work and I trust your judgement and I will try to merge any improvements you want to make to this package.

@jamesdbrock jamesdbrock merged commit 618bcf4 into purescript-contrib:main Jan 7, 2022
@jamesdbrock
Copy link
Member

@fsoikin fsoikin deleted the rec-combinators branch January 7, 2022 15:32
@fsoikin fsoikin mentioned this pull request Jan 7, 2022
4 tasks
@fsoikin
Copy link
Contributor Author

fsoikin commented Jan 7, 2022

Wow, thank you for the kind word :-)

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

Successfully merging this pull request may close these issues.

2 participants