on master help sign in
Merge branch 'master' into error-reflection

Conflicts: idris.cabal src/Idris/AbsSyntaxTree.hs src/Idris/ParseExpr.hs src/Idris/Parser.hs

commit380e1ca96e7f508b4017aa833a5cd9925ef3e3c5 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateThu 30 Jan 2014, 14:31 (13 years ago) parent33d07ac3e07c44
25 files changed+512−127
CHANGELOG+5 idris.cabal+7−1 jsrts/Runtime-common.js+17 src/IRTS/CodegenJavaScript.hs+174−26 src/Idris/AbsSyntaxTree.hs+5−2 src/Idris/Chaser.hs+1−1 src/Idris/Delaborate.hs+1−1 src/Idris/ElabTerm.hs+3−1 src/Idris/ParseExpr.hs+1 src/Idris/ParseHelpers.hs+34−19 src/Idris/Parser.hs+179−35 src/Pkg/Package.hs+2−2 test/test039/FunErrTest.idr → test/test038/FunErrTest.idr test/test038/expected+4−29 test/test038/run+2−4 test/test039/expected+29−4 test/test039/run+4−2 test/test038/test038.idr → test/test039/test038.idr test/test040/A.idr+4 test/test040/B/C.idr+4 test/test040/Faulty.idr+7 test/test040/Main.idr+16 test/test040/Multiple.idr+4 test/test040/expected+4 test/test040/run+5
CHANGELOG+5
@@ -10,11 +10,16 @@ New in 0.9.11:
1010* General improvements in error messages, especially %error_reverse
1111 annotation, which allows a hint as to how to display a term in error
1212 messages
13+* --ideslave mode now transmits semantic information about many of the
14+ strings that it emits, which can be used by clients to implement
15+ semantic highlighting like that of the REPL. This has been implemented
16+ in the Emacs mode and the IRC bot, which can serve as examples.
1317
1418Internal changes
1519
1620* Faster elaboration
1721* Smaller .ibc files
22+* Pretty-printer now used for all term output
1823
1924
2025New in 0.9.10:
idris.cabal+7−1
@@ -323,6 +323,12 @@ Extra-source-files:
323323 test/test038/run
324324 test/test038/expected
325325 test/test038/*.idr
326+ test/test039/run
327+ test/test039/expected
328+ test/test039/*.idr
329+ test/test040/run
330+ test/test040/expected
331+ test/test040/*.idr
326332
327333source-repository head
328334 type: git
@@ -442,7 +448,7 @@ Library
442448 , ansi-wl-pprint
443449 , binary
444450 , bytestring
445− , containers
451+ , containers >= 0.5
446452 , directory
447453 , directory >= 1.2
448454 , filepath
jsrts/Runtime-common.js+17
@@ -49,3 +49,20 @@ var __IDRRT__tailcall = function(k) {
4949
5050 return ret;
5151};
52+
53+var __IDRRT__EVALTC = function(arg0) {
54+ var ret = (arg0 instanceof __IDRRT__Con && __IDRLT__mEVAL0[arg0.tag])?(__IDRLT__mEVAL0[arg0.tag](arg0)):(arg0);
55+ while (ret instanceof __IDRRT__Cont)
56+ ret = ret.k();
57+
58+ return ret;
59+};
60+
61+var __IDRRT__APPLYTC = function(fn0, arg0) {
62+ var ev = __IDRRT__EVALTC(fn0);
63+ var ret = (ev instanceof __IDRRT__Con && __IDRLT__mAPPLY0[ev.tag])?(__IDRLT__mAPPLY0[ev.tag](fn0,arg0,ev)):(null)
64+ while (ret instanceof __IDRRT__Cont)
65+ ret = ret.k();
66+
67+ return ret;
68+}
src/IRTS/CodegenJavaScript.hs+174−26
@@ -246,14 +246,17 @@ jsLet name value body =
246246 ) [value]
247247
248248
249−jsSubst :: String -> JS -> JS -> JS
250−jsSubst var new (JSVar old)
249+jsSubst :: JS -> JS -> JS -> JS
250+jsSubst var new old
251+ | var == old = new
252+
253+jsSubst (JSIdent var) new (JSVar old)
251254 | var == translateVariableName old = new
252− | otherwise = JSVar old
255+ | otherwise = JSVar old
253256
254−jsSubst var new (JSIdent old)
257+jsSubst var new old@(JSIdent _)
255258 | var == old = new
256− | otherwise = JSIdent old
259+ | otherwise = old
257260
258261jsSubst var new (JSArray fields) =
259262 JSArray (map (jsSubst var new) fields)
@@ -261,25 +264,25 @@ jsSubst var new (JSArray fields) =
261264jsSubst var new (JSNew con vals) =
262265 JSNew con $ map (jsSubst var new) vals
263266
264−jsSubst var new (JSApp (JSProj (JSFunction args body) "apply") vals)
267+jsSubst (JSIdent var) new (JSApp (JSProj (JSFunction args body) "apply") vals)
265268 | var `notElem` args =
266− JSApp (JSProj (JSFunction args (jsSubst var new body)) "apply") (
267− map (jsSubst var new) vals
269+ JSApp (JSProj (JSFunction args (jsSubst (JSIdent var) new body)) "apply") (
270+ map (jsSubst (JSIdent var) new) vals
268271 )
269272 | otherwise =
270273 JSApp (JSProj (JSFunction args body) "apply") (
271− map (jsSubst var new) vals
274+ map (jsSubst (JSIdent var) new) vals
272275 )
273276
274−jsSubst var new (JSApp (JSFunction [arg] body) vals)
277+jsSubst (JSIdent var) new (JSApp (JSFunction [arg] body) vals)
275278 | var /= arg =
276279 JSApp (JSFunction [arg] (
277− jsSubst var new body
278− )) $ map (jsSubst var new) vals
280+ jsSubst (JSIdent var) new body
281+ )) $ map (jsSubst (JSIdent var) new) vals
279282 | otherwise =
280283 JSApp (JSFunction [arg] (
281284 body
282− )) $ map (jsSubst var new) vals
285+ )) $ map (jsSubst (JSIdent var) new) vals
283286
284287jsSubst var new (JSApp lhs rhs) =
285288 JSApp (jsSubst var new lhs) (map (jsSubst var new) rhs)
@@ -324,7 +327,7 @@ removeAllocations (JSSeq body) =
324327 removeHelper :: [JS] -> [JS]
325328 removeHelper [js] = [js]
326329 removeHelper ((JSAlloc name (Just val@(JSIdent _))):js) =
327− map (jsSubst name val) (removeHelper js)
330+ map (jsSubst (JSIdent name) val) (removeHelper js)
328331 removeHelper (j:js) = j : removeHelper js
329332
330333removeAllocations (JSFunction args body) =
@@ -378,7 +381,7 @@ isJSConstant js
378381
379382inlineJS :: JS -> JS
380383inlineJS (JSReturn (JSApp (JSFunction ["cse"] body) [val@(JSVar _)])) =
381− inlineJS $ jsSubst "cse" val body
384+ inlineJS $ jsSubst (JSIdent "cse") val body
382385
383386inlineJS (JSReturn (JSApp (JSFunction [arg] cond@(JSCond _)) [val])) =
384387 JSSeq [ JSAlloc arg (Just (inlineJS val))
@@ -394,7 +397,7 @@ inlineJS (JSApp (JSProj (JSFunction args (JSReturn body)) "apply") [
394397 inlineApply [] body _ = inlineJS body
395398 inlineApply (a:as) body n =
396399 inlineApply as (
397− jsSubst a (JSIndex (JSProj var "vars") (JSNum (JSInt n))) body
400+ jsSubst (JSIdent a) (JSIndex (JSProj var "vars") (JSNum (JSInt n))) body
398401 ) (n + 1)
399402
400403inlineJS (JSApp (JSIdent "__IDR__mEVAL0") [val])
@@ -408,33 +411,43 @@ inlineJS (JSApp (JSIdent "__IDRRT__tailcall") [
408411inlineJS (JSApp (JSFunction [arg] (JSReturn ret)) [val])
409412 | JSNew con [tag, vals] <- ret
410413 , opt <- inlineJS val =
411− JSNew con [tag, jsSubst arg opt vals]
414+ JSNew con [tag, jsSubst (JSIdent arg) opt vals]
412415
413416 | JSNew con [JSFunction [] (JSReturn (JSApp fun vars))] <- ret
414417 , opt <- inlineJS val =
415418 JSNew con [JSFunction [] (
416− JSReturn $ JSApp (jsSubst arg opt fun) (map (jsSubst arg opt) vars)
419+ JSReturn (
420+ JSApp (
421+ jsSubst (JSIdent arg) opt fun
422+ ) (
423+ map (jsSubst (JSIdent arg) opt) vars
424+ )
425+ )
417426 )]
418427
419428 | JSApp (JSProj obj field) args <- ret
420429 , opt <- inlineJS val =
421− JSApp (JSProj (jsSubst arg opt obj) field) $ map (jsSubst arg opt) args
430+ JSApp (
431+ JSProj (jsSubst (JSIdent arg) opt obj) field
432+ ) (
433+ map (jsSubst (JSIdent arg) opt) args
434+ )
422435
423436 | JSIndex (JSProj obj field) idx <- ret
424437 , opt <- inlineJS val =
425438 JSIndex (JSProj (
426− jsSubst arg opt obj
439+ jsSubst (JSIdent arg) opt obj
427440 ) field
428− ) (jsSubst arg opt idx)
441+ ) (jsSubst (JSIdent arg) opt idx)
429442
430443 | JSOp op lhs rhs <- ret
431444 , opt <- inlineJS val =
432− JSOp op (jsSubst arg opt lhs) $
433− (jsSubst arg opt rhs)
445+ JSOp op (jsSubst (JSIdent arg) opt lhs) $
446+ (jsSubst (JSIdent arg) opt rhs)
434447
435448 | JSApp (JSIdent fun) args <- ret
436449 , opt <- inlineJS val =
437− JSApp (JSIdent fun) $ map (jsSubst arg opt) args
450+ JSApp (JSIdent fun) $ map (jsSubst (JSIdent arg) opt) args
438451
439452inlineJS (JSApp fun args) =
440453 JSApp (inlineJS fun) (map inlineJS args)
@@ -480,6 +493,11 @@ reduceJS js = reduceLoop [] ([], js)
480493funName :: JS -> String
481494funName (JSAlloc fun _) = fun
482495
496+elimDeadLoop :: [JS] -> [JS]
497+elimDeadLoop js
498+ | ret <- deadEvalApplyCases js
499+ , ret /= js = elimDeadLoop ret
500+ | otherwise = js
483501
484502deadEvalApplyCases :: [JS] -> [JS]
485503deadEvalApplyCases js =
@@ -816,6 +834,131 @@ reduceConstants js
816834 , ret /= js = reduceConstants ret
817835 | otherwise = js
818836
837+
838+elimDuplicateEvals :: JS -> JS
839+elimDuplicateEvals (JSAlloc fun (Just (JSFunction args (JSSeq seq)))) =
840+ JSAlloc fun $ Just (JSFunction args $ JSSeq (elimHelper seq))
841+ where
842+ elimHelper :: [JS] -> [JS]
843+ elimHelper (j@(JSAlloc var (Just val)):js) =
844+ j : map (jsSubst val (JSIdent var)) (elimHelper js)
845+ elimHelper (j:js) =
846+ j : elimHelper js
847+ elimHelper [] = []
848+
849+elimDuplicateEvals js = js
850+
851+optimizeEvalTailcalls :: (String, String) -> JS -> JS
852+optimizeEvalTailcalls (fun, tc) js =
853+ optHelper js
854+ where
855+ optHelper :: JS -> JS
856+ optHelper (JSApp (JSIdent "__IDRRT__tailcall") [
857+ JSFunction [] (JSReturn (JSApp (JSIdent n) args))
858+ ])
859+ | n == fun = JSApp (JSIdent tc) $ map optHelper args
860+
861+ optHelper (JSFunction args body) =
862+ JSFunction args $ optHelper body
863+
864+ optHelper (JSSeq seq) =
865+ JSSeq $ map optHelper seq
866+
867+ optHelper (JSReturn ret) =
868+ JSReturn $ optHelper ret
869+
870+ optHelper (JSApp lhs rhs) =
871+ JSApp (optHelper lhs) (map optHelper rhs)
872+
873+ optHelper (JSNew con args) =
874+ JSNew con $ map optHelper args
875+
876+ optHelper (JSOp op lhs rhs) =
877+ JSOp op (optHelper lhs) (optHelper rhs)
878+
879+ optHelper (JSProj obj field) =
880+ JSProj (optHelper obj) field
881+
882+ optHelper (JSArray vals) =
883+ JSArray $ map optHelper vals
884+
885+ optHelper (JSAssign lhs rhs) =
886+ JSAssign (optHelper lhs) (optHelper rhs)
887+
888+ optHelper (JSAlloc var (Just val)) =
889+ JSAlloc var (Just $ optHelper val)
890+
891+ optHelper (JSIndex lhs rhs) =
892+ JSIndex (optHelper lhs) (optHelper rhs)
893+
894+ optHelper (JSCond conds) =
895+ JSCond $ map (optHelper *** optHelper) conds
896+
897+ optHelper (JSTernary c t f) =
898+ JSTernary (
899+ optHelper c
900+ ) (
901+ optHelper t
902+ ) (
903+ optHelper f
904+ )
905+
906+ optHelper js = js
907+
908+
909+removeInstanceChecks :: JS -> JS
910+removeInstanceChecks (JSCond conds) =
911+ JSCond $ map (removeHelper *** removeInstanceChecks) conds
912+ where
913+ removeHelper (
914+ JSOp "&&" (JSOp "instanceof" _ (JSIdent "__IDRRT__Con")) check
915+ ) = removeHelper check
916+ removeHelper js = js
917+
918+removeInstanceChecks (JSFunction args body) =
919+ JSFunction args $ removeInstanceChecks body
920+
921+removeInstanceChecks (JSSeq seq) =
922+ JSSeq $ map removeInstanceChecks seq
923+
924+removeInstanceChecks (JSReturn ret) =
925+ JSReturn $ removeInstanceChecks ret
926+
927+removeInstanceChecks (JSApp lhs rhs) =
928+ JSApp (removeInstanceChecks lhs) $ map removeInstanceChecks rhs
929+
930+removeInstanceChecks (JSNew con args) =
931+ JSNew con $ map removeInstanceChecks args
932+
933+removeInstanceChecks (JSOp op lhs rhs) =
934+ JSOp op (removeInstanceChecks lhs) (removeInstanceChecks rhs)
935+
936+removeInstanceChecks (JSProj obj field) =
937+ JSProj (removeInstanceChecks obj) field
938+
939+removeInstanceChecks (JSArray vals) =
940+ JSArray $ map removeInstanceChecks vals
941+
942+removeInstanceChecks (JSAssign lhs rhs) =
943+ JSAssign (removeInstanceChecks lhs) (removeInstanceChecks rhs)
944+
945+removeInstanceChecks (JSAlloc var (Just val)) =
946+ JSAlloc var (Just $ removeInstanceChecks val)
947+
948+removeInstanceChecks (JSIndex lhs rhs) =
949+ JSIndex (removeInstanceChecks lhs) (removeInstanceChecks rhs)
950+
951+removeInstanceChecks (JSTernary c t f) =
952+ JSTernary (
953+ removeInstanceChecks c
954+ ) (
955+ removeInstanceChecks t
956+ ) (
957+ removeInstanceChecks f
958+ )
959+
960+removeInstanceChecks js = js
961+
819962reduceLoop :: [String] -> ([JS], [JS]) -> [JS]
820963reduceLoop reduced (cons, program) =
821964 case partition findConstructors program of
@@ -942,8 +1085,13 @@ codegenJavaScript target definitions filename outputType = do
9421085 constRemoved = map reduceConstants reduced
9431086 constrInit = initConstructors constRemoved
9441087 removeAlloc = map removeAllocations constrInit
945− deadElim = deadEvalApplyCases removeAlloc
946− js = inlineFunctions deadElim in
1088+ deadElim = elimDeadLoop removeAlloc
1089+ inlined = inlineFunctions deadElim
1090+ elimDup = map elimDuplicateEvals inlined
1091+ evalTC = map (optimizeEvalTailcalls ("__IDR__mEVAL0", "__IDRRT__EVALTC")) elimDup
1092+ applyTC = map (optimizeEvalTailcalls ("__IDR__mAPPLY0", "__IDRRT__APPLYTC")) evalTC
1093+ remChecks = map removeInstanceChecks applyTC
1094+ js = remChecks in
9471095 map compileJS js
9481096
9491097 mainLoop :: JS
src/Idris/AbsSyntaxTree.hs+5−2
@@ -26,6 +26,7 @@ import Data.List
2626import Data.Char
2727import qualified Data.Map as M
2828import qualified Data.Text as T
29+import qualified Data.Map as M
2930import Data.Either
3031import qualified Data.Set as S
3132import Data.Word (Word)
@@ -142,7 +143,9 @@ data IState = IState {
142143 idris_outh :: Handle,
143144 idris_errorhandlers :: [Name], -- ^ Global error handlers
144145 idris_nameIdx :: (Int, Ctxt (Int, Name)),
145− idris_function_errorhandlers :: Ctxt (M.Map Name (S.Set Name)) -- ^ Specific error handlers
146+ idris_function_errorhandlers :: Ctxt (M.Map Name (S.Set Name)), -- ^ Specific error handlers
147+ module_aliases :: M.Map [T.Text] [T.Text]
148+
146149 }
147150
148151data SizeChange = Smaller | Same | Bigger | Unknown
@@ -211,7 +214,7 @@ idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
211214 emptyContext
212215 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] [] []
213216 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
214− True defaultTheme stdout [] (0, emptyContext) emptyContext
217+ True defaultTheme stdout [] (0, emptyContext) emptyContext M.empty
215218
216219-- | The monad for the main REPL - reading and processing files and updating
217220-- global state (hence the IO inner monad).
src/Idris/Chaser.hs+1−1
@@ -132,7 +132,7 @@ buildTree built fp = btree [] fp
132132 file_in <- runIO $ readFile f
133133 file <- if lit then tclift $ unlit f file_in else return file_in
134134 (_, modules, _) <- parseImports f file
135− ms <- mapM (btree done) modules
135+ ms <- mapM (btree done) [realName | (realName, alias, fc) <- modules]
136136 return (concat ms)
137137 else return [] -- IBC with no source available
138138-- (\c -> return []) -- error, can't chase modules here
src/Idris/Delaborate.hs+1−1
@@ -185,7 +185,7 @@ pprintErr' i (NotInjective p x y) =
185185 pprintTerm i (delab i y)
186186pprintErr' i (CantResolve c) = text "Can't resolve type class" <+> pprintTerm i (delab i c)
187187pprintErr' i (CantResolveAlts as) = text "Can't disambiguate name:" <+>
188− cat (punctuate comma (map text as))
188+ cat (punctuate (comma <> space) (map text as))
189189pprintErr' i (NoTypeDecl n) = text "No type declaration for" <+> annName n
190190pprintErr' i (NoSuchVariable n) = text "No such variable" <+> annName n
191191pprintErr' i (IncompleteTerm t) = text "Incomplete term" <+> pprintTerm i (delab i t)
src/Idris/ElabTerm.hs+3−1
@@ -232,7 +232,9 @@ elab ist info pattern opts fn tm
232232 let (tc, _) = unApply ty
233233 let as' = pruneByType tc ctxt as
234234 tryAll (zip (map (elab' ina) as') (map showHd as'))
235− where showHd (PApp _ h _) = show h
235+ where showHd (PApp _ (PRef _ n) _) = show n
236+ showHd (PRef _ n) = show n
237+ showHd (PApp _ h _) = show h
236238 showHd x = show x
237239 elab' ina (PAlternative False as)
238240 = trySeq as
src/Idris/ParseExpr.hs+1
@@ -757,6 +757,7 @@ quoteGoal syn = do reserved "quoteGoal"; n <- name;
757757 <?> "quote goal expression"
758758
759759{- | Parses a dependent type signature
760+
760761@
761762Pi ::=
762763 '|'? Static? '(' TypeDeclList ')' DocComment '->' Expr
src/Idris/ParseHelpers.hs+34−19
@@ -25,13 +25,14 @@ import qualified Data.List.Split as Spl
2525import Data.List
2626import Data.Monoid
2727import Data.Char
28+import qualified Data.Map as M
2829import qualified Data.HashSet as HS
2930import qualified Data.Text as T
3031import qualified Data.ByteString.UTF8 as UTF8
3132
3233import System.FilePath
3334
34−-- | Idris parser with state used during parsing
35+-- | Idris parser with state used during parsing
3536type IdrisParser = StateT IState IdrisInnerParser
3637
3738newtype IdrisInnerParser a = IdrisInnerParser { runInnerParser :: Parser a }
@@ -40,7 +41,7 @@ newtype IdrisInnerParser a = IdrisInnerParser { runInnerParser :: Parser a }
4041instance TokenParsing IdrisInnerParser where
4142 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
4243
43−-- | Generalized monadic parsing constraint type
44+-- | Generalized monadic parsing constraint type
4445type MonadicParsing m = (DeltaParsing m, LookAheadParsing m, TokenParsing m, Monad m)
4546
4647-- | Helper to run Idris inner parser based stateT parsers
@@ -49,7 +50,7 @@ runparser p i inputname = parseString (runInnerParser (evalStateT p i)) (Directe
4950
5051{- * Space, comments and literals (token/lexing like parsers) -}
5152
52−-- | Consumes any simple whitespace (any character which satisfies Char.isSpace)
53+-- | Consumes any simple whitespace (any character which satisfies Char.isSpace)
5354simpleWhiteSpace :: MonadicParsing m => m ()
5455simpleWhiteSpace = satisfy isSpace *> pure ()
5556
@@ -68,9 +69,12 @@ isDocCommentMarker '^' = True
6869isDocCommentMarker _ = False
6970
7071{- | Consumes a single-line comment
72+
73+@
7174 SingleLineComment_t ::= '--' EOL_t
7275 | '--' ~DocCommentMarker_t ~EOL_t* EOL_t
7376 ;
77+@
7478 -}
7579singleLineComment :: MonadicParsing m => m ()
7680singleLineComment = try (string "--" *> eol *> pure ())
@@ -78,18 +82,22 @@ singleLineComment = try (string "--" *> eol *> pure ())
7882 <?> ""
7983
8084{- | Consumes a multi-line comment
85+
86+@
8187 MultiLineComment_t ::=
8288 '{ -- }'
8389 | '{ -' ~DocCommentMarker_t InCommentChars_t
8490 ;
91+@
8592
93+@
8694 InCommentChars_t ::=
8795 '- }'
8896 | MultiLineComment_t InCommentChars_t
8997 | ~'- }'+ InCommentChars_t
9098 ;
91− -}
92−
99+@
100+-}
93101multiLineComment :: MonadicParsing m => m ()
94102multiLineComment = try (string "{-" *> (string "-}") *> pure ())
95103 <|> string "{-" *> satisfy (not . isDocCommentMarker) *> inCommentChars
@@ -106,9 +114,12 @@ multiLineComment = try (string "{-" *> (string "-}") *> pure ())
106114 startEnd = "{}-"
107115
108116{-| Parses a documentation comment (similar to haddoc) given a marker character
117+
118+@
109119 DocComment_t ::= '--' DocCommentMarker_t ~EOL_t* EOL_t
110120 | '{ -' DocCommentMarket_t ~'- }'* '- }'
111121 ;
122+@
112123 -}
113124docComment :: MonadicParsing m => Char -> m String
114125docComment marker | isDocCommentMarker marker = do dc <- docComment' marker; return (T.unpack $ T.strip $ T.pack dc)
@@ -138,14 +149,14 @@ natural = Tok.natural
138149integer :: MonadicParsing m => m Integer
139150integer = Tok.integer
140151
141−-- | Parses a floating point number
152+-- | Parses a floating point number
142153float :: MonadicParsing m => m Double
143154float = Tok.double
144155
145156{- * Symbols, identifiers, names and operators -}
146157
147158
148−-- | Idris Style for parsing identifiers/reserved keywords
159+-- | Idris Style for parsing identifiers/reserved keywords
149160idrisStyle :: MonadicParsing m => IdentifierStyle m
150161idrisStyle = IdentifierStyle _styleName _styleStart _styleLetter _styleReserved Hi.Identifier Hi.ReservedIdentifier
151162 where _styleName = "Idris"
@@ -210,14 +221,18 @@ maybeWithNS parser ascend bad = do
210221
211222-- | Parses a name
212223name :: IdrisParser Name
213−name = do i <- get
214− iName (syntax_keywords i)
215− <?> "name"
216−
217−
218−{- | List of all initial segments in ascending order of a list. Every such
219− initial segment ends right before an element satisfying the given
220− condition.
224+name = (<?> "name") $ do
225+ keywords <- syntax_keywords <$> get
226+ aliases <- module_aliases <$> get
227+ unalias aliases <$> iName keywords
228+ where
229+ unalias :: M.Map [T.Text] [T.Text] -> Name -> Name
230+ unalias aliases (NS n ns) | Just ns' <- M.lookup ns aliases = NS n ns'
231+ unalias aliases name = name
232+
233+{- | List of all initial segments in ascending order of a list. Every
234+such initial segment ends right before an element satisfying the given
235+condition.
221236-}
222237initsEndAt :: (a -> Bool) -> [a] -> [[a]]
223238initsEndAt p [] = []
@@ -226,7 +241,7 @@ initsEndAt p (x:xs) | p x = [] : x_inits_xs
226241 where x_inits_xs = [x : cs | cs <- initsEndAt p xs]
227242
228243
229−{- | Create a `Name' from a pair of strings representing a base name and its
244+{- | Create a `Name' from a pair of strings representing a base name and its
230245 namespace.
231246-}
232247mkName :: (String, String) -> Name
@@ -304,7 +319,7 @@ lastIndent = do ist <- get
304319 (x : xs) -> return x
305320 _ -> return 1
306321
307−-- | Applies parser in an indented position
322+-- | Applies parser in an indented position
308323indented :: IdrisParser a -> IdrisParser a
309324indented p = notEndBlock *> p <* keepTerminator
310325
@@ -326,7 +341,7 @@ indentedBlock1 p = do openBlock
326341 closeBlock
327342 return res
328343
329−-- | Applies parser to get a block with exactly one (possibly indented) statement
344+-- | Applies parser to get a block with exactly one (possibly indented) statement
330345indentedBlockS :: IdrisParser a -> IdrisParser a
331346indentedBlockS p = do openBlock
332347 pushIndent
@@ -452,7 +467,7 @@ accessibility = do reserved "public"; return Public
452467 <|> do reserved "private"; return Hidden
453468 <?> "accessibility modifier"
454469
455−-- | Adds accessibility option for function
470+-- | Adds accessibility option for function
456471addAcc :: Name -> Maybe Accessibility -> IdrisParser ()
457472addAcc n a = do i <- get
458473 put (i { hide_list = (n, a) : hide_list i })
src/Idris/Parser.hs+179−35
@@ -47,11 +47,14 @@ import Control.Monad
4747import Control.Monad.Error (throwError, catchError)
4848import Control.Monad.State.Strict
4949
50+import Data.Function
5051import Data.Maybe
5152import qualified Data.List.Split as Spl
5253import Data.List
5354import Data.Monoid
5455import Data.Char
56+import Data.Ord
57+import qualified Data.Map as M
5558import qualified Data.HashSet as HS
5659import qualified Data.Text as T
5760import qualified Data.ByteString.UTF8 as UTF8
@@ -63,6 +66,7 @@ import System.FilePath
6366import System.IO
6467
6568{-
69+@
6670 grammar shortcut notation:
6771 ~CHARSEQ = complement of char sequence (i.e. any character except CHARSEQ)
6872 RULE? = optional rule (i.e. RULE or nothing)
@@ -70,12 +74,16 @@ import System.IO
7074 RULE+ = repeated rule with at least one match (i.e. RULE one or more times)
7175 RULE! = invalid rule (i.e. rule that is not valid in context, report meaningful error in case)
7276 RULE{n} = rule repeated n times
77+@
7378-}
7479
7580{- * Main grammar -}
7681
7782{- | Parses module definition
83+
84+@
7885 ModuleHeader ::= 'module' Identifier_t ';'?;
86+@
7987-}
8088moduleHeader :: IdrisParser [String]
8189moduleHeader = try (do reserved "module"
@@ -90,18 +98,26 @@ moduleHeader = try (do reserved "module"
9098 (x, '.':y) -> x : moduleName y
9199
92100{- | Parses an import statement
101+
102+@
93103 Import ::= 'import' Identifier_t ';'?;
104+@
94105 -}
95−import_ :: IdrisParser String
96−import_ = do reserved "import"
106+import_ :: IdrisParser (String, Maybe String, FC)
107+import_ = do fc <- getFC
108+ reserved "import"
97109 id <- identifier
110+ newName <- optional (reserved "as" *> identifier)
98111 option ';' (lchar ';')
99− return (toPath id)
112+ return (toPath id, toPath <$> newName, fc)
100113 <?> "import statement"
101− where toPath f = foldl1' (</>) (Spl.splitOn "." f)
114+ where toPath = foldl1' (</>) . Spl.splitOn "."
102115
103116{- | Parses program source
117+
118+@
104119 Prog ::= Decl* EOF;
120+@
105121 -}
106122prog :: SyntaxInfo -> IdrisParser [PDecl]
107123prog syn = do whiteSpace
@@ -111,7 +127,9 @@ prog syn = do whiteSpace
111127 let c = (concat decls)
112128 return c
113129
114−{- | Parses a top-level declaration
130+{-| Parses a top-level declaration
131+
132+@
115133Decl ::=
116134 Decl'
117135 | Using
@@ -126,6 +144,7 @@ Decl ::=
126144 | Transform
127145 | Import!
128146 ;
147+@
129148-}
130149decl :: SyntaxInfo -> IdrisParser [PDecl]
131150decl syn = do notEndBlock
@@ -151,6 +170,8 @@ decl syn = do notEndBlock
151170 return [d']
152171
153172{- | Parses a top-level declaration with possible syntax sugar
173+
174+@
154175Decl' ::=
155176 Fixity
156177 | FunDecl'
@@ -158,6 +179,7 @@ Decl' ::=
158179 | Record
159180 | SyntaxDecl
160181 ;
182+@
161183-}
162184decl' :: SyntaxInfo -> IdrisParser PDecl
163185decl' syn = fixity
@@ -168,7 +190,10 @@ decl' syn = fixity
168190 <?> "declaration"
169191
170192{- | Parses a syntax extension declaration (and adds the rule to parser state)
193+
194+@
171195 SyntaxDecl ::= SyntaxRule;
196+@
172197-}
173198syntaxDecl :: SyntaxInfo -> IdrisParser PDecl
174199syntaxDecl syn = do s <- syntaxRule syn
@@ -186,17 +211,24 @@ syntaxDecl syn = do s <- syntaxRule syn
186211 ename (Keyword n) = Just n
187212 ename _ = Nothing
188213
189−{- | Parses a syntax extension declaration
190−SyntaxRuleOpts ::= 'term' | 'pattern';
214+{- | Parses a syntax extension declaration
215+
216+@
217+SyntaxRuleOpts ::= 'term' | 'pattern';
218+@
191219
220+@
192221SyntaxRule ::=
193222 SyntaxRuleOpts? 'syntax' SyntaxSym+ '=' TypeExpr Terminator;
223+@
194224
225+@
195226SyntaxSym ::= '[' Name_t ']'
196227 | '{' Name_t '}'
197228 | Name_t
198229 | StringLiteral_t
199230 ;
231+@
200232-}
201233syntaxRule :: SyntaxInfo -> IdrisParser Syntax
202234syntaxRule syn
@@ -232,11 +264,14 @@ syntaxRule syn
232264
233265
234266{- | Parses a syntax symbol (either binding variable, keyword or expression)
267+
268+@
235269SyntaxSym ::= '[' Name_t ']'
236270 | '{' Name_t '}'
237271 | Name_t
238272 | StringLiteral_t
239273 ;
274+@
240275 -}
241276syntaxSym :: IdrisParser SSymbol
242277syntaxSym = try (do lchar '['; n <- name; lchar ']'
@@ -250,7 +285,10 @@ syntaxSym = try (do lchar '['; n <- name; lchar ']'
250285 <?> "syntax symbol"
251286
252287{- | Parses a function declaration with possible syntax sugar
288+
289+@
253290 FunDecl ::= FunDecl';
291+@
254292-}
255293fnDecl :: SyntaxInfo -> IdrisParser [PDecl]
256294fnDecl syn = try (do notEndBlock
@@ -259,13 +297,16 @@ fnDecl syn = try (do notEndBlock
259297 let d' = fmap (desugar syn i) d
260298 return [d']) <?> "function declaration"
261299
262−{- Parses a function declaration
300+{-| Parses a function declaration
301+
302+@
263303 FunDecl' ::=
264304 DocComment_t? FnOpts* Accessibility? FnOpts* FnName TypeSig Terminator
265305 | Postulate
266306 | Pattern
267307 | CAF
268308 ;
309+@
269310-}
270311fnDecl' :: SyntaxInfo -> IdrisParser PDecl
271312fnDecl' syn = checkFixity $
@@ -309,23 +350,29 @@ fnDecl' syn = checkFixity $
309350 | otherwise = return True
310351 fixityOK _ = return True
311352
312−{- Parses function options given initial options
353+{-| Parses function options given initial options
354+
355+@
313356FnOpts ::= 'total'
314357 | 'partial'
315358 | 'implicit'
316359 | '%' 'assert_total'
317360 | '%' 'error_handler'
318− | '%' 'reflection'
361+ | '%' 'reflection'
319362 | '%' 'specialise' '[' NameTimesList? ']'
320363 ;
364+@
321365
366+@
322367NameTimes ::= FnName Natural?;
368+@
323369
370+@
324371NameTimesList ::=
325372 NameTimes
326373 | NameTimes ',' NameTimesList
327374 ;
328−
375+@
329376-}
330377-- FIXME: Check compatability for function options (i.e. partal/total)
331378fnOpts :: [FnOpt] -> IdrisParser [FnOpt]
@@ -356,9 +403,11 @@ fnOpts opts
356403
357404{- | Parses a postulate
358405
406+@
359407Postulate ::=
360408 DocComment_t? 'postulate' FnOpts* Accesibility? FnOpts* FnName TypeSig Terminator
361409 ;
410+@
362411-}
363412postulate :: SyntaxInfo -> IdrisParser PDecl
364413postulate syn = do doc <- try $ do doc <- option "" (docComment '|')
@@ -384,9 +433,11 @@ postulate syn = do doc <- try $ do doc <- option "" (docComment '|')
384433
385434{- | Parses a using declaration
386435
436+@
387437Using ::=
388438 'using' '(' UsingDeclList ')' OpenBlock Decl* CloseBlock
389439 ;
440+@
390441 -}
391442using_ :: SyntaxInfo -> IdrisParser [PDecl]
392443using_ syn =
@@ -398,11 +449,13 @@ using_ syn =
398449 return (concat ds)
399450 <?> "using declaration"
400451
401−{- | Parses a parameters declaration
452+{- | Parses a parameters declaration
402453
454+@
403455Params ::=
404456 'parameters' '(' TypeDeclList ')' OpenBlock Decl* CloseBlock
405457 ;
458+@
406459 -}
407460params :: SyntaxInfo -> IdrisParser [PDecl]
408461params syn =
@@ -417,9 +470,11 @@ params syn =
417470
418471{- | Parses a mutual declaration (for mutually recursive functions)
419472
473+@
420474Mutual ::=
421475 'mutual' OpenBlock Decl* CloseBlock
422476 ;
477+@
423478-}
424479mutual :: SyntaxInfo -> IdrisParser [PDecl]
425480mutual syn =
@@ -432,11 +487,13 @@ mutual syn =
432487 return [PMutual fc (concat ds)]
433488 <?> "mutual block"
434489
435−{- | Parses a namespace declaration
490+{-| Parses a namespace declaration
436491
492+@
437493Namespace ::=
438494 'namespace' identifier OpenBlock Decl+ CloseBlock
439495 ;
496+@
440497-}
441498namespace :: SyntaxInfo -> IdrisParser [PDecl]
442499namespace syn =
@@ -447,9 +504,12 @@ namespace syn =
447504 return [PNamespace n (concat ds)]
448505 <?> "namespace declaration"
449506
450−{- |Parses a methods block (for instances)
507+{- | Parses a methods block (for instances)
508+
509+@
451510 InstanceBlock ::= 'where' OpenBlock FnDecl* CloseBlock
452− -}
511+@
512+-}
453513instanceBlock :: SyntaxInfo -> IdrisParser [PDecl]
454514instanceBlock syn = do reserved "where"
455515 openBlock
@@ -458,16 +518,20 @@ instanceBlock syn = do reserved "where"
458518 return (concat ds)
459519 <?> "instance block"
460520
461−{- |Parses a methods and instances block (for type classes)
521+{- | Parses a methods and instances block (for type classes)
462522
523+@
463524MethodOrInstance ::=
464525 FnDecl
465526 | Instance
466527 ;
528+@
467529
530+@
468531ClassBlock ::=
469532 'where' OpenBlock MethodOrInstance* CloseBlock
470533 ;
534+@
471535-}
472536classBlock :: SyntaxInfo -> IdrisParser [PDecl]
473537classBlock syn = do reserved "where"
@@ -477,16 +541,20 @@ classBlock syn = do reserved "where"
477541 return (concat ds)
478542 <?> "class block"
479543
480−{- |Parses a type class declaration
544+{-| Parses a type class declaration
481545
546+@
482547ClassArgument ::=
483548 Name
484549 | '(' Name ':' Expr ')'
485550 ;
551+@
486552
553+@
487554Class ::=
488555 DocComment_t? Accessibility? 'class' ConstraintList? Name ClassArgument* ClassBlock?
489556 ;
557+@
490558-}
491559class_ :: SyntaxInfo -> IdrisParser [PDecl]
492560class_ syn = do (doc, acc) <- try (do
@@ -507,13 +575,17 @@ class_ syn = do (doc, acc) <- try (do
507575 <|> do i <- name;
508576 return (i, PType)
509577
510−{- |Parses a type class instance declaration
578+{- | Parses a type class instance declaration
511579
580+@
512581 Instance ::=
513582 'instance' InstanceName? ConstraintList? Name SimpleExpr* InstanceBlock?
514583 ;
584+@
515585
516− InstanceName ::= '[' Name ']';
586+@
587+InstanceName ::= '[' Name ']';
588+@
517589-}
518590instance_ :: SyntaxInfo -> IdrisParser [PDecl]
519591instance_ syn = do reserved "instance"; fc <- getFC
@@ -534,20 +606,27 @@ instance_ syn = do reserved "instance"; fc <- getFC
534606
535607
536608{- | Parses a using declaration list
609+
610+@
537611UsingDeclList ::=
538612 UsingDeclList'
539613 | NameList TypeSig
540614 ;
615+@
541616
617+@
542618UsingDeclList' ::=
543619 UsingDecl
544620 | UsingDecl ',' UsingDeclList'
545621 ;
622+@
546623
624+@
547625NameList ::=
548626 Name
549627 | Name ',' NameList
550628 ;
629+@
551630-}
552631usingDeclList :: SyntaxInfo -> IdrisParser [Using]
553632usingDeclList syn
@@ -559,10 +638,13 @@ usingDeclList syn
559638 <?> "using declaration list"
560639
561640{- |Parses a using declaration
641+
642+@
562643UsingDecl ::=
563644 FnName TypeSig
564645 | FnName FnName+
565646 ;
647+@
566648-}
567649usingDecl :: SyntaxInfo -> IdrisParser Using
568650usingDecl syn = try (do x <- fnName
@@ -574,8 +656,11 @@ usingDecl syn = try (do x <- fnName
574656 return (UConstraint c xs)
575657 <?> "using declaration"
576658
577−{- | Parse a clause with patterns
659+{- | Parse a clause with patterns
660+
661+@
578662Pattern ::= Clause;
663+@
579664-}
580665pattern :: SyntaxInfo -> IdrisParser PDecl
581666pattern syn = do fc <- getFC
@@ -584,7 +669,10 @@ pattern syn = do fc <- getFC
584669 <?> "pattern"
585670
586671{- | Parse a constant applicative form declaration
587− CAF ::= 'let' FnName '=' Expr Terminator;
672+
673+@
674+CAF ::= 'let' FnName '=' Expr Terminator;
675+@
588676-}
589677caf :: SyntaxInfo -> IdrisParser PDecl
590678caf syn = do reserved "let"
@@ -597,7 +685,10 @@ caf syn = do reserved "let"
597685 <?> "constant applicative form declaration"
598686
599687{- | Parse an argument expression
600− ArgExpr ::= HSimpleExpr | {- In Pattern External (User-defined) Expression -};
688+
689+@
690+ArgExpr ::= HSimpleExpr | {- In Pattern External (User-defined) Expression -};
691+@
601692-}
602693argExpr :: SyntaxInfo -> IdrisParser PTerm
603694argExpr syn = let syn' = syn { inPattern = True } in
@@ -605,12 +696,17 @@ argExpr syn = let syn' = syn { inPattern = True } in
605696 <?> "argument expression"
606697
607698{- | Parse a right hand side of a function
699+
700+@
608701RHS ::= '=' Expr
609702 | '?=' RHSName? Expr
610703 | 'impossible'
611704 ;
705+@
612706
707+@
613708RHSName ::= '{' FnName '}';
709+@
614710-}
615711rhs :: SyntaxInfo -> Name -> IdrisParser PTerm
616712rhs syn n = do lchar '='; expr syn
@@ -633,16 +729,28 @@ rhs syn n = do lchar '='; expr syn
633729 addLet nm r = (PLet (sUN "value") Placeholder r (PMetavar nm))
634730
635731{- |Parses a function clause
732+
733+@
636734RHSOrWithBlock ::= RHS WhereOrTerminator
637735 | 'with' SimpleExpr OpenBlock FnDecl+ CloseBlock
638736 ;
737+@
738+
739+@
639740Clause ::= WExpr+ RHSOrWithBlock
640741 | SimpleExpr '<==' FnName RHS WhereOrTerminator
641742 | ArgExpr Operator ArgExpr WExpr* RHSOrWithBlock {- Except "=" and "?=" operators to avoid ambiguity -}
642743 | FnName ConstraintArg* ImplicitOrArgExpr* WExpr* RHSOrWithBlock
643744 ;
745+@
746+
747+@
644748ImplicitOrArgExpr ::= ImplicitArg | ArgExpr;
645−WhereOrTerminator ::= WhereBlock | Terminator;
749+@
750+
751+@
752+WhereOrTerminator ::= WhereBlock | Terminator;
753+@
646754-}
647755clause :: SyntaxInfo -> IdrisParser PClause
648756clause syn
@@ -771,17 +879,23 @@ clause syn
771879 fillLHSD n c a (PClauses fc o fn cs) = PClauses fc o fn (map (fillLHS n c a) cs)
772880 fillLHSD n c a x = x
773881
774−{- |Parses with pattern
775− WExpr ::= '|' Expr';
882+{-| Parses with pattern
883+
884+@
885+WExpr ::= '|' Expr';
886+@
776887-}
777888wExpr :: SyntaxInfo -> IdrisParser PTerm
778889wExpr syn = do lchar '|'
779890 expr' syn
780891 <?> "with pattern"
781892
782−{- |Parses a where block
893+{- | Parses a where block
894+
895+@
783896WhereBlock ::= 'where' OpenBlock Decl+ CloseBlock;
784− -}
897+@
898+-}
785899whereBlock :: Name -> SyntaxInfo -> IdrisParser ([PDecl], [(Name, Name)])
786900whereBlock n syn
787901 = do reserved "where"
@@ -791,6 +905,8 @@ whereBlock n syn
791905 <?> "where block"
792906
793907{- |Parses a code generation target language name
908+
909+@
794910Codegen ::= 'C'
795911 | 'Java'
796912 | 'JavaScript'
@@ -798,6 +914,7 @@ Codegen ::= 'C'
798914 | 'LLVM'
799915 | 'Bytecode'
800916 ;
917+@
801918-}
802919codegen_ :: IdrisParser Codegen
803920codegen_ = do reserved "C"; return ViaC
@@ -809,13 +926,18 @@ codegen_ = do reserved "C"; return ViaC
809926 <?> "code generation language"
810927
811928{- |Parses a compiler directive
929+@
812930StringList ::=
813931 String
814932 | String ',' StringList
815933 ;
934+@
816935
936+@
817937Directive ::= '%' Directive';
938+@
818939
940+@
819941Directive' ::= 'lib' CodeGen String_t
820942 | 'link' CodeGen String_t
821943 | 'flag' CodeGen String_t
@@ -831,6 +953,7 @@ Directive' ::= 'lib' CodeGen String_t
831953 | 'language' 'TypeProviders'
832954 | 'language' 'ErrorReflection'
833955 ;
956+@
834957-}
835958directive :: SyntaxInfo -> IdrisParser [PDecl]
836959directive syn = do try (lchar '%' *> reserved "lib"); cgn <- codegen_; lib <- stringLiteral;
@@ -899,15 +1022,22 @@ pLangExt = (reserved "TypeProviders" >> return TypeProviders)
8991022 <|> (reserved "ErrorReflection" >> return ErrorReflection)
9001023
9011024{- | Parses a totality
1025+
1026+@
9021027Totality ::= 'partial' | 'total'
1028+@
1029+
9031030-}
9041031totality :: IdrisParser Bool
9051032totality
9061033 = do reserved "total"; return True
9071034 <|> do reserved "partial"; return False
9081035
909−{- | Parses a type provider
1036+{- | Parses a type provider
1037+
1038+@
9101039Provider ::= '%' 'provide' '(' FnName TypeSig ')' 'with' Expr;
1040+@
9111041 -}
9121042provider :: SyntaxInfo -> IdrisParser [PDecl]
9131043provider syn = do try (lchar '%' *> reserved "provide");
@@ -919,7 +1049,10 @@ provider syn = do try (lchar '%' *> reserved "provide");
9191049 <?> "type provider"
9201050
9211051{- | Parses a transform
1052+
1053+@
9221054Transform ::= '%' 'transform' Expr '==>' Expr
1055+@
9231056-}
9241057transform :: SyntaxInfo -> IdrisParser [PDecl]
9251058transform syn = do try (lchar '%' *> reserved "transform")
@@ -945,7 +1078,7 @@ parseTactic :: IState -> String -> Result PTactic
9451078parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
9461079
9471080-- | Parse module header and imports
948−parseImports :: FilePath -> String -> Idris ([String], [String], Maybe Delta)
1081+parseImports :: FilePath -> String -> Idris ([String], [(String, Maybe String, FC)], Maybe Delta)
9491082parseImports fname input
9501083 = do i <- getIState
9511084 case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
@@ -953,7 +1086,7 @@ parseImports fname input
9531086 Success (x, i) -> do -- Discard state updates (there should be
9541087 -- none anyway)
9551088 return x
956− where imports :: IdrisParser (([String], [String], Maybe Delta), IState)
1089+ where imports :: IdrisParser (([String], [(String, Maybe String, FC)], Maybe Delta), IState)
9571090 imports = do whiteSpace
9581091 mname <- moduleHeader
9591092 ps <- many import_
@@ -1064,13 +1197,24 @@ loadSource h lidr f
10641197 let def_total = default_total i
10651198 file_in <- runIO $ readFile f
10661199 file <- if lidr then tclift $ unlit f file_in else return file_in
1067− (mname, modules, pos) <- parseImports f file
1200+ (mname, imports, pos) <- parseImports f file
1201+
1202+ -- process and check module aliases
1203+ let modAliases = M.fromList
1204+ [(prep alias, prep realName) | (realName, Just alias, fc) <- imports]
1205+ prep = map T.pack . reverse . Spl.splitOn "/"
1206+ aliasNames = [(alias, fc) | (_, Just alias, fc) <- imports]
1207+ histogram = groupBy ((==) `on` fst) . sortBy (comparing fst) $ aliasNames
1208+ case map head . filter ((/= 1) . length) $ histogram of
1209+ [] -> logLvl 3 $ "Module aliases: " ++ show (M.toList modAliases)
1210+ (n,fc):_ -> throwError . At fc . Msg $ "import alias not unique: " ++ show n
1211+
10681212 i <- getIState
1069− putIState (i { default_access = Hidden })
1213+ putIState (i { default_access = Hidden, module_aliases = modAliases })
10701214 clearIBC -- start a new .ibc file
1071− mapM_ (addIBC . IBCImport) modules
1072− ds' <- parseProg (defaultSyntax {syn_namespace = reverse mname })
1073− f file pos
1215+ mapM_ (addIBC . IBCImport) [realName | (realName, alias, fc) <- imports]
1216+ let syntax = defaultSyntax{ syn_namespace = reverse mname }
1217+ ds' <- parseProg syntax f file pos
10741218 unless (null ds') $ do
10751219 let ds = namespaces mname ds'
10761220 logLvl 3 (show $ showDecls True ds)
src/Pkg/Package.hs+2−2
@@ -24,14 +24,14 @@ import Pkg.PParser
2424
2525import Paths_idris (getDataDir)
2626
27−-- | Run the package through the idris compiler.
28−--
2927-- To build a package:
3028-- * read the package description
3129-- * check all the library dependencies exist
3230-- * invoke the makefile if there is one
3331-- * invoke idris on each module, with idris_opts
3432-- * install everything into datadir/pname, if install flag is set
33+
34+-- | Run the package through the idris compiler.
3535buildPkg :: Bool -> (Bool, FilePath) -> IO ()
3636buildPkg warnonly (install, fp)
3737 = do pkgdesc <- parseDesc fp
test/test039/FunErrTest.idr → test/test038/FunErrTest.idrrenamed

The content is the same.

test/test038/expected+4−29
@@ -1,29 +1,4 @@
1−True
2−False
3−True
4−False
5−True
6−False
7−True
8−False
9−True
10−False
11−False
12−True
13−False
14−True
15−True
16−False
17−True
18−False
19−True
20−False
21−False
22−True
23−False
24−False
25−False
26−True
27−False
28−True
29−False
1+FunErrTest.idr:35:10:When elaborating right hand side of badCadr1:
2+Could not prove that [] has at least two elements.
3+FunErrTest.idr:38:10:When elaborating right hand side of badCadr2:
4+Could not prove that tail [(fromInteger 1)] refl has at least two elements.
test/test038/run+2−4
@@ -1,5 +1,3 @@
11#!/usr/bin/env bash
2−idris $@ -o test038 test038.idr --nocolour
3−./test038
4−rm -f test038 *.ibc
5−
2+idris $@ FunErrTest.idr --nocolour --check
3+rm -f *.ibc
test/test039/expected+29−4
@@ -1,4 +1,29 @@
1−FunErrTest.idr:35:10:When elaborating right hand side of badCadr1:
2−Could not prove that [] has at least two elements.
3−FunErrTest.idr:38:10:When elaborating right hand side of badCadr2:
4−Could not prove that tail [(fromInteger 1)] refl has at least two elements.
1+True
2+False
3+True
4+False
5+True
6+False
7+True
8+False
9+True
10+False
11+False
12+True
13+False
14+True
15+True
16+False
17+True
18+False
19+True
20+False
21+False
22+True
23+False
24+False
25+False
26+True
27+False
28+True
29+False
test/test039/run+4−2
@@ -1,3 +1,5 @@
11#!/usr/bin/env bash
2−idris $@ FunErrTest.idr --nocolour --check
3−rm -f *.ibc
2+idris $@ -o test038 test038.idr --nocolour
3+./test038
4+rm -f test038 *.ibc
5+
test/test038/test038.idr → test/test039/test038.idrrenamed

The content is the same.

test/test040/A.idrnew file+4
@@ -0,0 +1,4 @@
1+module A
2+
3+num : Nat
4+num = 0
test/test040/B/C.idrnew file+4
@@ -0,0 +1,4 @@
1+module B.C
2+
3+num : Nat
4+num = 1
test/test040/Faulty.idrnew file+7
@@ -0,0 +1,7 @@
1+module Faulty
2+
3+import A
4+import B.C
5+
6+fault : num = Z
7+fault = refl
test/test040/Main.idrnew file+16
@@ -0,0 +1,16 @@
1+module Main
2+
3+import A as X
4+import B.C as Y
5+
6+checkX : X.num = Z
7+checkX = refl
8+
9+checkY : Y.num = S Z
10+checkY = refl
11+
12+checkAX : X.num = A.num
13+checkAX = refl
14+
15+checkBY : Y.num = B.C.num
16+checkBY = refl
test/test040/Multiple.idrnew file+4
@@ -0,0 +1,4 @@
1+module Multiple
2+
3+import Prelude.Vect as X
4+import Prelude.List as X
test/test040/expectednew file+4
@@ -0,0 +1,4 @@
1+MAIN-PASS
2+Faulty.idr:6:7:When elaborating type of Faulty.fault:
3+Can't disambiguate name: A.num, B.C.num
4+Multiple.idr:3:1:import alias not unique: "X"
test/test040/runnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/env bash
2+idris $@ Main.idr --nocolour --check && echo MAIN-PASS
3+idris $@ Faulty.idr --nocolour --check && echo FAULTY-PASS
4+idris $@ Multiple.idr --nocolour --check && echo MULTIPLE-PASS
5+rm -f *.ibc B/*.ibc