@@ -2,13 +2,33 @@ module Idris.Providers where
22
33import Core.TT
44import Core.Evaluate
5+import Core.Execute
56import Idris.AbsSyntax
67import Idris.AbsSyntaxTree
8+import Idris.Error
9+
10+import Debug.Trace
711
812-- | Wrap a type provider in the type of type providers
913providerTy :: FC -> PTerm -> PTerm
1014providerTy fc tm = PApp fc (PRef fc $ UN "Provider") [PExp 0 False tm ""]
1115
12−-- | Wrap the RHS of a type provider definition
16+-- | Wrap the RHS of a type provider definition
1317unProv :: FC -> PTerm -> PTerm
14−unProv fc tm = PApp fc (PRef fc $ NS (UN "unProv") ["Providers"]) [PExp 0 False tm ""]
18+unProv fc tm = PApp fc (PRef fc $ NS (UN "unProv") ["Providers"]) [PExp 0 False tm ""]
19+
20+-- | Handle an error, if the type provider returned an error. Otherwise do nothing.
21+providerError :: TT Name -> Idris ()
22+providerError tm = case unApply tm of
23+ (P _ (NS (UN "unProv") ["Providers"]) _, [_, tm']) ->
24+ case unApply tm' of
25+ (P _ (NS (UN "Error") ["Providers"]) _, [_, err]) ->
26+ do str <- execute err
27+ case (unApply str) of
28+ (Constant (Str msg), []) ->
29+ ierror . ProviderError $ msg
30+ (P _ (UN "prim__IO") _, [_, (Constant (Str msg))]) ->
31+ ierror . ProviderError $ msg
32+ _ -> fail "Error in type provider."
33+ _ -> return ()
34+ _ -> return ()