@@ -14,7 +14,7 @@ Maintainer : The Idris Community.
1414
1515module Idris.Parser(IdrisParser(..), ImportInfo(..), addReplSyntax, clearParserWarnings,
1616 decl, fixColour, loadFromIFile, loadModule, name, opChars, parseElabShellStep, parseConst, parseExpr, parseImports, parseTactic,
17− runparser) where
17+ runparser, ParseError, parseErrorDoc) where
1818
1919import Idris.AbsSyntax hiding (namespace, params)
2020import Idris.Core.Evaluate
@@ -36,7 +36,7 @@ import Idris.Parser.Ops
3636import Idris.Termination
3737import Idris.Unlit
3838
39−import qualified Util.Pretty as P
39+import qualified Util.Pretty
4040import Util.System (readSource)
4141
4242import Prelude hiding (pi)
@@ -57,11 +57,10 @@ import Data.Ord
5757import qualified Data.Text as T
5858import qualified System.Directory as Dir (makeAbsolute)
5959import System.FilePath
60−import Text.PrettyPrint.ANSI.Leijen (Doc, plain)
61−import qualified Text.PrettyPrint.ANSI.Leijen as ANSI
62−import Text.Trifecta hiding (Err, char, charLiteral, natural, span, string,
63− stringLiteral, symbol, whiteSpace)
64−import Text.Trifecta.Delta
60+import qualified Text.PrettyPrint.ANSI.Leijen as PP
61+import Text.Trifecta ((<?>))
62+import qualified Text.Trifecta as P
63+import qualified Text.Trifecta.Delta as P
6564
6665{-
6766@
@@ -84,17 +83,17 @@ import Text.Trifecta.Delta
8483@
8584-}
8685moduleHeader :: IdrisParser (Maybe (Docstring ()), [String], [(FC, OutputAnnotation)])
87−moduleHeader = try (do docs <- optional docComment
88− noArgs docs
89− reservedHL "module"
90− (i, ifc) <- identifier
91− option ';' (lchar ';')
92− let modName = moduleName i
93− return (fmap fst docs,
94− modName,
95− [(ifc, AnnNamespace (map T.pack modName) Nothing)]))
96− <|> try (do lchar '%'; reserved "unqualified"
97− return (Nothing, [], []))
86+moduleHeader = P.try (do docs <- optional docComment
87+ noArgs docs
88+ reservedHL "module"
89+ (i, ifc) <- identifier
90+ P.option ';' (lchar ';')
91+ let modName = moduleName i
92+ return (fmap fst docs,
93+ modName,
94+ [(ifc, AnnNamespace (map T.pack modName) Nothing)]))
95+ <|> P.try (do lchar '%'; reserved "unqualified"
96+ return (Nothing, [], []))
9897 <|> return (Nothing, moduleName "Main", [])
9998 where moduleName x = case span (/='.') x of
10099 (x, "") -> [x]
@@ -119,12 +118,11 @@ data ImportInfo = ImportInfo { import_reexport :: Bool
119118import_ :: IdrisParser ImportInfo
120119import_ = do fc <- getFC
121120 reservedHL "import"
122− reexport <- option False (do reservedHL "public"
123− return True)
121+ reexport <- P.option False (True <$ reservedHL "public")
124122 (id, idfc) <- identifier
125123 newName <- optional (do reservedHL "as"
126124 identifier)
127− option ';' (lchar ';')
125+ P.option ';' (lchar ';')
128126 return $ ImportInfo reexport (toPath id)
129127 (fmap (\(n, fc) -> (toPath n, fc)) newName)
130128 (map T.pack $ ns id) fc idfc
@@ -143,7 +141,7 @@ prog syn = do whiteSpace
143141 decls <- many (decl syn)
144142 let c = concat decls
145143 case maxline syn of
146− Nothing -> do notOpenBraces; eof
144+ Nothing -> do notOpenBraces; P.eof
147145 _ -> return ()
148146 ist <- get
149147 fc <- getFC
@@ -172,7 +170,7 @@ Decl ::=
172170@
173171-}
174172decl :: SyntaxInfo -> IdrisParser [PDecl]
175−decl syn = try (externalDecl syn)
173+decl syn = P.try (externalDecl syn)
176174 <|> internalDecl syn
177175 <?> "declaration"
178176
@@ -195,13 +193,13 @@ internalDecl syn
195193 if continue then
196194 do notEndBlock
197195 declBody continue
198− else try (do notEndBlock
199− declBody continue)
196+ else P.try (do notEndBlock
197+ declBody continue)
200198 <|> fail "End of readable input"
201199 where declBody :: Bool -> IdrisParser [PDecl]
202200 declBody b =
203− try (implementation True syn)
204− <|> try (openInterface syn)
201+ P.try (implementation True syn)
202+ <|> P.try (openInterface syn)
205203 <|> declBody' b
206204 <|> using_ syn
207205 <|> params syn
@@ -276,9 +274,9 @@ declExtensions syn rules = declExtension syn [] (filter isDeclRule rules)
276274declExtension :: SyntaxInfo -> [Maybe (Name, SynMatch)] -> [Syntax]
277275 -> IdrisParser [PDecl]
278276declExtension syn ns rules =
279− choice $ flip map (groupBy (ruleGroup `on` syntaxSymbols) rules) $ \rs ->
277+ P.choice $ flip map (groupBy (ruleGroup `on` syntaxSymbols) rules) $ \rs ->
280278 case head rs of -- can never be []
281− DeclRule (symb:_) _ -> try $ do
279+ DeclRule (symb:_) _ -> P.try $ do
282280 n <- extSymbol symb
283281 declExtension syn (n : ns) [DeclRule ss t | (DeclRule (_:ss) t) <- rs]
284282 -- If we have more than one Rule in this bucket, our grammar is
@@ -427,28 +425,28 @@ SyntaxSym ::= '[' Name_t ']'
427425-}
428426syntaxRule :: SyntaxInfo -> IdrisParser Syntax
429427syntaxRule syn
430− = do sty <- try (do
428+ = do sty <- P.try (do
431429 pushIndent
432− sty <- option AnySyntax
433− (do reservedHL "term"; return TermSyntax
434− <|> do reservedHL "pattern"; return PatternSyntax)
430+ sty <- P.option AnySyntax
431+ (TermSyntax <$ reservedHL "term"
432+ <|> PatternSyntax <$ reservedHL "pattern")
435433 reservedHL "syntax"
436434 return sty)
437435 syms <- some syntaxSym
438− when (all isExpr syms) $ unexpected "missing keywords in syntax rule"
436+ when (all isExpr syms) $ P.unexpected "missing keywords in syntax rule"
439437 let ns = mapMaybe getName syms
440438 when (length ns /= length (nub ns))
441− $ unexpected "repeated variable in syntax rule"
439+ $ P.unexpected "repeated variable in syntax rule"
442440 lchar '='
443441 tm <- typeExpr (allowImp syn) >>= uniquifyBinders [n | Binding n <- syms]
444442 terminator
445443 return (Rule (mkSimple syms) tm sty)
446444 <|> do reservedHL "decl"; reservedHL "syntax"
447445 syms <- some syntaxSym
448− when (all isExpr syms) $ unexpected "missing keywords in syntax rule"
446+ when (all isExpr syms) $ P.unexpected "missing keywords in syntax rule"
449447 let ns = mapMaybe getName syms
450448 when (length ns /= length (nub ns))
451− $ unexpected "repeated variable in syntax rule"
449+ $ P.unexpected "repeated variable in syntax rule"
452450 lchar '='
453451 openBlock
454452 dec <- some (decl syn)
@@ -544,10 +542,10 @@ SyntaxSym ::= '[' Name_t ']'
544542@
545543 -}
546544syntaxSym :: IdrisParser SSymbol
547−syntaxSym = try (do lchar '['; n <- fst <$> name; lchar ']'
548− return (Expr n))
549− <|> try (do lchar '{'; n <- fst <$> name; lchar '}'
550− return (Binding n))
545+syntaxSym = P.try (do lchar '['; n <- fst <$> name; lchar ']'
546+ return (Expr n))
547+ <|> P.try (do lchar '{'; n <- fst <$> name; lchar '}'
548+ return (Binding n))
551549 <|> do n <- fst <$> iName []
552550 return (Keyword n)
553551 <|> do sym <- fmap fst stringLiteral
@@ -561,11 +559,11 @@ syntaxSym = try (do lchar '['; n <- fst <$> name; lchar ']'
561559@
562560-}
563561fnDecl :: SyntaxInfo -> IdrisParser [PDecl]
564−fnDecl syn = try (do notEndBlock
565− d <- fnDecl' syn
566− i <- get
567− let d' = fmap (desugar syn i) d
568− return [d']) <?> "function declaration"
562+fnDecl syn = P.try (do notEndBlock
563+ d <- fnDecl' syn
564+ i <- get
565+ let d' = fmap (desugar syn i) d
566+ return [d']) <?> "function declaration"
569567
570568{-| Parses a function declaration
571569
@@ -580,7 +578,7 @@ fnDecl syn = try (do notEndBlock
580578-}
581579fnDecl' :: SyntaxInfo -> IdrisParser PDecl
582580fnDecl' syn = checkDeclFixity $
583− do (doc, argDocs, fc, opts', n, nfc, acc) <- try (do
581+ do (doc, argDocs, fc, opts', n, nfc, acc) <- P.try (do
584582 pushIndent
585583 (doc, argDocs) <- docstring syn
586584 (opts, acc) <- fnOpts
@@ -658,41 +656,32 @@ NameTimesList ::=
658656-}
659657fnOpt :: IdrisParser FnOpt
660658fnOpt = do reservedHL "total"; return TotalFn
661− <|> do reservedHL "partial"; return PartialFn
662− <|> do reservedHL "covering"; return CoveringFn
663− <|> do try (lchar '%' *> reserved "export"); c <- fmap fst stringLiteral;
664− return $ CExport c
665− <|> do try (lchar '%' *> reserved "no_implicit");
666− return NoImplicit
667− <|> do try (lchar '%' *> reserved "inline");
668− return Inlinable
669− <|> do try (lchar '%' *> reserved "static");
670− return StaticFn
671− <|> do try (lchar '%' *> reserved "assert_total");
659+ <|> PartialFn <$ reservedHL "partial"
660+ <|> CoveringFn <$ reservedHL "covering"
661+ <|> do P.try (lchar '%' *> reserved "export"); c <- fmap fst stringLiteral;
662+ return $ CExport c
663+ <|> NoImplicit <$ P.try (lchar '%' *> reserved "no_implicit")
664+ <|> Inlinable <$ P.try (lchar '%' *> reserved "inline")
665+ <|> StaticFn <$ P.try (lchar '%' *> reserved "static")
666+ <|> do P.try (lchar '%' *> reserved "assert_total");
672667 fc <- getFC
673668 parserWarning fc Nothing (Msg "%assert_total is deprecated. Use the 'assert_total' function instead.")
674669 return AssertTotal
675− <|> do try (lchar '%' *> reserved "error_handler");
676− return ErrorHandler
677− <|> do try (lchar '%' *> reserved "error_reverse");
678− return ErrorReverse
679− <|> do try (lchar '%' *> reserved "error_reduce");
680− return ErrorReduce
681− <|> do try (lchar '%' *> reserved "reflection");
682− return Reflection
683− <|> do try (lchar '%' *> reserved "hint");
684− return AutoHint
685− <|> do try (lchar '%' *> reserved "overlapping");
686− return OverlappingDictionary
670+ <|> ErrorHandler <$ P.try (lchar '%' *> reserved "error_handler")
671+ <|> ErrorReverse <$ P.try (lchar '%' *> reserved "error_reverse")
672+ <|> ErrorReduce <$ P.try (lchar '%' *> reserved "error_reduce")
673+ <|> Reflection <$ P.try (lchar '%' *> reserved "reflection")
674+ <|> AutoHint <$ P.try (lchar '%' *> reserved "hint")
675+ <|> OverlappingDictionary <$ P.try (lchar '%' *> reserved "overlapping")
687676 <|> do lchar '%'; reserved "specialise";
688− lchar '['; ns <- sepBy nameTimes (lchar ','); lchar ']';
677+ lchar '['; ns <- P.sepBy nameTimes (lchar ','); lchar ']';
689678 return $ Specialise ns
690− <|> do reservedHL "implicit"; return Implicit
679+ <|> Implicit <$ reservedHL "implicit"
691680 <?> "function modifier"
692681 where nameTimes :: IdrisParser (Name, Maybe Int)
693682 nameTimes = do n <- fst <$> fnName
694− t <- option Nothing (do reds <- fmap fst natural
695− return (Just (fromInteger reds)))
683+ t <- P.option Nothing (do reds <- fmap fst natural
684+ return (Just (fromInteger reds)))
696685 return (n, t)
697686
698687{-| Parses a postulate
@@ -705,10 +694,10 @@ Postulate ::=
705694-}
706695postulate :: SyntaxInfo -> IdrisParser PDecl
707696postulate syn = do (doc, ext)
708− <- try $ do (doc, _) <- docstring syn
709− pushIndent
710− ext <- ppostDecl
711− return (doc, ext)
697+ <- P.try $ do (doc, _) <- docstring syn
698+ pushIndent
699+ ext <- ppostDecl
700+ return (doc, ext)
712701 ist <- get
713702 (opts, acc) <- fnOpts
714703 (n_in, nfc) <- fnName
@@ -768,7 +757,7 @@ openInterface syn =
768757 do reservedHL "using"
769758 reservedHL "implementation"
770759 fc <- getFC
771− ns <- sepBy1 fnName (lchar ',')
760+ ns <- P.sepBy1 fnName (lchar ',')
772761
773762 openBlock
774763 ds <- many (decl syn)
@@ -848,14 +837,14 @@ InterfaceBlock ::=
848837interfaceBlock :: SyntaxInfo -> IdrisParser (Maybe (Name, FC), Docstring (Either Err PTerm), [PDecl])
849838interfaceBlock syn = do reservedHL "where"
850839 openBlock
851− (cn, cd) <- option (Nothing, emptyDocstring) $
852− try (do (doc, _) <- option noDocs docComment
853− n <- constructor
854− return (Just n, doc))
840+ (cn, cd) <- P.option (Nothing, emptyDocstring) $
841+ P.try (do (doc, _) <- P.option noDocs docComment
842+ n <- constructor
843+ return (Just n, doc))
855844 ist <- get
856845 let cd' = annotate syn ist cd
857846
858− ds <- many (notEndBlock >> try (implementation True syn)
847+ ds <- many (notEndBlock >> P.try (implementation True syn)
859848 <|> do x <- data_ syn
860849 return [x]
861850 <|> fnDecl syn)
@@ -886,24 +875,24 @@ Interface ::=
886875-}
887876interface_ :: SyntaxInfo -> IdrisParser [PDecl]
888877interface_ syn = do (doc, argDocs, acc)
889− <- try (do (doc, argDocs) <- docstring syn
890− acc <- accessibility
891− interfaceKeyword
892− return (doc, argDocs, acc))
878+ <- P.try (do (doc, argDocs) <- docstring syn
879+ acc <- accessibility
880+ interfaceKeyword
881+ return (doc, argDocs, acc))
893882 fc <- getFC
894883 cons <- constraintList syn
895884 let cons' = [(c, ty) | (_, c, _, ty) <- cons]
896885 (n_in, nfc) <- fnName
897886 let n = expandNS syn n_in
898887 cs <- many carg
899− fds <- option [(cn, NoFC) | (cn, _, _) <- cs] fundeps
900− (cn, cd, ds) <- option (Nothing, fst noDocs, []) (interfaceBlock syn)
888+ fds <- P.option [(cn, NoFC) | (cn, _, _) <- cs] fundeps
889+ (cn, cd, ds) <- P.option (Nothing, fst noDocs, []) (interfaceBlock syn)
901890 accData acc n (concatMap declared ds)
902891 return [PInterface doc syn fc cons' n nfc cs argDocs fds ds cn cd]
903892 <?> "interface declaration"
904893 where
905894 fundeps :: IdrisParser [(Name, FC)]
906− fundeps = do lchar '|'; sepBy name (lchar ',')
895+ fundeps = do lchar '|'; P.sepBy name (lchar ',')
907896
908897 interfaceKeyword :: IdrisParser ()
909898 interfaceKeyword = reservedHL "interface"
@@ -964,7 +953,7 @@ implementation kwopt syn
964953
965954 implementationUsing :: IdrisParser [Name]
966955 implementationUsing = do reservedHL "using"
967− ns <- sepBy1 fnName (lchar ',')
956+ ns <- P.sepBy1 fnName (lchar ',')
968957 return (map fst ns)
969958 <|> return []
970959
@@ -972,7 +961,7 @@ implementation kwopt syn
972961docstring :: SyntaxInfo
973962 -> IdrisParser (Docstring (Either Err PTerm),
974963 [(Name,Docstring (Either Err PTerm))])
975−docstring syn = do (doc, argDocs) <- option noDocs docComment
964+docstring syn = do (doc, argDocs) <- P.option noDocs docComment
976965 ist <- get
977966 let doc' = annotCode (tryFullExpr syn ist) doc
978967 argDocs' = [ (n, annotCode (tryFullExpr syn ist) d)
@@ -1005,8 +994,8 @@ NameList ::=
1005994-}
1006995usingDeclList :: SyntaxInfo -> IdrisParser [Using]
1007996usingDeclList syn
1008− = try (sepBy1 (usingDecl syn) (lchar ','))
1009− <|> do ns <- sepBy1 (fst <$> name) (lchar ',')
997+ = P.try (P.sepBy1 (usingDecl syn) (lchar ','))
998+ <|> do ns <- P.sepBy1 (fst <$> name) (lchar ',')
1010999 lchar ':'
10111000 t <- typeExpr (disallowImp syn)
10121001 return (map (\x -> UImplicit x t) ns)
@@ -1022,10 +1011,10 @@ UsingDecl ::=
10221011@
10231012-}
10241013usingDecl :: SyntaxInfo -> IdrisParser Using
1025−usingDecl syn = try (do x <- fst <$> fnName
1026− lchar ':'
1027− t <- typeExpr (disallowImp syn)
1028− return (UImplicit x t))
1014+usingDecl syn = P.try (do x <- fst <$> fnName
1015+ lchar ':'
1016+ t <- typeExpr (disallowImp syn)
1017+ return (UImplicit x t))
10291018 <|> do c <- fst <$> fnName
10301019 xs <- many (fst <$> fnName)
10311020 return (UConstraint c xs)
@@ -1068,7 +1057,7 @@ ArgExpr ::= HSimpleExpr | {- In Pattern External (User-defined) Expression -};
10681057-}
10691058argExpr :: SyntaxInfo -> IdrisParser PTerm
10701059argExpr syn = let syn' = syn { inPattern = True } in
1071− try (hsimpleExpr syn') <|> simpleExternalExpr syn'
1060+ P.try (hsimpleExpr syn') <|> simpleExternalExpr syn'
10721061 <?> "argument expression"
10731062
10741063{-| Parse a right hand side of a function
@@ -1090,8 +1079,8 @@ rhs syn n = do lchar '='
10901079 expr syn
10911080 <|> do symbol "?=";
10921081 fc <- getFC
1093− name <- option n' (do symbol "{"; n <- fst <$> fnName; symbol "}";
1094− return n)
1082+ name <- P.option n' (do symbol "{"; n <- fst <$> fnName; symbol "}";
1083+ return n)
10951084 r <- expr syn
10961085 return (addLet fc name r)
10971086 <|> impossible
@@ -1135,7 +1124,7 @@ WhereOrTerminator ::= WhereBlock | Terminator;
11351124-}
11361125clause :: SyntaxInfo -> IdrisParser PClause
11371126clause syn
1138− = do wargs <- try (do pushIndent; some (wExpr syn))
1127+ = do wargs <- P.try (do pushIndent; some (wExpr syn))
11391128 fc <- getFC
11401129 ist <- get
11411130 n <- case lastParse ist of
@@ -1143,11 +1132,8 @@ clause syn
11431132 Nothing -> fail "Invalid clause"
11441133 (do r <- rhs syn n
11451134 let wsyn = syn { syn_namespace = [], syn_toplevel = False }
1146− (wheres, nmap) <- choice [do x <- whereBlock n wsyn
1147− popIndent
1148− return x,
1149− do terminator
1150− return ([], [])]
1135+ (wheres, nmap) <- whereBlock n wsyn <* popIndent
1136+ <|> ([], []) <$ terminator
11511137 return $ PClauseR fc wargs r wheres) <|> (do
11521138 popIndent
11531139 reservedHL "with"
@@ -1158,19 +1144,16 @@ clause syn
11581144 let withs = concat ds
11591145 closeBlock
11601146 return $ PWithR fc wargs wval pn withs)
1161− <|> do ty <- try (do pushIndent
1162− ty <- simpleExpr syn
1163− symbol "<=="
1164− return ty)
1147+ <|> do ty <- P.try (do pushIndent
1148+ ty <- simpleExpr syn
1149+ symbol "<=="
1150+ return ty)
11651151 fc <- getFC
11661152 n_in <- fst <$> fnName; let n = expandNS syn n_in
11671153 r <- rhs syn n
11681154 let wsyn = syn { syn_namespace = [] }
1169− (wheres, nmap) <- choice [do x <- whereBlock n wsyn
1170− popIndent
1171− return x,
1172− do terminator
1173− return ([], [])]
1155+ (wheres, nmap) <- whereBlock n wsyn <* popIndent
1156+ <|> ([], []) <$ terminator
11741157 let capp = PLet fc RigW (sMN 0 "match") NoFC
11751158 ty
11761159 (PMatchApp fc n)
@@ -1178,7 +1161,7 @@ clause syn
11781161 ist <- get
11791162 put (ist { lastParse = Just n })
11801163 return $ PClause fc n capp [] r wheres
1181− <|> do (l, op, nfc) <- try (do
1164+ <|> do (l, op, nfc) <- P.try (do
11821165 pushIndent
11831166 l <- argExpr syn
11841167 (op, nfc) <- symbolicOperatorFC
@@ -1191,11 +1174,8 @@ clause syn
11911174 wargs <- many (wExpr syn)
11921175 (do rs <- rhs syn n
11931176 let wsyn = syn { syn_namespace = [] }
1194− (wheres, nmap) <- choice [do x <- whereBlock n wsyn
1195− popIndent
1196− return x,
1197− do terminator
1198− return ([], [])]
1177+ (wheres, nmap) <- whereBlock n wsyn <* popIndent
1178+ <|> ([], []) <$ terminator
11991179 ist <- get
12001180 let capp = PApp fc (PRef nfc [nfc] n) [pexp l, pexp r]
12011181 put (ist { lastParse = Just n })
@@ -1215,18 +1195,15 @@ clause syn
12151195 <|> do pushIndent
12161196 (n_in, nfc) <- fnName; let n = expandNS syn n_in
12171197 fc <- getFC
1218− args <- many (try (implicitArg (syn { inPattern = True } ))
1219− <|> try (constraintArg (syn { inPattern = True }))
1198+ args <- many (P.try (implicitArg (syn { inPattern = True } ))
1199+ <|> P.try (constraintArg (syn { inPattern = True }))
12201200 <|> (fmap pexp (argExpr syn)))
12211201 wargs <- many (wExpr syn)
12221202 let capp = PApp fc (PRef nfc [nfc] n) args
12231203 (do r <- rhs syn n
12241204 let wsyn = syn { syn_namespace = [] }
1225− (wheres, nmap) <- choice [do x <- whereBlock n wsyn
1226− popIndent
1227− return x,
1228− do terminator
1229− return ([], [])]
1205+ (wheres, nmap) <- whereBlock n wsyn <* popIndent
1206+ <|> ([], []) <$ terminator
12301207 ist <- get
12311208 put (ist { lastParse = Just n })
12321209 return $ PClause fc n capp wargs r wheres) <|> (do
@@ -1243,9 +1220,9 @@ clause syn
12431220 return $ PWith fc n capp wargs wval pn withs)
12441221 <?> "function clause"
12451222 where
1246− optProof = option Nothing (do reservedHL "proof"
1247− n <- fnName
1248− return (Just n))
1223+ optProof = P.option Nothing (do reservedHL "proof"
1224+ n <- fnName
1225+ return (Just n))
12491226
12501227 fillLHS :: Name -> PTerm -> [PTerm] -> PClause -> PClause
12511228 fillLHS n capp owargs (PClauseR fc wargs v ws)
@@ -1336,74 +1313,74 @@ Directive' ::= 'lib' CodeGen String_t
13361313@
13371314-}
13381315directive :: SyntaxInfo -> IdrisParser [PDecl]
1339−directive syn = do try (lchar '%' *> reserved "lib")
1316+directive syn = do P.try (lchar '%' *> reserved "lib")
13401317 cgn <- codegen_
13411318 lib <- fmap fst stringLiteral
13421319 return [PDirective (DLib cgn lib)]
1343− <|> do try (lchar '%' *> reserved "link")
1320+ <|> do P.try (lchar '%' *> reserved "link")
13441321 cgn <- codegen_; obj <- fst <$> stringLiteral
13451322 return [PDirective (DLink cgn obj)]
1346− <|> do try (lchar '%' *> reserved "flag")
1323+ <|> do P.try (lchar '%' *> reserved "flag")
13471324 cgn <- codegen_; flag <- fst <$> stringLiteral
13481325 return [PDirective (DFlag cgn flag)]
1349− <|> do try (lchar '%' *> reserved "include")
1326+ <|> do P.try (lchar '%' *> reserved "include")
13501327 cgn <- codegen_
13511328 hdr <- fst <$> stringLiteral
13521329 return [PDirective (DInclude cgn hdr)]
1353− <|> do try (lchar '%' *> reserved "hide"); n <- fst <$> fnName
1330+ <|> do P.try (lchar '%' *> reserved "hide"); n <- fst <$> fnName
13541331 return [PDirective (DHide n)]
1355− <|> do try (lchar '%' *> reserved "freeze"); n <- fst <$> iName []
1332+ <|> do P.try (lchar '%' *> reserved "freeze"); n <- fst <$> iName []
13561333 return [PDirective (DFreeze n)]
1357− <|> do try (lchar '%' *> reserved "thaw"); n <- fst <$> iName []
1334+ <|> do P.try (lchar '%' *> reserved "thaw"); n <- fst <$> iName []
13581335 return [PDirective (DThaw n)]
13591336 -- injectivity assertins are intended for debugging purposes
13601337 -- only, and won't be documented/could be removed at any point
1361− <|> do try (lchar '%' *> reserved "assert_injective"); n <- fst <$> fnName
1338+ <|> do P.try (lchar '%' *> reserved "assert_injective"); n <- fst <$> fnName
13621339 return [PDirective (DInjective n)]
13631340 -- Assert totality of something after definition. This is
13641341 -- here as a debugging aid, so commented out...
1365−-- <|> do try (lchar '%' *> reserved "assert_set_total"); n <- fst <$> fnName
1342+-- <|> do P.try (lchar '%' *> reserved "assert_set_total"); n <- fst <$> fnName
13661343-- return [PDirective (DSetTotal n)]
1367− <|> do try (lchar '%' *> reserved "access")
1344+ <|> do P.try (lchar '%' *> reserved "access")
13681345 acc <- accessibility
13691346 ist <- get
13701347 put ist { default_access = acc }
13711348 return [PDirective (DAccess acc)]
1372− <|> do try (lchar '%' *> reserved "default"); tot <- totality
1349+ <|> do P.try (lchar '%' *> reserved "default"); tot <- totality
13731350 i <- get
13741351 put (i { default_total = tot } )
13751352 return [PDirective (DDefault tot)]
1376− <|> do try (lchar '%' *> reserved "logging")
1353+ <|> do P.try (lchar '%' *> reserved "logging")
13771354 i <- fst <$> natural
13781355 return [PDirective (DLogging i)]
1379− <|> do try (lchar '%' *> reserved "dynamic")
1380− libs <- sepBy1 (fmap fst stringLiteral) (lchar ',')
1356+ <|> do P.try (lchar '%' *> reserved "dynamic")
1357+ libs <- P.sepBy1 (fmap fst stringLiteral) (lchar ',')
13811358 return [PDirective (DDynamicLibs libs)]
1382− <|> do try (lchar '%' *> reserved "name")
1359+ <|> do P.try (lchar '%' *> reserved "name")
13831360 (ty, tyFC) <- fnName
1384− ns <- sepBy1 name (lchar ',')
1361+ ns <- P.sepBy1 name (lchar ',')
13851362 return [PDirective (DNameHint ty tyFC ns)]
1386− <|> do try (lchar '%' *> reserved "error_handlers")
1363+ <|> do P.try (lchar '%' *> reserved "error_handlers")
13871364 (fn, nfc) <- fnName
13881365 (arg, afc) <- fnName
1389− ns <- sepBy1 name (lchar ',')
1366+ ns <- P.sepBy1 name (lchar ',')
13901367 return [PDirective (DErrorHandlers fn nfc arg afc ns) ]
1391− <|> do try (lchar '%' *> reserved "language"); ext <- pLangExt;
1368+ <|> do P.try (lchar '%' *> reserved "language"); ext <- pLangExt;
13921369 return [PDirective (DLanguage ext)]
1393− <|> do try (lchar '%' *> reserved "deprecate")
1370+ <|> do P.try (lchar '%' *> reserved "deprecate")
13941371 n <- fst <$> fnName
1395− alt <- option "" (fst <$> stringLiteral)
1372+ alt <- P.option "" (fst <$> stringLiteral)
13961373 return [PDirective (DDeprecate n alt)]
1397− <|> do try (lchar '%' *> reserved "fragile")
1374+ <|> do P.try (lchar '%' *> reserved "fragile")
13981375 n <- fst <$> fnName
1399− alt <- option "" (fst <$> stringLiteral)
1376+ alt <- P.option "" (fst <$> stringLiteral)
14001377 return [PDirective (DFragile n alt)]
14011378 <|> do fc <- getFC
1402− try (lchar '%' *> reserved "used")
1379+ P.try (lchar '%' *> reserved "used")
14031380 fn <- fst <$> fnName
14041381 arg <- fst <$> iName []
14051382 return [PDirective (DUsed fc fn arg)]
1406− <|> do try (lchar '%' *> reserved "auto_implicits")
1383+ <|> do P.try (lchar '%' *> reserved "auto_implicits")
14071384 b <- on_off
14081385 return [PDirective (DAutoImplicits b)]
14091386 <?> "directive"
@@ -1440,12 +1417,12 @@ ProviderWhat ::= 'proof' | 'term' | 'type' | 'postulate'
14401417@
14411418 -}
14421419provider :: SyntaxInfo -> IdrisParser [PDecl]
1443−provider syn = do doc <- try (do (doc, _) <- docstring syn
1444− fc1 <- getFC
1445− lchar '%'
1446− fc2 <- reservedFC "provide"
1447− highlightP (spanFC fc1 fc2) AnnKeyword
1448− return doc)
1420+provider syn = do doc <- P.try (do (doc, _) <- docstring syn
1421+ fc1 <- getFC
1422+ lchar '%'
1423+ fc2 <- reservedFC "provide"
1424+ highlightP (spanFC fc1 fc2) AnnKeyword
1425+ return doc)
14491426 provideTerm doc <|> providePostulate doc
14501427 <?> "type provider"
14511428 where provideTerm doc =
@@ -1469,7 +1446,7 @@ Transform ::= '%' 'transform' Expr '==>' Expr
14691446@
14701447-}
14711448transform :: SyntaxInfo -> IdrisParser [PDecl]
1472−transform syn = do try (lchar '%' *> reserved "transform")
1449+transform syn = do P.try (lchar '%' *> reserved "transform")
14731450 -- leave it unchecked, until we work out what this should
14741451 -- actually mean...
14751452-- safety <- option True (do reserved "unsafe"
@@ -1489,10 +1466,10 @@ RunElabDecl ::= '%' 'runElab' Expr
14891466-}
14901467runElabDecl :: SyntaxInfo -> IdrisParser PDecl
14911468runElabDecl syn =
1492− do kwFC <- try (do fc <- getFC
1493− lchar '%'
1494− fc' <- reservedFC "runElab"
1495− return (spanFC fc fc'))
1469+ do kwFC <- P.try (do fc <- getFC
1470+ lchar '%'
1471+ fc' <- reservedFC "runElab"
1472+ return (spanFC fc fc'))
14961473 script <- expr syn <?> "elaborator script"
14971474 highlightP kwFC AnnKeyword
14981475 return $ PRunElabDecl kwFC script (syn_namespace syn)
@@ -1500,20 +1477,20 @@ runElabDecl syn =
15001477
15011478{- * Loading and parsing -}
15021479{-| Parses an expression from input -}
1503−parseExpr :: IState -> String -> Result PTerm
1480+parseExpr :: IState -> String -> Either ParseError PTerm
15041481parseExpr st = runparser (fullExpr defaultSyntax) st "(input)"
15051482
15061483{-| Parses a constant form input -}
1507−parseConst :: IState -> String -> Result Const
1484+parseConst :: IState -> String -> Either ParseError Const
15081485parseConst st = runparser (fmap fst constant) st "(input)"
15091486
15101487{-| Parses a tactic from input -}
1511−parseTactic :: IState -> String -> Result PTactic
1488+parseTactic :: IState -> String -> Either ParseError PTactic
15121489parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
15131490
15141491{-| Parses a do-step from input (used in the elab shell) -}
1515−parseElabShellStep :: IState -> String -> Result (Either ElabShellCmd PDo)
1516−parseElabShellStep ist = runparser (fmap Right (do_ defaultSyntax) <|> fmap Left elabShellCmd) ist "(input)"
1492+parseElabShellStep :: IState -> String -> Either ParseError (Either ElabShellCmd PDo)
1493+parseElabShellStep ist = runparser (Right <$> do_ defaultSyntax <|> Left <$> elabShellCmd) ist "(input)"
15171494 where elabShellCmd = char ':' >>
15181495 (reserved "qed" >> pure EQED ) <|>
15191496 (reserved "abandon" >> pure EAbandon ) <|>
@@ -1525,7 +1502,7 @@ parseElabShellStep ist = runparser (fmap Right (do_ defaultSyntax) <|> fmap Left
15251502 (expressionTactic ["search"] ESearch ) <|>
15261503 (do reserved "doc"
15271504 doc <- (Right . fst <$> constant) <|> (Left . fst <$> fnName)
1528− eof
1505+ P.eof
15291506 return (EDocStr doc))
15301507 <?> "elab command"
15311508 expressionTactic cmds tactic =
@@ -1536,26 +1513,26 @@ parseElabShellStep ist = runparser (fmap Right (do_ defaultSyntax) <|> fmap Left
15361513 spaced parser = indentGt *> parser
15371514
15381515-- | Parse module header and imports
1539−parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [ImportInfo], Maybe Delta)
1516+parseImports :: FilePath -> String -> Idris (Maybe (Docstring ()), [String], [ImportInfo], Maybe P.Delta)
15401517parseImports fname input
15411518 = do i <- getIState
1542− case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
1543− Failure (ErrInfo err _) -> ifail $ show err
1544− Success (x, annots, i) ->
1519+ case P.parseString (evalStateT imports i) (P.Directed (UTF8.fromString fname) 0 0 0 0) input of
1520+ P.Failure (P.ErrInfo err _) -> ifail $ show err
1521+ P.Success (x, annots, i) ->
15451522 do putIState i
15461523 fname' <- runIO $ Dir.makeAbsolute fname
15471524 sendHighlighting $ addPath annots fname'
15481525 return x
15491526 where imports :: IdrisParser ((Maybe (Docstring ()), [String],
15501527 [ImportInfo],
1551− Maybe Delta),
1528+ Maybe P.Delta),
15521529 [(FC, OutputAnnotation)], IState)
15531530 imports = do optional shebang
15541531 whiteSpace
15551532 (mdoc, mname, annots) <- moduleHeader
15561533 ps_exp <- many import_
1557− mrk <- mark
1558− isEof <- lookAheadMatches eof
1534+ mrk <- P.mark
1535+ isEof <- lookAheadMatches P.eof
15591536 let mrk' = if isEof
15601537 then Nothing
15611538 else Just mrk
@@ -1572,11 +1549,11 @@ parseImports fname input
15721549 addPath (annot:annots) path = annot : addPath annots path
15731550
15741551 shebang :: IdrisParser ()
1575− shebang = string "#!" *> many (satisfy $ not . isEol) *> eol *> pure ()
1552+ shebang = string "#!" *> many (P.satisfy $ not . isEol) *> eol *> pure ()
15761553
15771554-- | There should be a better way of doing this...
1578−findFC :: Doc -> (FC, String)
1579−findFC x = let s = show (plain x) in findFC' s
1555+findFC :: PP.Doc -> (FC, String)
1556+findFC x = let s = show (PP.plain x) in findFC' s
15801557 where findFC' s = case span (/= ':') s of
15811558 -- Horrid kludge to prevent crashes on Windows
15821559 (prefix, ':':'\\':rest) ->
@@ -1590,36 +1567,36 @@ findFC x = let s = show (plain x) in findFC' s
15901567 (FC failname pos pos, msg)
15911568
15921569-- | Check if the coloring matches the options and corrects if necessary
1593−fixColour :: Bool -> ANSI.Doc -> ANSI.Doc
1594−fixColour False doc = ANSI.plain doc
1570+fixColour :: Bool -> PP.Doc -> PP.Doc
1571+fixColour False doc = PP.plain doc
15951572fixColour True doc = doc
15961573
15971574-- | A program is a list of declarations, possibly with associated
15981575-- documentation strings.
1599−parseProg :: SyntaxInfo -> FilePath -> String -> Maybe Delta ->
1576+parseProg :: SyntaxInfo -> FilePath -> String -> Maybe P.Delta ->
16001577 Idris [PDecl]
16011578parseProg syn fname input mrk
16021579 = do i <- getIState
16031580 case runparser mainProg i fname input of
1604− Failure (ErrInfo doc _) -> do -- FIXME: Get error location from trifecta
1605− -- this can't be the solution!
1606− -- Issue #1575 on the issue tracker.
1607− -- https://github.com/idris-lang/Idris-dev/issues/1575
1608− let (fc, msg) = findFC doc
1609− i <- getIState
1610− case idris_outputmode i of
1611− RawOutput h -> iputStrLn (show $ fixColour (idris_colourRepl i) doc)
1612− IdeMode n h -> iWarn fc (P.text msg)
1613− putIState (i { errSpan = Just fc })
1614− return []
1615− Success (x, i) -> do putIState i
1616− reportParserWarnings
1617− return $ collect x
1581+ Left err -> do -- FIXME: Get error location from trifecta
1582+ -- this can't be the solution!
1583+ -- Issue #1575 on the issue tracker.
1584+ -- https://github.com/idris-lang/Idris-dev/issues/1575
1585+ let (fc, msg) = findFC $ parseErrorDoc err
1586+ i <- getIState
1587+ case idris_outputmode i of
1588+ RawOutput h -> iputStrLn (show . fixColour (idris_colourRepl i) . parseErrorDoc $ err)
1589+ IdeMode n h -> iWarn fc (Util.Pretty.text msg)
1590+ putIState (i { errSpan = Just fc })
1591+ return []
1592+ Right (x, i) -> do putIState i
1593+ reportParserWarnings
1594+ return $ collect x
16181595 where mainProg :: IdrisParser ([PDecl], IState)
16191596 mainProg = case mrk of
16201597 Nothing -> do i <- get; return ([], i)
16211598 Just mrk -> do
1622− release mrk
1599+ P.release mrk
16231600 ds <- prog syn
16241601 i' <- get
16251602 return (ds, i')