on master help sign in
Allow functions to be declared as error handlers
commit52d816525ec0eb3fc035727182411500a5e66b08 authorDavid Christiansen <david@davidchristiansen.dk> dateSat 28 Sep 2013, 21:01 (13 years ago) parentcda1274
3 files changed+15−2
src/Idris/AbsSyntaxTree.hs+6−2 src/Idris/ElabDecls.hs+6 src/Idris/Parser.hs+3
src/Idris/AbsSyntaxTree.hs+6−2
@@ -128,7 +128,8 @@ data IState = IState {
128128 idris_outputmode :: OutputMode,
129129 idris_colourRepl :: Bool,
130130 idris_colourTheme :: ColourTheme,
131− idris_outh :: Handle
131+ idris_outh :: Handle,
132+ idris_errorhandlers :: [Name]
132133 }
133134
134135data SizeChange = Smaller | Same | Bigger | Unknown
@@ -182,12 +183,14 @@ data IBCWrite = IBCFix FixDecl
182183 | IBCLineApp FilePath Int PTerm
183184 deriving Show
184185
186+-- | The initial state for the compiler
187+idrisInit :: IState
185188idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
186189 emptyContext emptyContext emptyContext emptyContext
187190 emptyContext emptyContext emptyContext emptyContext
188191 [] "" defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] []
189192 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
190− True defaultTheme stdout
193+ True defaultTheme stdout []
191194
192195-- | The monad for the main REPL - reading and processing files and updating
193196-- global state (hence the IO inner monad).
@@ -368,6 +371,7 @@ data FnOpt = Inlinable -- always evaluate when simplifying
368371 -- a function argument, and further evaluation resutls
369372 | Implicit -- implicit coercion
370373 | CExport String -- export, with a C name
374+ | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
371375 | Reflection -- a reflecting function, compile-time only
372376 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
373377 deriving (Show, Eq)
src/Idris/ElabDecls.hs+6
@@ -96,6 +96,12 @@ elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
9696 addIBC (IBCFlags n opts')
9797 when (Implicit `elem` opts) $ do addCoercion n
9898 addIBC (IBCCoercion n)
99+ -- If the function is declared as an error handler and the language
100+ -- extension is enabled, then add it to the list of error handlers.
101+ when (ErrorReflection `elem` idris_language_extensions i && ErrorHandler `elem` opts) $
102+ -- TODO: Check that the declared type is the correct type for an error handler:
103+ -- handler : List (TTName, TT) -> Err -> ErrorReport
104+ putIState $ i { idris_errorhandlers = n : idris_errorhandlers i }
99105 when corec $ do setAccessibility n Frozen
100106 addIBC (IBCAccess n Frozen)
101107 where
src/Idris/Parser.hs+3
@@ -292,6 +292,7 @@ FnOpts ::= 'total'
292292 | 'partial'
293293 | 'implicit'
294294 | '%' 'assert_total'
295+ | '%' 'error_handler'
295296 | '%' 'reflection'
296297 | '%' 'specialise' '[' NameTimesList? ']'
297298 ;
@@ -313,6 +314,8 @@ fnOpts opts
313314 fnOpts (CExport c : opts)
314315 <|> do try (lchar '%' *> reserved "assert_total");
315316 fnOpts (AssertTotal : opts)
317+ <|> do try (lchar '%' *> reserved "error_handler");
318+ fnOpts (ErrorHandler : opts)
316319 <|> do try (lchar '%' *> reserved "reflection");
317320 fnOpts (Reflection : opts)
318321 <|> do lchar '%'; reserved "specialise";