on master help sign in
WIP
commite148a68ae75073465f0a66717837967f51ed2c02 authorJason Felice <jason.m.felice@gmail.com> dateMon 30 Oct 2017, 21:48 (9 years ago) parent3bdb58e
5 files changed+101−130
src/Idris/Package/Parser.hs+11−24 src/Idris/Parser.hs+15−15 src/Idris/Parser/Expr.hs+5−5 src/Idris/Parser/Helpers.hs+69−86 src/Idris/REPL/Parser.hs+1
src/Idris/Package/Parser.hs+11−24
@@ -5,13 +5,13 @@ Copyright :
55License : BSD3
66Maintainer : The Idris Community.
77-}
8−{-# LANGUAGE CPP, ConstraintKinds, FlexibleInstances, TypeSynonymInstances #-}
8+{-# LANGUAGE CPP, ConstraintKinds, FlexibleContexts, FlexibleInstances, TypeSynonymInstances #-}
99module Idris.Package.Parser where
1010
1111import Idris.CmdOptions
1212import Idris.Imports
1313import Idris.Package.Common
14−import Idris.Parser.Helpers (MonadicParsing, eol, iName, identifier, isEol,
14+import Idris.Parser.Helpers (IdrisInnerParser, MonadicParsing, eol, iName, identifier, isEol,
1515 lchar, packageName, parseErrorDoc, reserved,
1616 runparser, someSpace')
1717
@@ -21,26 +21,13 @@ import Data.List (union)
2121import System.Directory (doesFileExist)
2222import System.Exit
2323import System.FilePath (isValid, takeExtension, takeFileName)
24−import Text.Parser.Token (TokenParsing)
24+import Text.Parser.Token (TokenParsing(..), stringLiteral)
2525import qualified Text.PrettyPrint.ANSI.Leijen as PP
26−import Text.Trifecta ((<?>))
27−import qualified Text.Trifecta as P
28−
29−type PParser = StateT PkgDesc P.Parser
30−
31−#if MIN_VERSION_base(4,9,0)
32−instance {-# OVERLAPPING #-} P.DeltaParsing PParser where
33− line = lift P.line
34− {-# INLINE line #-}
35− position = lift P.position
36− {-# INLINE position #-}
37− slicedWith f (StateT m) = StateT $ \s -> P.slicedWith (\(a,s') b -> (f a b, s')) $ m s
38− {-# INLINE slicedWith #-}
39− rend = lift P.rend
40− {-# INLINE rend #-}
41− restOfLine = lift P.restOfLine
42− {-# INLINE restOfLine #-}
43−#endif
26+import Text.Megaparsec ((<?>))
27+import qualified Text.Megaparsec as P
28+import qualified Text.Megaparsec.Char as P
29+
30+type PParser = StateT PkgDesc IdrisInnerParser
4431
4532instance {-# OVERLAPPING #-} TokenParsing PParser where
4633 someSpace = someSpace'
@@ -85,7 +72,7 @@ filename = (do
8572 -- This also moves away from tying filenames to identifiers, so
8673 -- it will also accept hyphens
8774 -- (https://github.com/idris-lang/Idris-dev/issues/2721)
88− filename <- P.stringLiteral <* someSpace'
75+ filename <- stringLiteral <* someSpace'
8976 -- Through at least version 0.9.19.1, IPKG executable values were
9077 -- possibly namespaced identifiers, like foo.bar.baz.
9178 <|> show . fst <$> iName []
@@ -130,7 +117,7 @@ pClause :: PParser ()
130117pClause = clause "executable" filename (\st v -> st { execout = Just v })
131118 <|> clause "main" (fst <$> iName []) (\st v -> st { idris_main = Just v })
132119 <|> clause "sourcedir" (fst <$> identifier) (\st v -> st { sourcedir = v })
133− <|> clause "opts" (pureArgParser . words <$> P.stringLiteral) (\st v -> st { idris_opts = v ++ idris_opts st })
120+ <|> clause "opts" (pureArgParser . words <$> stringLiteral) (\st v -> st { idris_opts = v ++ idris_opts st })
134121 <|> clause "pkgs" (commaSep (pPkgName <* someSpace')) (\st ps ->
135122 let pkgs = pureArgParser $ concatMap (\x -> ["-p", show x]) ps
136123 in st { pkgdeps = ps `union` pkgdeps st
@@ -146,6 +133,6 @@ pClause = clause "executable" filename (\st v -> st { execout = Just v })
146133 <|> clause "homepage" textUntilEol (\st v -> st { pkghomepage = Just v })
147134 <|> clause "sourceloc" textUntilEol (\st v -> st { pkgsourceloc = Just v })
148135 <|> clause "bugtracker" textUntilEol (\st v -> st { pkgbugtracker = Just v })
149− <|> clause "brief" P.stringLiteral (\st v -> st { pkgbrief = Just v })
136+ <|> clause "brief" stringLiteral (\st v -> st { pkgbrief = Just v })
150137 <|> clause "author" textUntilEol (\st v -> st { pkgauthor = Just v })
151138 <|> clause "maintainer" textUntilEol (\st v -> st { pkgmaintainer = Just v })
src/Idris/Parser.hs+15−15
@@ -49,6 +49,7 @@ import Data.Foldable (asum)
4949import Data.Function
5050import Data.Generics.Uniplate.Data (descendM)
5151import Data.List
52+import Data.List.NonEmpty (NonEmpty(..))
5253import qualified Data.List.Split as Spl
5354import qualified Data.Map as M
5455import Data.Maybe
@@ -57,9 +58,9 @@ import qualified Data.Text as T
5758import qualified System.Directory as Dir (makeAbsolute)
5859import System.FilePath
5960import qualified Text.PrettyPrint.ANSI.Leijen as PP
60−import Text.Trifecta ((<?>))
61−import qualified Text.Trifecta as P
62−import qualified Text.Trifecta.Delta as P
61+import Text.Megaparsec ((<?>))
62+import qualified Text.Megaparsec as P
63+import qualified Text.Megaparsec.Char as P
6364
6465{-
6566@
@@ -432,20 +433,20 @@ syntaxRule syn
432433 reservedHL "syntax"
433434 return sty)
434435 syms <- some syntaxSym
435− when (all isExpr syms) $ P.unexpected "missing keywords in syntax rule"
436+ when (all isExpr syms) $ P.unexpected . P.Label $ 'm' :| "issing keywords in syntax rule"
436437 let ns = mapMaybe getName syms
437438 when (length ns /= length (nub ns))
438− $ P.unexpected "repeated variable in syntax rule"
439+ $ P.unexpected . P.Label $ 'r' :| "epeated variable in syntax rule"
439440 lchar '='
440441 tm <- typeExpr (allowImp syn) >>= uniquifyBinders [n | Binding n <- syms]
441442 terminator
442443 return (Rule (mkSimple syms) tm sty)
443444 <|> do reservedHL "decl"; reservedHL "syntax"
444445 syms <- some syntaxSym
445− when (all isExpr syms) $ P.unexpected "missing keywords in syntax rule"
446+ when (all isExpr syms) $ P.unexpected . P.Label $ 'm' :| "issing keywords in syntax rule"
446447 let ns = mapMaybe getName syms
447448 when (length ns /= length (nub ns))
448− $ P.unexpected "repeated variable in syntax rule"
449+ $ P.unexpected . P.Label $ 'r' :| "epeated variable in syntax rule"
449450 lchar '='
450451 openBlock
451452 dec <- some (decl syn)
@@ -576,7 +577,7 @@ fnDecl syn = P.try (do notEndBlock
576577@
577578-}
578579fnDecl' :: SyntaxInfo -> IdrisParser PDecl
579−fnDecl' syn = checkDeclFixity $
580+fnDecl' syn = (checkDeclFixity $
580581 do (doc, argDocs, fc, opts', n, nfc, acc) <- P.try (do
581582 pushIndent
582583 (doc, argDocs) <- docstring syn
@@ -594,7 +595,7 @@ fnDecl' syn = checkDeclFixity $
594595 return (PTy doc argDocs syn fc opts' n nfc ty)
595596 <|> postulate syn
596597 <|> caf syn
597− <|> pattern syn
598+ <|> pattern syn)
598599 <?> "function declaration"
599600
600601{-| Parses a series of function and accessbility options
@@ -1512,7 +1513,7 @@ parseElabShellStep ist = runparser (Right <$> do_ defaultSyntax <|> Left <$> ela
15121513 spaced parser = indentGt *> parser
15131514
15141515-- | Parse module header and imports
1515−parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [ImportInfo], Maybe P.Delta)
1516+parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [ImportInfo], Maybe ParseState)
15161517parseImports fname input
15171518 = do i <- getIState
15181519 case runparser imports i fname input of
@@ -1524,13 +1525,13 @@ parseImports fname input
15241525 return x
15251526 where imports :: IdrisParser ((Maybe (Docstring ()), [String],
15261527 [ImportInfo],
1527− Maybe P.Delta),
1528+ Maybe ParseState),
15281529 [(FC, OutputAnnotation)], IState)
15291530 imports = do optional shebang
15301531 whiteSpace
15311532 (mdoc, mname, annots) <- moduleHeader
15321533 ps_exp <- many import_
1533− mrk <- P.mark
1534+ mrk <- P.getParserState
15341535 isEof <- lookAheadMatches P.eof
15351536 let mrk' = if isEof
15361537 then Nothing
@@ -1572,8 +1573,7 @@ fixColour True doc = doc
15721573
15731574-- | A program is a list of declarations, possibly with associated
15741575-- documentation strings.
1575−parseProg :: SyntaxInfo -> FilePath -> String -> Maybe P.Delta ->
1576− Idris [PDecl]
1576+parseProg :: SyntaxInfo -> FilePath -> String -> Maybe ParseState -> Idris [PDecl]
15771577parseProg syn fname input mrk
15781578 = do i <- getIState
15791579 case runparser mainProg i fname input of
@@ -1595,7 +1595,7 @@ parseProg syn fname input mrk
15951595 mainProg = case mrk of
15961596 Nothing -> do i <- get; return ([], i)
15971597 Just mrk -> do
1598− P.release mrk
1598+ P.setParserState mrk
15991599 ds <- prog syn
16001600 i' <- get
16011601 return (ds, i')
src/Idris/Parser/Expr.hs+5−5
@@ -5,8 +5,8 @@ Copyright :
55License : BSD3
66Maintainer : The Idris Community.
77-}
8−{-# LANGUAGE ConstraintKinds, GeneralizedNewtypeDeriving, PatternGuards,
9− TupleSections #-}
8+{-# LANGUAGE ConstraintKinds, FlexibleContexts, GeneralizedNewtypeDeriving,
9+ PatternGuards, TupleSections #-}
1010module Idris.Parser.Expr where
1111
1212import Idris.AbsSyntax
@@ -26,8 +26,8 @@ import Data.Function (on)
2626import Data.List
2727import Data.Maybe
2828import Text.Parser.Expression
29−import Text.Trifecta ((<?>))
30−import qualified Text.Trifecta as P
29+import Text.Megaparsec ((<?>))
30+import qualified Text.Megaparsec as P
3131
3232-- | Allow implicit type declarations
3333allowImp :: SyntaxInfo -> SyntaxInfo
@@ -1466,7 +1466,7 @@ VerbatimString_t ::=
14661466;
14671467@
14681468 -}
1469−verbatimStringLiteral :: MonadicParsing m => m (String, FC)
1469+verbatimStringLiteral :: IdrisParser (String, FC)
14701470verbatimStringLiteral = P.token $ do (FC f start _) <- getFC
14711471 P.try $ string "\"\"\""
14721472 str <- P.manyTill P.anyChar $ P.try (string "\"\"\"")
src/Idris/Parser/Helpers.hs+69−86
@@ -5,9 +5,9 @@ Copyright :
55License : BSD3
66Maintainer : The Idris Community.
77-}
8−{-# LANGUAGE CPP, ConstraintKinds, FlexibleInstances,
8+{-# LANGUAGE CPP, ConstraintKinds, FlexibleContexts, FlexibleInstances,
99 GeneralizedNewtypeDeriving, PatternGuards, StandaloneDeriving,
10− TypeSynonymInstances #-}
10+ TypeSynonymInstances, UndecidableInstances #-}
1111module Idris.Parser.Helpers where
1212
1313import Idris.AbsSyntax
@@ -23,7 +23,6 @@ import Prelude hiding (pi)
2323import Control.Applicative
2424import Control.Monad
2525import Control.Monad.State.Strict
26−import qualified Data.ByteString.UTF8 as UTF8
2726import Data.Char
2827import qualified Data.HashSet as HS
2928import Data.List
@@ -31,34 +30,40 @@ import qualified Data.Map as M
3130import Data.Maybe
3231import qualified Data.Text as T
3332import System.FilePath
34−import qualified Text.Parser.Char as Chr
35−import Text.Parser.LookAhead
33+import Data.List.NonEmpty (fromList)
34+import qualified Text.Parser.Char
35+import qualified Text.Parser.Combinators
3636import qualified Text.Parser.Token as Tok
3737import qualified Text.PrettyPrint.ANSI.Leijen as PP
38−import Text.Trifecta ((<?>))
39−import qualified Text.Trifecta as P
40−import qualified Text.Trifecta.Delta as P
38+import Text.Megaparsec ((<?>))
39+import qualified Text.Megaparsec as P
40+import qualified Text.Megaparsec.Char as P
41+import qualified Text.Megaparsec.Char.Lexer as P hiding (space)
42+
43+newtype ParseError = ParseError { parseErrorDoc :: PP.Doc }
4144
4245-- | Idris parser with state used during parsing
43−type IdrisParser = StateT IState P.Parser
44−
45−#if MIN_VERSION_base(4,9,0)
46−instance {-# OVERLAPPING #-} P.DeltaParsing IdrisParser where
47− line = lift P.line
48− {-# INLINE line #-}
49− position = lift P.position
50− {-# INLINE position #-}
51− slicedWith f (StateT m) = StateT $ \s -> P.slicedWith (\(a,s') b -> (f a b, s')) $ m s
52− {-# INLINE slicedWith #-}
53− rend = lift P.rend
54− {-# INLINE rend #-}
55− restOfLine = lift P.restOfLine
56− {-# INLINE restOfLine #-}
57−#endif
46+type IdrisParser = StateT IState IdrisInnerParser
47+type IdrisInnerParser = P.Parsec () String
48+type ParseState = P.State String
49+
50+-- | Generalized monadic parsing constraint type
51+type MonadicParsing m = (P.MonadParsec () String m, Tok.TokenParsing m)
5852
5953someSpace' :: MonadicParsing m => m ()
6054someSpace' = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
6155
56+instance Text.Parser.Combinators.Parsing IdrisInnerParser where
57+ eof = P.eof
58+ unexpected msg = P.unexpected . P.Label . fromList $ msg
59+ try = P.try
60+ p <?> s = p <?> s --FIXME:?
61+ notFollowedBy = P.notFollowedBy
62+ --FIXME:
63+instance Text.Parser.Char.CharParsing IdrisInnerParser where
64+ satisfy = P.satisfy
65+ --FIXME:??
66+
6267instance {-# OVERLAPPING #-} Tok.TokenParsing IdrisParser where
6368 someSpace = someSpace'
6469 token p = do s <- get
@@ -70,18 +75,12 @@ instance {-# OVERLAPPING #-} Tok.TokenParsing IdrisParser where
7075 put (s { lastTokenSpan = Just (FC fn (sl, sc) (el, ec)) })
7176 return r
7277
73−-- | Generalized monadic parsing constraint type
74−type MonadicParsing m = (P.DeltaParsing m, LookAheadParsing m, Monad m)
75−
76−newtype ParseError = ParseError { parseErrorDoc :: PP.Doc }
77−
7878-- | Helper to run Idris inner parser based stateT parsers
79−runparser :: StateT st P.Parser res -> st -> String -> String -> Either ParseError res
79+runparser :: StateT st IdrisInnerParser res -> st -> String -> String -> Either ParseError res
8080runparser p i inputname s =
81− case P.parseString (evalStateT p i)
82− (P.Directed (UTF8.fromString inputname) 0 0 0 0) s of
83− P.Failure (P.ErrInfo doc _) -> Left (ParseError doc)
84− P.Success value -> Right value
81+ case P.parse (evalStateT p i) inputname s of
82+ Left _ -> Left $ ParseError undefined --FIXME:
83+ Right value -> Right value
8584
8685highlightP :: FC -> OutputAnnotation -> IdrisParser ()
8786highlightP fc annot = do ist <- get
@@ -130,7 +129,7 @@ isEol _ = False
130129
131130-- | A parser that succeeds at the end of the line
132131eol :: MonadicParsing m => m ()
133−eol = () <$ P.satisfy isEol <|> lookAhead P.eof <?> "end of line"
132+eol = () <$ P.satisfy isEol <|> P.lookAhead P.eof <?> "end of line"
134133
135134{- | Consumes a single-line comment
136135
@@ -202,14 +201,15 @@ docComment = do dc <- pushIndent *> docCommentLine
202201 return contents)
203202 <?> ""
204203
205− argDocCommentLine = do string "|||"
206− many (P.satisfy isSpace)
207− char '@'
208− many (P.satisfy isSpace)
204+ argDocCommentLine :: IdrisParser (Name, String)
205+ argDocCommentLine = do P.string "|||"
206+ P.many (P.satisfy isSpace)
207+ P.char '@'
208+ P.many (P.satisfy isSpace)
209209 n <- fst <$> name
210− many (P.satisfy isSpace)
211− docs <- many (P.satisfy (not . isEol))
212− eol ; someSpace'
210+ P.many (P.satisfy isSpace)
211+ docs <- P.many (P.satisfy (not . isEol))
212+ P.eol ; someSpace'
213213 return (n, docs)
214214
215215-- | Parses some white space
@@ -254,30 +254,29 @@ reservedIdentifiers = HS.fromList
254254 ]
255255
256256identifierOrReserved :: MonadicParsing m => m String
257−identifierOrReserved = P.token $ P.try $ do
257+identifierOrReserved = Tok.token $ P.try $ do
258258 c <- P.satisfy isAlpha <|> P.oneOf "_"
259259 cs <- P.many (P.satisfy isAlphaNum <|> P.oneOf "_'.")
260260 return $ c : cs
261261
262262char :: MonadicParsing m => Char -> m Char
263−char = Chr.char
263+char = P.char
264264
265265string :: MonadicParsing m => String -> m String
266−string = Chr.string
266+string = P.string
267267
268268-- | Parses a character as a token
269269lchar :: MonadicParsing m => Char -> m Char
270−lchar = P.token . P.char
270+lchar = Tok.token . P.char
271271
272272-- | Parses a character as a token, returning the source span of the character
273273lcharFC :: MonadicParsing m => Char -> m FC
274274lcharFC ch = do (FC file (l, c) _) <- getFC
275− _ <- P.token (char ch)
275+ _ <- Tok.token (P.char ch)
276276 return $ FC file (l, c) (l, c+1)
277277
278−-- | Parses string as a token
279278symbol :: MonadicParsing m => String -> m ()
280−symbol = void . Tok.symbol
279+symbol = void . P.symbol someSpace'
281280
282281symbolFC :: MonadicParsing m => String -> m FC
283282symbolFC str = do (FC file (l, c) _) <- getFC
@@ -286,7 +285,7 @@ symbolFC str = do (FC file (l, c) _) <- getFC
286285
287286-- | Parses a reserved identifier
288287reserved :: MonadicParsing m => String -> m ()
289−reserved name = P.token $ P.try $ do
288+reserved name = Tok.token $ P.try $ do
290289 P.string name
291290 P.notFollowedBy (P.satisfy isAlphaNum <|> P.oneOf "_'.") <?> "end of " ++ name
292291
@@ -304,7 +303,7 @@ reservedHL str = reservedFC str >>= flip highlightP AnnKeyword
304303-- Taken from Parsec (c) Daan Leijen 1999-2001, (c) Paolo Martini 2007
305304-- | Parses a reserved operator
306305reservedOp :: MonadicParsing m => String -> m ()
307−reservedOp name = P.token $ P.try $
306+reservedOp name = Tok.token $ P.try $
308307 do string name
309308 P.notFollowedBy operatorLetter <?> ("end of " ++ show name)
310309
@@ -318,8 +317,8 @@ identifier :: (MonadicParsing m) => m (String, FC)
318317identifier = P.try $ do
319318 (FC f (l, c) _) <- getFC
320319 ident <- identifierOrReserved
321− when (ident `HS.member` reservedIdentifiers) $ P.unexpected $ "reserved " ++ ident
322− when (ident == "_") $ P.unexpected "wildcard"
320+ when (ident `HS.member` reservedIdentifiers) $ P.unexpected undefined --FIXME: $ "reserved " ++ ident
321+ when (ident == "_") $ P.unexpected undefined --FIXME: "wildcard"
323322 return (ident, FC f (l, c) (l, c + length ident))
324323
325324-- | Parses an identifier with possible namespace as a name
@@ -330,8 +329,8 @@ iName bad = maybeWithNS identifier False bad <?> "name"
330329maybeWithNS :: (MonadicParsing m) => m (String, FC) -> Bool -> [String] -> m (Name, FC)
331330maybeWithNS parser ascend bad = do
332331 fc <- getFC
333− i <- P.option "" (lookAhead (fst <$> identifier))
334− when (i `elem` bad) $ P.unexpected "reserved identifier"
332+ i <- P.option "" (P.lookAhead (fst <$> identifier))
333+ when (i `elem` bad) $ P.unexpected undefined --FIXME: "reserved identifier"
335334 let transf = if ascend then id else reverse
336335 (x, xs, fc) <- P.choice (transf (parserNoNS parser : parsersNS parser i))
337336 return (mkName (x, xs), fc)
@@ -400,7 +399,7 @@ invalidOperators = [":", "=>", "->", "<-", "=", "?=", "|", "**", "==>", "\\", "%
400399
401400-- | Parses an operator
402401symbolicOperator :: MonadicParsing m => m String
403−symbolicOperator = do op <- P.token . some $ operatorLetter
402+symbolicOperator = do op <- Tok.token . some $ operatorLetter
404403 when (op `elem` (invalidOperators ++ commentMarkers)) $
405404 fail $ op ++ " is not a valid operator"
406405 return op
@@ -412,32 +411,17 @@ symbolicOperatorFC = do (FC f (l, c) _) <- getFC
412411 return (op, FC f (l, c) (l, c + length op))
413412
414413{- * Position helpers -}
415−{- | Get filename from position (returns "(interactive)" when no source file is given) -}
416−fileName :: P.Delta -> String
417−fileName (P.Directed fn _ _ _ _) = UTF8.toString fn
418−fileName _ = "(interactive)"
419−
420−{- | Get line number from position -}
421−lineNum :: P.Delta -> Int
422−lineNum (P.Lines l _ _ _) = fromIntegral l + 1
423−lineNum (P.Directed _ l _ _ _) = fromIntegral l + 1
424−lineNum _ = 0
425−
426−{- | Get column number from position -}
427−columnNum :: P.Delta -> Int
428−columnNum pos = fromIntegral (P.column pos) + 1
429−
430−
431414{- | Get file position as FC -}
432415getFC :: MonadicParsing m => m FC
433−getFC = do s <- P.position
434− let (dir, file) = splitFileName (fileName s)
435− let f = if dir == addTrailingPathSeparator "." then file else fileName s
436− return $ FC f (lineNum s, columnNum s) (lineNum s, columnNum s) -- TODO: Change to actual spanning
416+getFC = do pos <- P.getPosition
417+ let columnNumber = P.unPos . P.sourceColumn $ pos
418+ let lineNumber = P.unPos . P.sourceLine $ pos
419+ let (dir, file) = splitFileName (P.sourceName pos)
420+ let f = if dir == addTrailingPathSeparator "." then file else P.sourceName pos
421+ return $ FC f (lineNumber, columnNumber) (lineNumber, columnNumber) -- TODO: Change to actual spanning
437422 -- Issue #1594 on the Issue Tracker.
438423 -- https://github.com/idris-lang/Idris-dev/issues/1594
439424
440−
441425{-* Syntax helpers-}
442426-- | Bind constraints to term
443427bindList :: (RigCount -> Name -> FC -> PTerm -> PTerm -> PTerm) -> [(RigCount, Name, FC, PTerm)] -> PTerm -> PTerm
@@ -447,15 +431,15 @@ bindList b ((r, n, fc, t):bs) sc = b r n fc t (bindList b bs sc)
447431{- | @commaSeparated p@ parses one or more occurences of `p`,
448432 separated by commas and optional whitespace. -}
449433commaSeparated :: MonadicParsing m => m a -> m [a]
450−commaSeparated p = p `P.sepBy1` (P.spaces >> P.char ',' >> P.spaces)
434+commaSeparated p = p `P.sepBy1` (P.space >> P.char ',' >> P.space)
451435
452436{- * Layout helpers -}
453437
454438-- | Push indentation to stack
455439pushIndent :: IdrisParser ()
456−pushIndent = do pos <- P.position
440+pushIndent = do columnNumber <- indent
457441 ist <- get
458− put (ist { indent_stack = (fromIntegral (P.column pos) + 1) : indent_stack ist })
442+ put (ist { indent_stack = columnNumber : indent_stack ist })
459443
460444-- | Pops indentation from stack
461445popIndent :: IdrisParser ()
@@ -466,8 +450,8 @@ popIndent = do ist <- get
466450
467451
468452-- | Gets current indentation
469−indent :: IdrisParser Int
470−indent = liftM ((+1) . fromIntegral . P.column) P.position
453+indent :: MonadicParsing m => m Int
454+indent = P.unPos . P.sourceColumn <$> P.getPosition
471455
472456-- | Gets last indentation
473457lastIndent :: IdrisParser Int
@@ -510,8 +494,7 @@ indentedBlockS p = do openBlock
510494
511495-- | Checks if the following character matches provided parser
512496lookAheadMatches :: MonadicParsing m => m a -> m Bool
513−lookAheadMatches p = do match <- lookAhead (optional p)
514− return $ isJust match
497+lookAheadMatches p = isJust <$> P.lookAhead (P.optional p)
515498
516499-- | Parses a start of block
517500openBlock :: IdrisParser ()
@@ -555,7 +538,7 @@ terminator = do lchar ';'; popIndent
555538 if c <= l then popIndent else fail "not a terminator"
556539 <|> do isParen <- lookAheadMatches (P.oneOf ")}")
557540 if isParen then popIndent else fail "not a terminator"
558− <|> lookAhead P.eof
541+ <|> P.lookAhead P.eof
559542
560543-- | Parses and keeps a terminator
561544keepTerminator :: IdrisParser ()
@@ -565,7 +548,7 @@ keepTerminator = () <$ lchar ';'
565548 <|> do isParen <- lookAheadMatches (P.oneOf ")}|")
566549 isIn <- lookAheadMatches (reserved "in")
567550 unless (isIn || isParen) $ fail "not a terminator"
568− <|> lookAhead P.eof
551+ <|> P.lookAhead P.eof
569552
570553-- | Checks if application expression does not end
571554notEndApp :: IdrisParser ()
@@ -577,7 +560,7 @@ notEndBlock :: IdrisParser ()
577560notEndBlock = do ist <- get
578561 case brace_stack ist of
579562 Just lvl : xs -> do i <- indent
580− isParen <- lookAheadMatches (char ')')
563+ isParen <- lookAheadMatches (P.char ')')
581564 when (i < lvl || isParen) (fail "end of block")
582565 _ -> return ()
583566
src/Idris/REPL/Parser.hs+1
@@ -4,6 +4,7 @@ Description : Parser for the REPL commands.
44License : BSD3
55Maintainer : The Idris Community.
66-}
7+{-# LANGUAGE FlexibleContexts #-}
78module Idris.REPL.Parser (
89 parseCmd
910 , help