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

Add between parser combinator to Data.String.Parser #3414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion libs/contrib/Data/String/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,17 @@ covering
spaces1 : Monad m => ParseT m ()
spaces1 = skip (some space) <?> "whitespaces"


||| Run the parser p between the opening parser `o` and the closing parser `c`,
||| returning the result of p.
export
between : Monad m => ParseT m o -> ParseT m c -> ParseT m p -> ParseT m p
between o c p = id <$ o <*> p <* c

||| Discards brackets around a matching parser
export
parens : Monad m => ParseT m a -> ParseT m a
parens p = char '(' *> p <* char ')'
parens p = between (char '(') (char ')') p

||| Discards whitespace after a matching parser
export
Expand Down Expand Up @@ -406,3 +413,4 @@ export
ntimes : Monad m => (n : Nat) -> ParseT m a -> ParseT m (Vect n a)
ntimes Z p = pure Vect.Nil
ntimes (S n) p = [| p :: (ntimes n p) |]

Loading