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

Use existential type variable for IndentOpt #571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions Text/Megaparsec/Char/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,22 @@ nonIndented sc p = indentGuard sc EQ pos1 *> p
-- 'indentBlock', which see.
--
-- @since 4.3.0
data IndentOpt m a b
data IndentOpt m a
= -- | Parse no indented tokens, just return the value
IndentNone a
| -- | Parse many indented tokens (possibly zero), use given indentation
-- level (if 'Nothing', use level of the first indented token); the
-- second argument tells how to get the final result, and the third
-- argument describes how to parse an indented token
IndentMany (Maybe Pos) ([b] -> m a) (m b)
forall b. IndentMany (Maybe Pos) ([b] -> m a) (m b)
| -- | Just like 'IndentMany', but requires at least one indented token to
-- be present
IndentSome (Maybe Pos) ([b] -> m a) (m b)
forall b. IndentSome (Maybe Pos) ([b] -> m a) (m b)

instance Functor m => Functor (IndentOpt m) where
fmap f (IndentNone x) = IndentNone (f x)
fmap f (IndentMany i g p) = IndentMany i (fmap (fmap f) g) p
fmap f (IndentSome i g p) = IndentSome i (fmap (fmap f) g) p

-- | Parse a “reference” token and a number of other tokens that have a
-- greater (but the same for all of them) level of indentation than that of
Expand All @@ -238,7 +243,7 @@ indentBlock ::
-- | How to consume indentation (white space)
m () ->
-- | How to parse “reference” token
m (IndentOpt m a b) ->
m (IndentOpt m a) ->
m a
indentBlock sc r = do
sc
Expand Down
4 changes: 4 additions & 0 deletions megaparsec.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ library
Text.Megaparsec.Lexer

default-language: Haskell2010

default-extensions:
ExistentialQuantification

build-depends:
array >=0.5.3 && <0.6,
base >=4.15 && <5,
Expand Down